dom / latest / serialport / disconnect_event.html /

SerialPort: disconnect

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

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.

Syntax

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

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

ondisconnect = event => { };

Event type

A generic Event.

Bubbling

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

For more information, see Event bubbling and capture.

Examples

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 `event.target` to refer to the unavailable port
});

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
disconnect_event
89
89
No
No
75
No
No
No
No
No
No
No

See also

© 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/SerialPort/disconnect_event