files/en-us/web/api/usb/disconnect_event/index.md
{{APIRef("WebUSB API")}}{{SeeCompatTable}}{{SecureContext_Header}}{{AvailableInWorkers}}
The disconnect event of the {{DOMxRef("USB")}} interface is fired whenever a paired device is disconnected.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("disconnect", (event) => { })
ondisconnect = (event) => { }
A {{domxref("USBConnectionEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("USBConnectionEvent")}}
In addition to the properties listed below, properties from the parent interface, {{domxref("Event")}}, are available.
Once a USB device is disconnected, you might want to update the UI.
navigator.usb.addEventListener("disconnect", (event) => {
// Remove event.device from the UI.
});
Alternatively, you can use the USB.ondiscconnect event handler property to establish a handler for the disconnect event:
navigator.usb.ondisconnect = (event) => {
// Remove event.device from the UI.
};
{{Specifications}}
{{Compat}}