Web Serial APIwindow_and_dedicated
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
SecurityErrorDOMException- : The returned
Promiserejects with this error in either of the following situations:- A Permissions-Policy/serial Permissions Policy blocks the use of this feature.
- A user permission prompt was denied.
- : The returned
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
Browser compatibility
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
