SerialPort: disconnect event

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Note: This feature is available in Dedicated Web Workers.

The disconnect event of the SerialPort interface is fired when the port has disconnected from the device. This event is only fired for ports associated with removable devices such as those connected via USB.

This event bubbles to the instance of Serial that returned this interface.


Use the event name in methods like addEventListener(), or set an event handler property.

addEventListener("disconnect", (event) => {});

ondisconnect = (event) => {};

Event type

A generic Event.


This event bubbles to Serial. The property refers to the SerialPort object that bubbles up.

For more information, see Event bubbling.


Notify when a specific port disconnects

Here the event listener is installed on a specific SerialPort object.

port.addEventListener("disconnect", (event) => {
  // notify that the port has become unavailable

Listening for any ports that become unavailable

The disconnect event bubbles up to the 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 `` to refer to the unavailable port


Web Serial API
# dfn-disconnect
Web Serial API
# dom-serialport-ondisconnect

Browser compatibility

BCD tables only load in the browser

See also