WebUSB

Also known as: WebUSB API

On this page 7

WebUSB is a JavaScript API that lets a web page communicate directly with USB devices after the user explicitly selects a device in a browser prompt. Among Web APIs, the WebUSB API exposes low-level USB transfers to web applications, so hardware such as microcontroller boards, lab instruments and label printers can be configured from a browser without installing native drivers or desktop software.

The specification is developed as a Draft Community Group Report in the W3C Web Platform Incubator Community Group. It ships in Chromium-based browsers such as Chrome, Edge and Opera on desktop and Android, while Firefox and Safari have declined to implement it over security and privacy concerns.

How WebUSB connects a page to a device

WebUSB works through a permission-gated, promise-based flow: the page requests a device, the user picks one from a browser chooser, and the page then opens it and exchanges data through standard USB transfer types. A call to navigator.usb.requestDevice() must be triggered by a user gesture such as a click, and it accepts filters on vendor ID, product ID or interface class to limit the list shown.

After selection, the returned USBDevice object goes through a fixed sequence. The table below summarizes the main steps and the method used at each one.

StepMethodPurpose
Request accessnavigator.usb.requestDevice()User chooses a device in a prompt
Open sessiondevice.open()Starts communication with the device
Select configurationdevice.selectConfiguration(1)Activates a device configuration
Claim interfacedevice.claimInterface(n)Gains exclusive use of an interface
Transfer datatransferIn() or transferOut()Reads or writes endpoint data
Release and closereleaseInterface() and close()Frees the device for other software
Typical WebUSB connection sequence

Once access is granted, navigator.usb.getDevices() returns previously authorized devices without a new prompt, and connect and disconnect events report hot-plugging. Optional WebUSB descriptors in device firmware can advertise a landing page URL, which Chromium may surface as a notification when the device is plugged in.

USB transfer types available to web code

WebUSB exposes four USB transfer types, mirroring the USB 2.0 specification, and the right choice depends on how the device firmware defines its endpoints. All transfers return promises that resolve with a status such as ok, stall or babble.

Transfer typeWebUSB methodsCharacteristicsTypical use
ControlcontrolTransferIn/Out()Setup packets, guaranteed deliveryCommands and configuration
BulktransferIn/Out()Reliable, no timing guaranteeFirmware images, file data
InterrupttransferIn/Out()Small, polled at fixed intervalsStatus updates, sensor readings
IsochronousisochronousTransferIn/Out()Timed delivery, no retriesAudio and video streams
WebUSB transfer types and their uses

Control transfers specify a request type, recipient, request code, value and index, exactly as in the USB protocol. Developers therefore need the device’s protocol documentation or firmware source; WebUSB moves bytes but does not interpret them.

Security model and protected device classes

The WebUSB security model rests on explicit user choice, secure contexts and a blocklist. The API is available only over HTTPS or localhost, cannot be invoked without a user gesture, and can be disabled by Permissions Policy in embedded frames or by enterprise administrators.

Chromium also refuses to expose protected interface classes that the operating system already handles, because raw access could enable keylogging or data theft. Interfaces for HID, mass storage, audio, video, smart cards and wireless controllers are blocked, and a maintained blocklist excludes specific devices known to be dangerous, such as some security keys.

Critics argue that users cannot judge what a page will do with a device once access is granted. A malicious site could, for example, reflash firmware on a poorly protected device. This concern is the main reason Mozilla and Apple rejected the API, so cross-browser support remains unlikely.

WebUSB belongs to a family of device access APIs, each targeting a different layer. The comparison below helps decide which one fits a given device.

APIDevice scopeAbstraction levelBest fit
WebUSBGeneric USB devicesRaw endpoints and transfersVendor-specific USB protocols
WebHIDHuman interface devicesHID reportsGame controllers, macro keypads
Web SerialSerial ports, USB serial adaptersByte streamsArduino boards, modems, GPS units
Web Bluetooth APIBluetooth Low Energy peripheralsGATT servicesFitness trackers, beacons
Gamepad APIStandard game controllersMapped buttons and axesBrowser games
Browser hardware access APIs

A common mistake is choosing WebUSB for a device that already enumerates as a serial port or HID device. The operating system claims those interfaces, so WebUSB cannot open them, and Web Serial or WebHID is the correct route.

Practical use and limitations

WebUSB is most valuable when eliminating native software removes real friction. Firmware update tools, Android device flashing utilities, educational microcontroller editors and point-of-sale peripherals are the clearest successes.

SituationRecommendationReason
Custom device, own firmwareUse WebUSBFull control over descriptors and protocol
Audience uses Safari or FirefoxProvide a native fallbackNo support in those browsers
Device is a keyboard or mouseUse WebHID insteadHID class is protected
Windows device without WinUSBAdd WinUSB descriptorsDriver must allow user-space access
Deciding whether WebUSB is appropriate

Operating system drivers create the most practical friction. On Windows, a device must bind to the WinUSB driver, ideally through Microsoft OS descriptors in firmware; on Linux, udev rules may be needed for permission. Only one program can claim an interface at a time, so a running desktop tool can block the web page.

Robust implementations also handle disconnects during transfers, retry stalled endpoints with clearHalt(), and keep large transfers in chunks that match the endpoint packet size. Long firmware uploads should report progress so that users do not unplug the device mid-write, which can leave hardware in an unrecoverable bootloader state.

Put simply

WebUSB lets a website talk to a gadget plugged into a computer, such as a small circuit board or a printer, without asking the user to install special software first.

The browser acts as a careful doorkeeper. A website cannot see any device until the user picks it from a list, and sensitive devices like keyboards and memory sticks stay off limits. The key point: it trades convenience for trust, which is why only some browsers offer it.

In practice

A school robotics program gives students microcontroller boards running firmware with WebUSB descriptors. Instead of installing a desktop programming tool on 30 locked-down Chromebooks, the teacher points students to a web-based editor served over HTTPS.

Each student clicks Connect, selects the board from the browser prompt, and the page claims the vendor interface, then sends a compiled program of about 40 KB through bulk transfers. Uploading takes a few seconds, and the board restarts with the new code. The program saves hours of setup time each term, while families using Safari at home receive instructions for a small offline uploader as a fallback.