JavaScript Navigator usb Property

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

What You’ll Learn

navigator.usb is the entry point for the WebUSB API. Learn the USB object, requestDevice / getDevices, connect events, secure context rules, five examples, and try-it labs.

01

Kind

Read-only property

02

Returns

USB object

03

Status

Experimental

04

Context

Secure (HTTPS)

05

Pick device

requestDevice()

06

Reuse

getDevices()

Introduction

USB devices range from custom gadgets and Arduino-style boards to specialty hardware that does not fit neatly into serial or HID protocols. WebUSB lets a web page talk to those devices — with the user’s permission.

navigator.usb is read-only. When WebUSB is available, it returns a USB object you use to request access, list previously paired devices, and listen for connect / disconnect events.

💡
Permission first

You cannot silently open every USB device on the user’s desk. requestDevice() starts a pairing flow and needs a user gesture (button click). Always explain why you need the device.

Understanding the usb Property

Think of navigator.usb as the WebUSB “front desk.” The real work happens on the USB object it returns.

  • USB object — entry point with methods and events.
  • requestDevice() — user picks a device and grants access (returns a USBDevice).
  • getDevices() — list previously paired attached devices.
  • connect / disconnect — events when paired devices appear or leave.
  • Filters — limit the picker by vendorId, productId, and related fields.
  • Experimental — feature-detect; do not require it for core UX.

📝 Syntax

General form of the property:

JavaScript
navigator.usb

Value

  • A USB object when WebUSB is available in this context.
  • Missing / unavailable when unsupported, insecure, or blocked.

Common patterns

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

// Request a device (must run from a click handler):
async function pickDevice() {
  const filters = [
    { vendorId: 0x1209, productId: 0xa800 },
    { vendorId: 0x1209, productId: 0xa850 }
  ];
  const device = await navigator.usb.requestDevice({ filters });
  console.log(device.productName);
}

// List previously paired devices:
const known = await navigator.usb.getDevices();

⚡ Quick Reference

GoalCode
Get WebUSB entrynavigator.usb
Detect API"usb" in navigator && navigator.usb
Pick a deviceawait navigator.usb.requestDevice({ filters })
List paired devicesawait navigator.usb.getDevices()
Listen for plug-innavigator.usb.addEventListener("connect", …)
Secure page?window.isSecureContext
Status (MDN)Experimental / not Baseline

🔍 At a Glance

Four facts to remember about navigator.usb.

Returns
USB

WebUSB entry

Status
experimental

Not Baseline

HTTPS
required

Secure context

Permission
user gesture

requestDevice

📋 WebUSB vs Web Serial vs WebHID

WebUSB (navigator.usb)Web SerialWebHID
FocusBroader USB device accessSerial / virtual COMHID-class devices
Pick methodrequestDevice()requestPort()requestDevice()
ReturnsUSBDeviceSerialPortHIDDevice[]
Best forCustom USB protocolsBoards / printers over serialGamepads / HID gadgets
StatusExperimental / limitedLimited — check MDNLimited / check MDN

Examples Gallery

Examples follow MDN WebUSB / navigator.usb patterns. Prefer Try It Yourself on HTTPS in a Chromium browser with a real USB device. requestDevice needs a button click.

📚 Getting Started

Detect WebUSB and confirm a secure context.

Example 1 — Feature Detection

Check whether the WebUSB entry point exists on navigator.

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

How It Works

If missing, show a message and keep a non-WebUSB path (native tool, firmware updater, etc.).

Example 2 — Secure Context Check

WebUSB requires HTTPS / localhost — check both flags together.

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

if (!window.isSecureContext) {
  console.log("Serve over HTTPS to use WebUSB");
} else if (!navigator.usb) {
  console.log("Secure, but WebUSB not exposed");
} else {
  console.log("Ready to call getDevices / requestDevice");
}
Try It Yourself

How It Works

Treat “missing” as unsupported for this page — even on HTTPS in Safari / Firefox.

📈 Practical Patterns

List paired devices, request a new one, and listen for plug events.

Example 3 — List Paired Devices

getDevices() returns paired attached devices the site may already use.

JavaScript
async function listPaired() {
  if (!navigator.usb) {
    return "WebUSB not supported.";
  }
  const devices = await navigator.usb.getDevices();
  return "paired devices: " + devices.length;
}

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

How It Works

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

Example 4 — Request a Device (Button Click)

Open the pairing flow from a user gesture. Prefer real vendor/product filters.

JavaScript
async function pickUsbDevice() {
  if (!navigator.usb) {
    throw Error("WebUSB not supported.");
  }
  // Demo filters from MDN-style vendor/product IDs — replace with your hardware.
  const filters = [
    { vendorId: 0x1209, productId: 0xa800 },
    { vendorId: 0x1209, productId: 0xa850 }
  ];
  const device = await navigator.usb.requestDevice({ filters });
  return "Selected: " + (device.productName || "USB device");
}

