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

The ondisconnect EventHandler of the Serial interface is called when the port has been disconnected from the device. This method receives an Event object. The target of this event is the SerialPort interface that has been disconnected.

This event is only fired for ports associated with removable devices such as those connected via USB. The user must grant the origin permission to access this device during a call to requestPort() before this event will be fired.


Serial.ondisconnect = function(event);
Serial.addEventListener('disconnect', function(event));


The following example shows an event listener for the disconnect event,. This allows the site to react when a port is disconnected.

navigator.serial.addEventListener('disconnect', (e) => {
  // Remove `` from the list of available ports.


Web Serial API
# dom-serial-ondisconnect

Browser compatibility

BCD tables only load in the browser