files/en-us/web/api/serial/getports/index.md
{{APIRef("Web Serial API")}}{{SecureContext_Header}}{{SeeCompatTable}}{{AvailableInWorkers("window_and_dedicated")}}
The getPorts() method of the {{domxref("Serial")}} interface returns a {{jsxref("Promise")}} that resolves with an array of {{domxref("SerialPort")}} objects representing serial ports connected to the host which the origin has permission to access.
getPorts()
None.
A {{jsxref("Promise")}} that resolves with an array of {{domxref("SerialPort")}} objects.
SecurityError {{domxref("DOMException")}}
Promise rejects with this error in either of the following situations:
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}}
{{Compat}}