Serial.ondisconnect

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.

Syntax

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

Example

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 `e.target` from the list of available ports.
});

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
ondisconnect
89
89
No
No
No
No
No
No
No
No
No
No

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Serial/ondisconnect