// Call pickUsbDevice() from a button onclick — not on page load.
Try It Yourself

How It Works

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

Example 5 — Connect / Disconnect Listeners

React when a previously paired USB device is plugged in or removed.

JavaScript
function watchUsb() {
  if (!navigator.usb) {
    return { ok: false, message: "WebUSB not supported." };
  }
  navigator.usb.addEventListener("connect", (e) => {
    console.log("USB connected:", e.device.productName);
  });
  navigator.usb.addEventListener("disconnect", (e) => {
    console.log("USB disconnected:", e.device.productName);
  });
  return { ok: true, message: "Listening for connect / disconnect" };
}

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

How It Works

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

🚀 Common Use Cases

  • Custom USB gadgets — configure devices that speak a vendor USB protocol.
  • Firmware / flashing tools — browser-based updaters for supported boards.
  • Lab / education demos — teach USB transfers without a native installer.
  • Specialty hardware dashboards — meters, cameras, or instruments with WebUSB support.
  • Progressive enhancement — WebUSB when available; otherwise guide users to another path.

🧠 How navigator.usb Works

1

Detect the entry point

navigator.usb must exist in a secure context.

Detect
2

User pairs a device

requestDevice() from a button click starts pairing.

Permission
3

Reuse with getDevices()

Later visits can list paired attached devices.

Reuse
4

Talk to USBDevice

Open the device and transfer data with your protocol.

📝 Notes

  • Experimental — not Baseline; feature-detect always.
  • Secure context required (HTTPS / localhost).
  • Returns a USB object; main methods are requestDevice() and getDevices().
  • requestDevice() needs transient user activation (a click).
  • Related: userActivation, serial, hid, bluetooth.

Limited / Experimental Support

navigator.usb belongs to the experimental WebUSB API and is not Baseline. Support is limited (commonly Chromium-based). Always feature-detect, use HTTPS, and keep a non-WebUSB fallback.

Experimental · Not Baseline

Navigator.usb

WebUSB entry point for pairing USB devices from the browser. Great for demos when supported — never assume universal availability.

Limited Experimental
Google Chrome WebUSB / Chromium path (check version)
Limited
Microsoft Edge Follow Chromium WebUSB support
Limited
Opera Follow Chromium WebUSB support
Limited
Mozilla Firefox Typically unavailable — feature-detect
Unavailable
Apple Safari Typically unavailable — feature-detect
Unavailable
Internet Explorer No WebUSB API support
Unavailable
usb Limited

Bottom line: Detect navigator.usb, call requestDevice from a user gesture, reuse getDevices on reload, and hide USB UI when the API is missing.

Conclusion

navigator.usb is the experimental WebUSB entry point. Feature-detect it, use HTTPS, call requestDevice() from a button click, reuse getDevices() for known devices, and keep a fallback when the API is missing.

Continue with userActivation, serial, or the JavaScript hub.

💡 Best Practices

✅ Do

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

❌ Don’t

  • Assume every browser supports WebUSB
  • Open the picker on page load without a click
  • Require USB for core site features
  • Ignore Experimental / limited support warnings
  • Assign to navigator.usb

Key Takeaways

Knowledge Unlocked

Five things to remember about usb

Experimental WebUSB entry — pair with permission, reuse getDevices, stay on HTTPS.

5
Core concepts
🔌 02

Pick

requestDevice

API
🔁 03

Reuse

getDevices

Pattern
🔒 04

HTTPS

required

Security
🎯 05

Status

experimental

Detect

❓ Frequently Asked Questions

It is a read-only Navigator property that returns a USB object — the entry point for the WebUSB API so your page can find and connect to USB devices (with the user’s permission).
MDN marks the USB interface Experimental and not Baseline (limited availability). Always feature-detect, use HTTPS, and keep a non-WebUSB fallback.
Yes. It is available only in secure contexts (HTTPS or localhost) in supporting browsers.
navigator.usb.requestDevice(options) starts the browser’s pairing flow so the user can select a USB device. Call it from a user gesture. It resolves to a USBDevice.
navigator.usb.getDevices() returns previously paired attached devices as an array of USBDevice objects — without showing a new picker by itself.
WebUSB targets broader USB device access. Web Serial focuses on serial / virtual COM ports. WebHID focuses on HID-class devices. Choose the API that matches your hardware protocol.
Did you know?

The number of filters you pass to requestDevice() does not equal the number of devices shown. MDN: the browser lists matching devices it finds — one filter can match several attached gadgets.

Learn userActivation Next

Baseline API for transient and sticky user gesture state.

userActivation →

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