files/en-us/web/api/serialport/disconnect_event/index.md
{{SecureContext_Header}}{{APIRef("Web Serial API")}}{{SeeCompatTable}}{{AvailableInWorkers("window_and_dedicated")}}
The disconnect event of the {{domxref("SerialPort")}} interface is fired when the port disconnects from the device.
More specifically, the disconnect event fires when a port that was previously logically connected after a user granted permission for a site to access it (following a {{domxref("Serial.requestPort()")}} call) is no longer connected.
This event bubbles to the instance of {{domxref("Serial")}} that returned this interface. The event.target property refers to the {{domxref('SerialPort')}} object that bubbles up.
For more information, see Event bubbling.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("disconnect", (event) => { })
ondisconnect = (event) => { }
A generic {{domxref("Event")}}.
Here the event listener is installed on a specific {{domxref("SerialPort")}} object.
port.addEventListener("disconnect", (event) => {
// notify that the port has become unavailable
});
The disconnect event bubbles up to the {{domxref("Serial")}} object where you can listen for any ports that become unavailable.
navigator.serial.addEventListener("disconnect", (event) => {
// notify that a port has become unavailable
// use `event.target` to refer to the unavailable port
});
{{Specifications}}
{{Compat}}