I am trying to get a disconnect event from a usb device using the WebUSB API.
I am getting access to the device and adding an event listener to "disconnect" by the following:
navigator.usb.requestDevice({ filters: [{ vendorId: ... ... ...}] })
.then(device=> {
navigator.usb.addEventListener('disconnect', device => {
printToScreen("Message", "Device disconnect!!! ");
});
return device.open();
})
FYI: The printToScreen() method adds text to a div tag.
The device dose connect and I can see the device permission listed when i click the lock icon in the address bar, and i can retrieve the Landing Page URL no problem. when I disconnect the device the device permission listed is removed (which is normal because the device dose not have a Serial Number, thus the permission granted by the user can'not be persisted) but the disconnect event dose not appear? not sure what I am doing wrong.
So my question is, how can I detect/get the callback from the disconnect event? or is this a bug and I should file it? any help would be appreciated, thank you.
As well, after adding the Serial Number to the device, I get a "NotFoundError: Device unavailable" when I try to open the device with "return device.open()", but the "navigator.usb.requestDevice" returns the correct device.