Serial.getPorts()

Secure context

This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

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 which the origin has permission to access.

Syntax

var promise = Serial.getPorts();

Return value

A Promise that resolves with an array of SerialPort objects.

Exceptions

DOMException "SecurityError"
The returned Promise rejects with this error if a Feature Policy restricts use of this API or a permission to use it has not granted via a user gesture.

Examples

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.
});

Specifications

Specification Status Comment
Web Serial API
The definition of 'Serial.getPorts()' in that specification.
Draft Initial definition.

Browser compatibility

BCD tables only load in the browser