10

After obtaining access to an attached device using navigator.usb.requestDevice I'm trying to open a connection with an attached device as follows:

device.open()
    .then(() => device.selectConfiguration(1))
    .then(() => device.claimInterface(1))

It seemingly successfully selects the configuration, however the claimInterface step will produce the following error:

DOMException: Unable to claim interface.

I'm running Chrome 55.0.2883.75 beta with the --disable-webusb-security flag as root (without those I didn't get any devices) on Ubuntu 16.10.

How can I get the connection up and running?

Edit:

It seems that the cdc_acm driver already claimed the interface since device I'm trying to attach is a serial device, unloading the driver will allow you to claim the device (however after this it complains about interface 1 not being available, as well as 0 or 2).

Joris Blaak
  • 398
  • 2
  • 10
  • 1
    Since this device has multiple interfaces we should make sure that you're claiming the right one. Please include the output of `lsusb -v` for your device which will list the full device descriptors. A USB CDC device will indeed be difficult to use with WebUSB because of the existing drivers that are loaded however forcing the driver to unload should release the interface. When you get an error like "Unable to claim interface" Chrome will provide possibly more detail about the error in chrome://device-log. – Reilly Grant May 05 '17 at 23:54

1 Answers1

2

Once the configuration is selected, you can find the right interface number in device.configuration.interfaces[0].interfaceNumber:

device.open()
    .then(() => device.selectConfiguration(1))
    .then(() => device.claimInterface(device.configuration.interfaces[0].interfaceNumber))
Supersharp
  • 29,002
  • 9
  • 92
  • 134
  • Thank you for answering. The number 0, 1 and 2 I found using the method you suggest here. But all of those will produce the same error. – Joris Blaak Dec 20 '16 at 12:44
  • @JorisBlaak What kind of device do you try to access? did you try with another device (usb key for example)? – Supersharp Dec 20 '16 at 12:50
  • A serial device, as mentioned in the _Edit_ it was already claimed by the driver – Joris Blaak Dec 20 '16 at 12:51
  • So now it works? If not, maybe you can try device.reset() to free the interface. – Supersharp Dec 20 '16 at 13:03
  • I didn't try that one! I've moved to an alternate implementation, but I would like to get the WebUSB version up and running. – Joris Blaak Dec 20 '16 at 13:04
  • 2
    @Supersharp This is what I get: "Failed to claim interface: Access denied (insufficient permissions)" Any suggestions? – jdrake Aug 04 '17 at 16:31