I am trying to get a disconnect event from a USB HID device using the WebHID API.
The code:
const devices = await navigator.hid.requestDevice({
filters: [{vendorId: 'some_vendor_id'}]
,
});
const device = devices[0];
console.log(`HID connected: ${device.productName}`);
if (!device.opened) {
await device.open();
}
navigator.hid.addEventListener('disconnect', device => {
console.log(`HID disconnected: ${device.productName}`);
});
Device connects successfully but after it is turned off or disconnected from computer, disconnect
event is not triggered.
Am I doing something wrong or is it a bug?
These events are not yet implemented. I have filed an issue to help track this.