SerialPort: disconnect event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Dedicated Web Workers.
The disconnect event of the SerialPort interface is fired when the port disconnects from the device.
Description
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 Serial.requestPort() call) is no longer connected.
Bubbling
This event bubbles to the instance of Serial that returned this interface. The event.target property refers to the SerialPort object that bubbles up.
For more information, see Event bubbling.
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.
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
| Specification |
|---|
| Web Serial API # dfn-disconnect |
| Web Serial API # dom-serialport-ondisconnect |
Browser compatibility
| desktop | mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
disconnect event
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bluetooth RFCOMM serial ports dispatch
disconnect events
|
|
|
|
|
|
|
|
|
|
|
|
|
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- In development. Supported in a pre-release version.
- In development. Supported in a pre-release version.
- No support
- No support
- Experimental. Expect behavior to change in the future.
- See implementation notes.
See also
connectevent