HID: connect event
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.
Theconnect event of theHID interface fires when the user agent connects to a HID device.
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
addEventListener("connect", (event) => { })onconnect = (event) => { }Event type
AHIDConnectionEvent. Inherits fromEvent.
Event properties
In addition to the properties listed below, properties from the parent interface,Event, are available.
Examples
In the following example an event listener is registered to listen for the connection of a device. The name of the device is then printed to the console usingHIDDevice.productName.
navigator.hid.addEventListener("connect", ({ device }) => { console.log(`HID connected: ${device.productName}`);});Specifications
| Specification |
|---|
| WebHID API> # dom-hid-onconnect> |