JavaScript Navigator serial Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Limited availability
Secure context

What You’ll Learn

navigator.serial is the entry point for the Web Serial API. Learn the Serial object, getPorts / requestPort, connect events, secure context rules, five examples, and try-it labs.

01

Kind

Read-only property

02

Returns

Serial object

03

Availability

Limited / not Baseline

04

Context

Secure (HTTPS)

05

Pick port

requestPort()

06

Reuse

getPorts()

Introduction

Serial ports let computers talk to gadgets line-by-line — microcontrollers (ESP32, micro:bit), 3D printers, USB-CDC adapters, and some Bluetooth devices that expose a virtual serial port.

navigator.serial is read-only. When Web Serial is available, it returns a Serial object. MDN notes the same instance is always returned. You use that object to list granted ports, ask the user to pick a new one, and listen for connect / disconnect events.

💡
Permission first

A site starts with no serial access. requestPort() shows a picker and needs a user gesture (button click). Always explain why you need the device.

⚠️
Limited availability

MDN: not Baseline — many browsers omit Web Serial. Feature-detect, require HTTPS, and keep a fallback (native tool, file upload, etc.). No Deprecated / Experimental / Non-standard banner is required on current MDN for this property.

Understanding the serial Property

Think of navigator.serial as the Web Serial “front desk.” The real work happens on the Serial object it returns.

  • Serial object — entry point with methods and events.
  • requestPort() — user picks a port and grants access (returns a SerialPort).
  • getPorts() — list ports already granted earlier.
  • connect / disconnect — events when devices appear or leave.
  • Permissions Policy — if blocked, navigator.serial may be missing entirely.

📝 Syntax

General form of the property:

JavaScript
navigator.serial

Value

  • A Serial object when Web Serial is available in this context.
  • Missing / unavailable when unsupported, insecure, or blocked by policy.

Common patterns

JavaScript
// Feature-detect:
if ("serial" in navigator && navigator.serial) {
  // Web Serial entry point is available
}

// List ports already granted (MDN page-load pattern):
navigator.serial.getPorts().then((ports) => {
  // Initialize UI with ports
});

// Request a port (must run from a click handler):
async function pickPort() {
  const port = await navigator.serial.requestPort({
    // Optional filters, e.g. { filters: [{ usbVendorId: 0xabcd }] }
  });
  console.log(port);
}

⚡ Quick Reference

GoalCode
Get Web Serial entrynavigator.serial
Detect API"serial" in navigator && navigator.serial
Pick a portawait navigator.serial.requestPort(options)
List granted portsawait navigator.serial.getPorts()
Listen for plug-innavigator.serial.addEventListener("connect", …)
Secure page?window.isSecureContext
Status (MDN)Limited availability / not Baseline

🔍 At a Glance

Four facts to remember about navigator.serial.

Returns
Serial

Web Serial entry

Availability
limited

Not Baseline

HTTPS
required

Secure context

Permission
user gesture

requestPort

📋 Web Serial vs WebHID vs WebUSB (concept)

Web Serial (navigator.serial)WebHID (navigator.hid)WebUSB (typical)
FocusSerial / virtual COM portsHID-class devicesBroader USB access
Entrynavigator.serialnavigator.hidnavigator.usb
PermissionrequestPort()requestDevice()Similar user picker
Best forBoards, printers, serial gadgetsGamepads, specialty HIDCustom USB protocols
StatusLimited — check MDNLimited / check MDNLimited — check MDN

Examples Gallery

Examples follow MDN Web Serial / navigator.serial patterns. Prefer Try It Yourself on HTTPS in a Chromium browser with a real serial device. requestPort needs a button click.

📚 Getting Started

Detect Web Serial and confirm a secure context.

Example 1 — Feature Detection

Check whether the Web Serial entry point exists on navigator.

JavaScript
const supported = Boolean(navigator.serial);
console.log(supported ? "Web Serial available" : "Web Serial missing");
Try It Yourself

How It Works

If missing, show a message and keep a non-serial path (native tool, file export, etc.).

Example 2 — Secure Context Check

Web Serial requires HTTPS / localhost — check both flags together.

JavaScript
console.log("secure: " + window.isSecureContext);
console.log("serial: " + Boolean(navigator.serial));

if (!window.isSecureContext) {
  console.log("Serve over HTTPS to use Web Serial");
} else if (!navigator.serial) {
  console.log("Secure, but Web Serial not exposed");
} else {
  console.log("Ready to call getPorts / requestPort");
}
Try It Yourself

How It Works

Policy blocks can also hide navigator.serial even on HTTPS — treat “missing” as unsupported for this page.

📈 Practical Patterns

List granted ports, request a new one, and listen for plug events.

Example 3 — List Granted Ports

getPorts() returns serial ports the site already has access to (MDN page-load pattern).

JavaScript
async function listGranted() {
  if (!navigator.serial) {
    return "Web Serial not supported.";
  }
  const ports = await navigator.serial.getPorts();
  return "granted ports: " + ports.length;
}

listGranted().then(console.log);
Try It Yourself

How It Works

On return visits, reconnect to known ports without showing the picker again (until permission is revoked).

Example 4 — Request a Port (Button Click)

Open the picker from a user gesture. Prefer vendor filters in production.

