WebUSB API
The USBConnectionEvent interface of the WebUSB API is the event type passed to USB USB.connect_event and USB.disconnect_event events when the user agent detects that a new USB device has been connected or disconnected.
Constructor
- USBConnectionEvent.USBConnectionEvent
- : Returns a
USBConnectionEventobject.
- : Returns a
Instance properties
- USBConnectionEvent.device
- : 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.
navigator.usb.addEventListener("connect", (event) => {
// Add event.device to the UI.
});
navigator.usb.addEventListener("disconnect", (event) => {
// Remove event.device from the UI.
});
Specifications
Browser compatibility
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
