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()
Fundamentals
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.
Concept
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.
Foundation
📝 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);
}
Cheat Sheet
⚡ Quick Reference
Goal
Code
Get Web Serial entry
navigator.serial
Detect API
"serial" in navigator && navigator.serial
Pick a port
await navigator.serial.requestPort(options)
List granted ports
await navigator.serial.getPorts()
Listen for plug-in
navigator.serial.addEventListener("connect", …)
Secure page?
window.isSecureContext
Status (MDN)
Limited availability / not Baseline
Snapshot
🔍 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
Compare
📋 Web Serial vs WebHID vs WebUSB (concept)
Web Serial (navigator.serial)
WebHID (navigator.hid)
WebUSB (typical)
Focus
Serial / virtual COM ports
HID-class devices
Broader USB access
Entry
navigator.serial
navigator.hid
navigator.usb
Permission
requestPort()
requestDevice()
Similar user picker
Best for
Boards, printers, serial gadgets
Gamepads, specialty HID
Custom USB protocols
Status
Limited — check MDN
Limited / check MDN
Limited — check MDN
Hands-On
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");
Web Serial missing
(or "Web Serial available" in a supporting browser)
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");
}
Web Serial not supported.
(or "granted ports: 0" / a positive count)
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.
Web Serial not supported.
(or "Port selected…" / cancel error message)
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()));
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.
LimitedNot Baseline
Google ChromeWeb Serial / Chromium path (check version)
Limited
Microsoft EdgeFollow Chromium Web Serial support
Limited
OperaFollow Chromium Web Serial support
Limited
Mozilla FirefoxTypically unavailable — feature-detect
Unavailable
Apple SafariTypically unavailable — feature-detect
Unavailable
Internet ExplorerNo Web Serial API support
Unavailable
serialLimited
Bottom line: Detect navigator.serial, call requestPort from a user gesture, reuse getPorts on reload, and hide serial UI when the API is missing.
Wrap Up
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.
Web Serial entry point — pick ports with permission, reuse getPorts, stay on HTTPS.
5
Core concepts
📄01
Returns
Serial
Value
🔌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.