W3cubDocs

/Web APIs

Serial: getPorts() method

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

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

js

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 if a Permissions Policy blocks the use of this feature or a user permission prompt was denied.

Examples

The following example uses getPorts() to initialize a list of available ports.

js

navigator.serial.getPorts().then((ports) => {
  // Initialize the list of available ports with `ports` on page load.
});

Specifications

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
getPorts 89 89 No No 75 No No No No No No No

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Serial/getPorts