files/en-us/web/api/hid/connect_event/index.md
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers("window_and_worker_except_shared")}}
The connect event of the {{domxref("HID")}} interface fires when the user agent connects to a HID device.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("connect", (event) => { })
onconnect = (event) => { }
A {{domxref("HIDConnectionEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("HIDConnectionEvent")}}
In addition to the properties listed below, properties from the parent interface, {{domxref("Event")}}, are available.
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 using {{domxref("HIDDevice.productName")}}.
navigator.hid.addEventListener("connect", ({ device }) => {
console.log(`HID connected: ${device.productName}`);
});
{{Specifications}}
{{Compat}}