WebHID API
Published
WebHID API — The WebHID API lets a web app request access to non-standard Human Interface Devices via navigator.hid.requestDevice() and exchange input, output, and feature reports with them.
Browser & ecosystem support
Section titled “Browser & ecosystem support”- Legend
- Yes
- Partial
- Flag
- No
- Unknown
| Browser / Platform | Support | Versions | Confidence | Source | Notes |
|---|---|---|---|---|---|
| Chrome (Desktop) | Yes | 89 | high | source | — |
| Chrome (Android) | No | — | high | source | 1 |
| Edge (Desktop) | Yes | 89 | high | source | 2 |
| Firefox (Desktop) | No | — | high | source | 3 |
| Firefox (Android) | No | — | high | source | 45 |
| Safari (macOS) | No | — | high | source | 6 |
| Safari (iOS) | No | — | high | source | 78 |
| Samsung Internet | No | — | high | source | 910 |
| WebView (Android) | No | — | high | source | 1112 |
- No Chrome Android support is recorded in browser-compat-data.
- Derived by browser-compat-data mirroring from Chrome.
- No Firefox support is recorded in browser-compat-data.
- No Firefox for Android support is recorded in browser-compat-data.
- Derived by browser-compat-data mirroring from Firefox.
- No Safari support is recorded in browser-compat-data.
- No Safari on iOS support is recorded in browser-compat-data.
- Derived by browser-compat-data mirroring from Safari.
- No Samsung Internet support is recorded in browser-compat-data.
- Derived by browser-compat-data mirroring from Chrome Android.
- No WebView Android support is recorded in browser-compat-data.
- Derived by browser-compat-data mirroring from Chrome Android.
How to use it
Section titled “How to use it”Requesting a device must happen inside a user gesture, and filters narrows the picker to
devices matching a vendor ID. Once the user selects a device, open it before sending or
receiving reports:
async function connectHidDevice() { const [device] = await navigator.hid.requestDevice({ filters: [{ vendorId: 0x2341 }], }); await device.open(); return device;}How to detect it at runtime
Section titled “How to detect it at runtime”Check for navigator.hid before offering the feature, and give the reader a fallback path
when it is absent:
if ('hid' in navigator) { connectButton.hidden = false;} else { connectButton.hidden = true; fallbackNotice.textContent = 'This browser cannot access HID devices from the page.';}Practical checklist
Section titled “Practical checklist”- Requires a secure context — plain HTTP origins other than potentially trustworthy ones like
localhostcannot use it. requestDevice()needs transient user activation (a click or keypress handler); without it, the returned promise rejects with aSecurityErrorDOMException.requestDevice()resolves with an array (not a single device) of the HID interfaces exposed by the device the user picked — an empty array means the user closed the picker without choosing one.- Devices must be
open()ed before reports can be sent; callingsendReport()on a device that is not open rejects with anInvalidStateErrorDOMException. - Per MDN browser-compat-data, Chrome for Android and Android WebView do not implement the API, so
'hid' in navigatorisfalsethere and any HID-dependent flow needs the fallback path above.
Where to go next
Section titled “Where to go next”For the full reference (secure-context rules, connect/disconnect events, report handling), see WebHID API.
See also Web Serial API for the equivalent flow over a serial port.
← Back to the Compatibility explorer.