thegecko/webusb

requestDevice returnes empty

Closed this issue · 10 comments

I can get a device with node-usb but webusb throws an error no devices found

with webusb:

var usb = require("usb").usb;
usb.requestDevice({filters: [{vendorId: 0x0fcf}]}).then(console.log).catch(console.log)

gives:

Error: requestDevice error: no devices found
    at adapter_1.adapter.listUSBDevices.then.devices (...../webusb/lib/usb.js:159:35)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)
> 

with node-usb:

var usb = require("usb");
usb.getDeviceList().filter(d => {return d.deviceDescriptor.idVendor == 0x0fcf})

output:

[ Device {
    busNumber: 1,
    deviceAddress: 7,
    deviceDescriptor: 
     { bLength: 18,
       bDescriptorType: 1,
       bcdUSB: 512,
       bDeviceClass: 0,
       bDeviceSubClass: 0,
       bDeviceProtocol: 0,
       bMaxPacketSize0: 32,
       idVendor: 4047,
       idProduct: 4105,
       bcdDevice: 256,
       iManufacturer: 1,
       iProduct: 2,
       iSerialNumber: 3,
       bNumConfigurations: 1 },
    portNumbers: [ 1 ] } ]

in chrome WebUSB works

usb.requestDevice({filters: [{vendorId: 0x0fcf}]}).then(console.log).catch(console.log)
> Promise {<pending>}
> USBDevice {usbVersionMajor: 2, usbVersionMinor: 0, usbVersionSubminor: 0, deviceClass: 0, deviceSubclass: 0, …}

I guess it's being dropped by the filters somehow, but I am struggling to work out where switching between the different adapters js/ts and the promise api's. Can you point us into the right direction?

seems to be the code which checks for capabilities and web capabilities on addapter.loadDevices. not sure what that is doing, is it an API requirement?

Hi @Richard-Mathie The WebUSB specification highlights that WebUSB enabled devices need to have a WebUSB capability descriptor. Therefore this library will only return devices which satisfy that constraint.

The part of the specification outlining this can be seen here:
https://wicg.github.io/webusb/#webusb-platform-capability-descriptor

And this is where I filter based on that capability:
https://github.com/thegecko/webusb/blob/master/src/adapter.ts#L259

It's also possible it doesn't return WebUSB devices without URLs (I haven't had a chance to test that) so if that's your case, please let me know.

Yeah I had a look through, and it might have been the URL filter, its a bit hard to trace for me.

You could try disabling each of the filters/checks in turn in the code I point to above and recompiling to see progress?

I've had a chance to test this now and there were errors when a WebUSB device didn't have a URL. Now fixed in #11 and I'll make a release...

@Richard-Mathie Did this fix your issue?

Closing due to inactivity

@Richard-Mathie It seems Chrome allows the user to filter against all devices (not just those with the WebUSB characteristic). Therefore I've removed this restriction in PR #13 (and released in 1.0.4) which may have been the cause of your issue.

Ah nice, Yeah thats right Chrome pops up a dropdown list of devices to approve. I guess i should check if FF, IE or edge behave differently.

Sorry I haven't had much time to look at this lately. I might check it out this evening.