Serial.onconnect
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The onconnect
event handler of the Serial
interface is called when a port has been connected from a device. This method receives an Event
object. The target of this event is the SerialPort
interface that has been disconnected.
This event is only fired for ports associated with removable devices such as those connected via USB. The user must grant the origin permission to access this device during a call to requestPort()
before this event will be fired.
Syntax
Serial.onconnect = function(event); Serial.addEventListener('connect', function(event));
Example
The following example shows an event listener for the connect
event,. This allows the site to react when a port is connected.
navigator.serial.addEventListener('connect', (e) => { // Connect to `e.target` or add it to a list of available ports. });
Specifications
Specification |
---|
Web Serial API # dom-serial-onconnect |
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 | |
onconnect |
89 |
89 |
No |
No |
No |
No |
No |
No |
No |
No |
No |
No |
© 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/Serial/onconnect