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 connect event of the SerialPort interface is fired when the port connects to the device.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("connect", (event) => { })
onconnect = (event) => { }A generic Event.
More specifically, the connect event fires when the port becomes logically connected to the device. This happens after a user grants permission for a site to access the port that the device is attached to, following a Serial.requestPort() call:
This event bubbles up to the Serial instance that returned this interface. The event.target property refers to the SerialPort object that bubbles up.
For more information, see Event bubbling.
The Serial.requestPort() method returns a Promise that resolves with a SerialPort chosen by the user.
// Prompt user to choose a serial port
const port = await navigator.serial.requestPort();
port.addEventListener("connect", (event) => {
// notify that the chosen port is connected
});The connect event bubbles up to the Serial object where you can listen for any newly-connected ports.
navigator.serial.addEventListener("connect", (event) => {
// notify that a new port is available
// use `event.target` to refer to the newly-added port
});disconnect event