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 getPorts() method of the Serial interface returns a Promise that resolves with an array of SerialPort objects representing serial ports connected to the host that the origin has permission to access.
getPorts()None.
A Promise that resolves with an array of SerialPort objects.
SecurityError DOMExceptionThe returned Promise rejects with this error in either of the following situations:
serial Permissions Policy blocks the use of this feature.The following example uses getPorts() to initialize a list of available ports.
navigator.serial.getPorts().then((ports) => {
// Initialize the list of available ports with `ports` on page load.
});