Firefox Tomorrow

web api instance method

Serial: getPorts() method

View on MDN ↗

Secure contextAvailable in 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.

Syntax

getPorts()

Parameters

None.

Return value

A Promise that resolves with an array of SerialPort objects.

Exceptions

  • SecurityError DOMException
    • : The returned Promise rejects with this error in either of the following situations:

Examples

List available ports

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

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.