HIDConnectionEvent
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
Note: This feature is available inWeb Workers, except forShared Web Workers.
TheHIDConnectionEvent interface of theWebHID API represents HID connection events, and is the event type passed toconnect anddisconnect event handlers when a device's connection state changes.
In this article
Constructor
HIDConnectionEvent()ExperimentalReturns a new
HIDConnectionEventobject. Typically this constructor is not used as events are created when a device's connection state changes.
Instance properties
This interface also inherits properties fromEvent.
HIDConnectionEvent.deviceRead onlyExperimentalReturns the
HIDDeviceinstance representing the device associated with the connection event.
Examples
The following example registers event listeners forconnect anddisconnect events, then prints theHIDDevice.productName to the console.
navigator.hid.addEventListener("connect", ({ device }) => { console.log(`HID connected: ${device.productName}`);});navigator.hid.addEventListener("disconnect", ({ device }) => { console.log(`HID disconnected: ${device.productName}`);});Specifications
| Specification |
|---|
| WebHID API> # dom-hidconnectionevent> |