Serial: getPorts() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
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 which the origin has permission to access.
Syntax
getPorts()
Parameters
None.
Return value
A Promise that resolves with an array of SerialPort objects.
Exceptions
SecurityErrorDOMException-
The returned
Promiserejects with this error in either of the following situations:- A
serialPermissions Policy blocks the use of this feature. - A user permission prompt was denied.
- A
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 |
|---|
| Web Serial API # dom-serial-getports |
Browser compatibility
| desktop | mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
getPorts
|
|
|
|
|
|
|
|
|
|
|
|
|
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- In development. Supported in a pre-release version.
- In development. Supported in a pre-release version.
- No support
- No support
- See implementation notes.