Web/API/USB/requestDevice

From Get docs
< Web/API‎ | USB

This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.


Secure contextThis feature is available only in secure contexts (HTTPS), in some or all supporting browsers.


The requestDevice() method of the USB interface returns a Promise that resolves with an instance of USBDevice if the specified device is found. Calling this function triggers the user agent's pairing flow.

Syntax

USB.requestDevice([filters])

Parameters

filters
An array of filter objects for possible devices you would like to pair. Each filter object can have the following properties:
  • vendorId
  • productId
  • classCode
  • subclassCode
  • protocolCode
  • serialNumber

Return value

A Promise that resolves with an instance of USBDevice.

Example

The following example looks for one of two USB devices. Notice that two product IDs are specified. Both are passed to requestDevice(). This triggers a user-agent flow that prompts the user to select a device for pairing. Only the selected device is passed to then().

The number of filters does not specifiy the number of devices shown by the user agent. For example, if only a USB device with product ID 0xa800 is found, then only one device will be listed by the user agent. On the other hand if the user agent finds two of the first listed device and one of the second, then all three devices will be listed.

const filters = [
        {vendorId: 0x1209, productId: 0xa800},
        {vendorId: 0x1209, productId: 0xa850}
      ];
navigator.usb.requestDevice({filters: filters})
.then(usbDevice => {
  console.log("Product name: " + usbDevice.productName);
})
.catch(e => {
  console.log("There is no device. " + e);
});

Specifications

Specification Status Comment
WebUSBThe definition of 'requestDevice' in that specification. Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet

requestDevice

Experimental'

Chrome

Full support 61

Edge

Full support 79

Firefox

No support No

IE

No support No

Opera

Full support 48

Safari

No support No

WebView Android

No support No

Chrome Android

Full support 61

Firefox Android

No support No

Opera Android

Full support 45

Safari iOS

No support No

Samsung Internet Android

Full support 8.0

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.'
Experimental. Expect behavior to change in the future.