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.
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener('connect', event => { });
onconnect = event => { };
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.
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 => {
});
The connect
event bubbles up to the Serial
object where you can listen for any newly-connected ports.
navigator.serial.addEventListener('connect', event => {
});