Alex Filatov
Alex Filatov

Reputation: 111

Cannot claim the only interface I can see through device.configuration.interfaces

Trying to read USB Barcode Scanner on MacOS 10.14.1 in Google Chrome Version 71.0.3578.98 via WebUSB.

Using a barcode scanner: https://www.ebay.co.uk/itm/Barcode-Scanner-USB-Handheld-Wired-Portable-Laser-Scan-Bar-Code-Reader-Scan-POS/282865082953

Device is visible in the requestDevice dialog as Usb211 and opens successfully, code I used for this here:

const VENDOR_ID = 0x8888

navigator.usb.requestDevice({ filters: [{ vendorId: VENDOR_ID }] })
.then(selectedDevice => {
  device = selectedDevice;
  return device.open();
})
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(device.configuration.interfaces[0].interfaceNumber)) # interfaceNumber is 0 
.catch(error => { console.log(error); });

When I tried to claimInterface(0) (which is the only interface available in the device object, it fails with the error An attempt to claim a USB device interface has been blocked because it implements a protected interface class. (or SecurityError DOMException The requested interface implements a protected class.) - this one is expected because of the recent changes: https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/LZXocaeCwDw/GLfAffGLAAAJ

Is there any way to "debug deeper" somehow because I cannot see a way to use only available interface.

Thank you!

Upvotes: 2

Views: 1341

Answers (2)

Alex Filatov
Alex Filatov

Reputation: 111

Solved this by switching scanner into different interface - there are 4 interface modes and one of them ("USB VCOM") allows to have 2 interfaces available, so claimInterface(1) was successful.

Upvotes: 0

Reilly Grant
Reilly Grant

Reputation: 6083

If the only available interface is blocked then there is no way to use it through the WebUSB API. There is a separate API in the works, WebHID, that is designed to satisfy the particular requirements when granting access to devices that provide an HID interface.

Upvotes: 1

Related Questions