GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • MDN
  • HTML: Markup language
  • Elements
  • Global attributes
  • Attributes
  • See all…
  • Responsive images
  • HTML cheatsheet
  • Date & time formats
  • See all…
  • SVG
  • MathML
  • XML
  • CSS: Styling language

This view

  • Original page
  • New address

GeezerVison is showing developer.mozilla.org — Serial - Web APIs | MDN

Serial

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

  • See full compatibility
  • Learn more

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 Serial interface of the Web Serial API provides attributes and methods for finding and connecting to serial ports from a web page.

Instance methods

Serial.requestPort()

Returns a Promise that resolves with an instance of SerialPort representing the device chosen by the user. This method must be called via transient activation.

Serial.getPorts()

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.

Events

The following events are available to Serial via event bubbling from SerialPort:

SerialPort connect event

An event fired when a port has been connected to the device.

SerialPort disconnect event

An event fired when a port has been disconnected from the device.

Examples

Basic usage

The following example shows how a site can check for available ports and allow the user to grant it permission to access additional ports.

On load event listeners are added for the connect and disconnect events so that the site can react when a device is connected or disconnected from the system. The getPorts() method is then called to see which ports are connected that the site already has access to.

If the site doesn't have access to any connected ports it has to wait until it has user activation to proceed. In this example we use a click event handler on a button for this task. A filter is passed to requestPort() with a USB vendor ID in order to limit the set of devices shown to the user to only USB devices built by a particular manufacturer.

js
navigator.serial.addEventListener("connect", (e) => {
  // Connect to `e.target` or add it to a list of available ports.
});

navigator.serial.addEventListener("disconnect", (e) => {
  // Remove `e.target` from the list of available ports.
});

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

button.addEventListener("click", () => {
  const usbVendorId = 0xabcd;
  navigator.serial
    .requestPort({ filters: [{ usbVendorId }] })
    .then((port) => {
      // Connect to `port` or add it to the list of available ports.
    })
    .catch((e) => {
      // The user didn't select a port.
    });
});

Specifications

Specification
WebSerial
# serial-interface

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on May 19, 2026 by MDN contributors.

View this page on GitHub • Report a problem with this content
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.