SerialPort: connect event
The connect event of the SerialPort interface is fired when a port has connected to 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("connect", (event) => {});
onconnect = (event) => {};
Event type
Bubbling
This event bubbles to Serial. The event.target property refers to the SerialPort object that bubbles up.
For more information, see Event bubbling.
Examples
Notify when a specific port connects
The Serial.requestPort() method returns a Promise that resolves with a SerialPort chosen by the user.
const port = await navigator.serial.requestPort();
port.addEventListener("connect", (event) => {
});
Listening for any newly-connected ports
The connect event bubbles up to the Serial object where you can listen for any newly-connected ports.
navigator.serial.addEventListener("connect", (event) => {
});
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 |
connect_event |
89 |
89 |
No |
No |
75 |
No |
No |
No |
No |
No |
No |
No |
See also