Serial: getPorts() method - Web APIs | MDN
Syntax
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.
js
navigator.serial.getPorts().then((ports) => {
// Initialize the list of available ports with `ports` on page load.
});
Specifications
| Specification |
|---|
| Web Serial API # dom-serial-getports |