JavaScript
async function pickSerialPort() {
  if (!navigator.serial) {
    throw Error("Web Serial not supported.");
  }
  // Demo: no filters = show available ports.
  // Real apps often pass filters: [{ usbVendorId: 0xabcd }]
  const port = await navigator.serial.requestPort();
  return "Port selected (SerialPort object ready)";
}

// Call pickSerialPort() from a button onclick — not on page load.
// Catch errors when the user cancels the dialog.
Try It Yourself

How It Works

Calling requestPort() without a user gesture usually fails. Wire it to a button in the try-it lab.

Example 5 — Connect / Disconnect Listeners

React when a serial device is plugged in or removed (MDN pattern).

JavaScript
function watchSerial() {
  if (!navigator.serial) {
    return { ok: false, message: "Web Serial not supported." };
  }
  navigator.serial.addEventListener("connect", (e) => {
    // Connect to e.target or add it to a list of available ports.
    console.log("Serial connected");
  });
  navigator.serial.addEventListener("disconnect", (e) => {
    // Remove e.target from the list of available ports.
    console.log("Serial disconnected");
  });
  return { ok: true, message: "Listening for connect / disconnect" };
}

console.log(JSON.stringify(watchSerial()));
Try It Yourself

How It Works

After you set listeners, plug/unplug a previously allowed device to see the events in a supporting browser.

🚀 Common Use Cases

  • Microcontroller tooling — flash, monitor, or configure ESP32 / micro:bit style boards in the browser.
  • 3D printers & CNC — send G-code over a serial connection with user consent.
  • Sensor dashboards — stream readings from USB-serial adapters.
  • Education / demos — teach serial protocols without installing a native IDE.
  • Progressive enhancement — Web Serial when available; otherwise guide users to another path.

🧠 How navigator.serial Works

1

Detect the entry point

navigator.serial must exist in a secure context.

Detect
2

User grants a port

requestPort() from a button click shows the picker.

Permission
3

Reuse with getPorts()

Later visits can list ports the site already may use.

Reuse
4

Open and talk to SerialPort

Open the port, then read / write streams for your device protocol.

📝 Notes

  • Limited availability (MDN) — not Baseline; feature-detect always.
  • Not Deprecated, Experimental, or Non-standard on current MDN — no status banner required.
  • Secure context required (HTTPS / localhost).
  • Returns a Serial object; the same instance is always returned.
  • Related: hid, serviceWorker, bluetooth, Window.

Limited Browser Support

navigator.serial has Limited availability and is not Baseline (MDN). Support is strongest in Chromium-based browsers. Always feature-detect, use HTTPS, and keep a non-serial fallback.

Limited · Not Baseline

Navigator.serial

Web Serial entry point for serial / virtual COM devices. Great for board tooling when supported — never assume universal availability.

Limited Not Baseline
Google Chrome Web Serial / Chromium path (check version)
Limited
Microsoft Edge Follow Chromium Web Serial support
Limited
Opera Follow Chromium Web Serial support
Limited
Mozilla Firefox Typically unavailable — feature-detect
Unavailable
Apple Safari Typically unavailable — feature-detect
Unavailable
Internet Explorer No Web Serial API support
Unavailable
serial Limited

Bottom line: Detect navigator.serial, call requestPort from a user gesture, reuse getPorts on reload, and hide serial UI when the API is missing.

Conclusion

navigator.serial is the Web Serial API entry point. Feature-detect it, use HTTPS, call requestPort() from a button click, reuse getPorts() for known devices, and keep a fallback when the API is missing.

Continue with serviceWorker, hid, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect navigator.serial first
  • Serve demos over HTTPS
  • Call requestPort() from a user gesture
  • Filter by vendor ID when you know your hardware
  • Handle cancel / permission errors gracefully

❌ Don’t

  • Assume every browser supports Web Serial
  • Open the picker on page load without a click
  • Require serial for core site features
  • Ignore Permissions Policy blocks
  • Assign to navigator.serial

Key Takeaways

Knowledge Unlocked

Five things to remember about serial

Web Serial entry point — pick ports with permission, reuse getPorts, stay on HTTPS.

5
Core concepts
🔌 02

Pick

requestPort

API
🔁 03

Reuse

getPorts

Pattern
🔒 04

HTTPS

required

Security
🎯 05

Support

limited

Detect

❓ Frequently Asked Questions

It is a read-only Navigator property that returns a Serial object — the entry point for the Web Serial API so your page can find and connect to serial ports (including USB/Bluetooth devices that emulate a serial port).
MDN does not mark it Deprecated or Experimental. It has Limited availability (not Baseline) and requires a secure context. Always feature-detect and check browser support.
Yes. It is available only in secure contexts (HTTPS or localhost) in supporting browsers.
navigator.serial.requestPort(options) opens the browser’s port picker so the user can grant access to a selected serial device. Call it from a user gesture such as a button click. It resolves to a SerialPort.
navigator.serial.getPorts() returns ports the site already has access to. Use it on page load to reconnect without showing a new picker.
Unsupported browser, insecure context, or a Permissions Policy that blocks the serial feature — the property will not be available when blocked.
Did you know?

Web Serial is not only for old RS-232 cables. Many modern USB and Bluetooth gadgets expose a virtual serial port (USB CDC-ACM or Bluetooth SPP) that navigator.serial can reach — distinct from raw WebUSB or WebHID access.

Learn serviceWorker Next

Baseline Service Worker API entry point for PWAs and offline caching.

serviceWorker →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful