USBConnectionEvent
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The USBConnectionEvent
interface of the WebUSB API is the event type passed to USB.onconnect
and USB.ondisconnect
when the user agent detects that a new USB device has been connected or disconnected.
Constructor
USBConnectionEvent()
Experimental-
Returns a
USBConnectionEvent
object.
Instance properties
USBConnectionEvent.device
Read only Experimental-
Returns a
USBDevice
object representing the current device.
Examples
In the following example listening for connect and disconnect events is used to add and remove the devices from the user interface of an application.
js
navigator.usb.addEventListener("connect", (event) => {
// Add event.device to the UI.
});
navigator.usb.addEventListener("disconnect", (event) => {
// Remove event.device from the UI.
});
Specifications
Specification |
---|
WebUSB API # usbconnectionevent |
Browser compatibility
BCD tables only load in the browser