The connect and disconnect events are currently only fired on navigator.usb. For disconnects in particular it is useful to be able to listen for a particular device being disconnected. For the Web Serial API we did this by making SerialPort itself an EventTarget and defining a custom parent algorithm so that the events bubble to navigator.serial after being fired on the SerialPort.
We should do the same for this API. I believe such a change would be backwards compatible. The only difference is that the target attribute of the USBConnectionEvent would be set to the value of its device attribute instead of navigator.usb.
The current workaround developers have to employ is to register an event handler and compare it against the device they are interested in.
The
connect
anddisconnect
events are currently only fired onnavigator.usb
. For disconnects in particular it is useful to be able to listen for a particular device being disconnected. For the Web Serial API we did this by makingSerialPort
itself anEventTarget
and defining a custom parent algorithm so that the events bubble tonavigator.serial
after being fired on theSerialPort
.We should do the same for this API. I believe such a change would be backwards compatible. The only difference is that the
target
attribute of theUSBConnectionEvent
would be set to the value of itsdevice
attribute instead ofnavigator.usb
.The current workaround developers have to employ is to register an event handler and compare it against the device they are interested in.
CC @RReverser