1

For starters I used navigator.hid.requestDevice without any filters. So I can see which devices are available before adding a custom filter, but my device doesn't show up in the HID browser device picker.

enter image description here

However, in the chrome device log chrome://device-log/ I can see connection/disconnection events for the device with both HID and USB labels:

enter image description here

I don't think this device is on the block list, so I'm not really sure why it's not showing up as an option when requesting HID devices. It shows up in Windows in the Device Manager under HID category as well.

If I use navigator.usb then the device does show up when requested, but when opened the device gets a Security Error, which possibly means it needs WinUSB driver. It's a HID USB device and works with libs outside of WebHID and WebUSB.

Any reasons it's not showing up?

Edit 1:

My device showed up in chrome://usb-internals/ where I see that it says HID is blocked by WebUSB. Not sure how to solve this yet.

enter image description here

Edit 2:

Using Chrome Canary and the devtools console provided a debug message when using the HID Device picker: Chooser dialog is not displaying a device blocked by the HID blocklist: vendorId=7992, productId=258, name='TEST', serial=''

Looking at the HID blocklist https://github.com/WICG/webhid/blob/main/blocklist.txt I still don't see an issue with the vendor id or product id. The usage page and usage don't match either, but the debug message doesn't mention those, so it's hard to say the exact reason.

Edit 3:

With chrome canary 103.0.5034.0 the new output gives this reason this device is blocked:

Chooser dialog is not displaying a device blocked by the HID blocklist: vendorId=7992, productId=258, name='TEST', serial='', numberOfCollections=1, numberOfProtectedInputReports=0, numberOfProtectedOutputReports=0, numberOfProtectedFeatureReports=0
karamazovbros
  • 950
  • 1
  • 11
  • 40

2 Answers2

3

If you're seeing it in the browser picker when you don't define any filters, it means this device is not blocklisted indeed.

I'd recommend you grab information such as vendorId and productId from https://nondebug.github.io/webhid-explorer/ for instance. After you connect your device, check out vendorId and productId info and use them as filters:

const filters = [{ vendorId: 0x1234, productId: 0x5678 }];

const [device] = await navigator.hid.requestDevice({ filters });

More generally, https://web.dev/hid/ is a great resource to get started with WebHID.

Edit 1

If you're not seeing your device in the browser picker when you don't have any filters but see "HID device added" in about:device-log, it means the browser picker is hiding it (either because it has a top-level collection with a FIDO usage or is blocklisted (https://github.com/WICG/webhid/blob/main/blocklist.txt). See Chromium source code at chrome/browser/ui/hid/hid_chooser_controller.cc:


bool HidChooserController::DisplayDevice(
    const device::mojom::HidDeviceInfo& device) const {
  // Check if `device` has a top-level collection with a FIDO usage. FIDO
  // devices may be displayed if the origin is privileged or the blocklist is
  // disabled.
  const bool has_fido_collection =
      base::Contains(device.collections, device::mojom::kPageFido,
                     [](const auto& c) { return c->usage->usage_page; });
  if (has_fido_collection) {
    if (base::CommandLine::ForCurrentProcess()->HasSwitch(
            switches::kDisableHidBlocklist) ||
        (chooser_context_ &&
         chooser_context_->IsFidoAllowedForOrigin(origin_))) {
      return FilterMatchesAny(device) && !IsExcluded(device);
    }
    VLOG(1) << "Not displaying a FIDO HID device.";
    return false;
  }

  if (!device::HidBlocklist::IsDeviceExcluded(device))
    return FilterMatchesAny(device) && !IsExcluded(device);

  VLOG(1) << "Not displaying a device blocked by the HID blocklist.";
  return false;
}

Edit 2

Note that it is possible your device is blocklisted if it doesn't have any collection. See HidBlocklist::IsDeviceExcluded() source code. Is that the case?

By the way, it is possible to disable the HID blocklist by running Chrome with a special flag:

$ chrome --disable-hid-blocklist

See Run Chromium with flags page.

François Beaufort
  • 4,843
  • 3
  • 29
  • 38
  • It never shows up in the browser picker. Even without filters. I was looking at the block list, but my device doesn't match any of the components so idk why it doesn't show up in the HID browser picker. It shows up in the USB browser picker, but then there's a Security Error when opened. – karamazovbros Apr 19 '22 at 17:26
  • I've edited my answer to explain why device may not show up in browser picker – François Beaufort Apr 20 '22 at 06:49
  • For info, I'm working on adding logs to `about:device-log` to help with this. See https://chromium-review.googlesource.com/c/chromium/src/+/3595839/ – François Beaufort Apr 20 '22 at 07:38
  • Is there any easy way to determine the exact block list issue? I've reviewed the list and my HID device doesn't seem to share any of those attributes. – karamazovbros Apr 26 '22 at 03:21
  • Also be sure to take a look at my latest edit. – karamazovbros Apr 26 '22 at 03:43
  • My changes have landed in chrome canary 103.0.5023.0. Give it a try and let me know which error message you see in devtools console. – François Beaufort Apr 26 '22 at 05:43
  • Your latest edit means your device is a hid device, and that's why it's blocked by web USB. – François Beaufort Apr 26 '22 at 05:43
  • Added another edit. The HID device picker does say it's on the blocklist. What needs to be modified in the firmware to fix this? I can't tell why it's being blocked. usage? usage page? – karamazovbros Apr 26 '22 at 17:51
  • See my last edit: does your device have collections? try disabling the blocklist. – François Beaufort Apr 27 '22 at 07:06
  • Which version of chrome? I'm not seeing that disable-hid-blocklist option available. Also for clarity I'm using Windows. – karamazovbros Apr 28 '22 at 00:45
  • Any version of Chrome should work for disabling the hid blocklist. See https://www.chromium.org/developers/how-tos/run-chromium-with-flags/#windows to run chrome with a switch. Do you know by any chance if your device has HID collections? – François Beaufort Apr 28 '22 at 05:44
  • Oh, then that's interesting. I ran the special flag on Chrome/Chromium/Canary, but I still wasn't seeing the device. The device HID descriptor has a collection (0xA1, 0x01). Is there a web tool that can specify the exact the reason the HID device is blocked? – karamazovbros May 01 '22 at 03:18
  • In chrome canary 103.0.5034.0, I've added more logs. Can you share the new message you see in chrome dev tools console? See https://chromiumdash.appspot.com/commit/36caf29521bb00e120e15fb4b61a5ea65c4b5d28 – François Beaufort May 01 '22 at 05:40
  • Thanks. Added a new edit with the output. – karamazovbros May 01 '22 at 06:09
  • Could it be that despite having a collection, your device doesn't have any input reports, output reports, feature reports defined? – François Beaufort May 01 '22 at 06:25
  • It does have input and output reports though. I works flawlessly sending and receiving data using a native Windows HID lib. The HID descriptor also specifies the output and input report specifics, so maybe the descriptor is off somehow? It doesn't have feature reports though just input and output reports. – karamazovbros May 01 '22 at 06:31
  • According to https://source.chromium.org/chromium/chromium/src/+/main:services/device/public/cpp/hid/hid_blocklist.cc;l=214;drc=6fa3b54df432518a2966cfab92bed34ba95c6363, it seems like your device does not have any reports as it does not return `false`. On the other hand, https://source.chromium.org/chromium/chromium/src/+/main:content/browser/hid/hid_service.cc;l=64;drc=6fa3b54df432518a2966cfab92bed34ba95c6363 suggests a collection always include at least one report. Could you share a clean and entire log of about:device-log to make sure your device is not removed/updated somehow? – François Beaufort May 01 '22 at 06:50
  • Quick question: Can I order this device by any chance to debug myself? – François Beaufort May 01 '22 at 07:04
  • So that gave me a hint to look at the output/input part of the descriptor. I modified it slightly and now I can view the device with the HID device picker. I still need to run more tests to make sure the descriptor is still good though communication appears to be working in my test software still. So even if this current version of the descriptor still needs work it's good to know it's fixable in the firmware for Web HID. Thank you so much for the help. The debug statements were very helpful. – karamazovbros May 01 '22 at 07:09
  • Glad you made it work! Can you share the hardware diff change you made to help similar developers? Any chance I can try this device by the Way? – François Beaufort May 01 '22 at 11:50
  • No, sorry, this device isn't available. Added an answer. Feel free to edit if you see something that can be improved in the explanation. – karamazovbros May 05 '22 at 19:53
2

I want to give an extra thanks to François Beaufort for pointing me in the right direction and adding debug logs to Chrome Canary specifically for WebHID testing.

The issue was that WebHID saw the number of input and output reports both as 0 and blocked the device from appearing in the HID device picker. Again, the device I was using works natively on Windows, so this issue was hidden until working with WebHID.

The exact issue was in the HID descriptor of the device firmware in the input & output sections of the HID descriptor. While I can't share the whole descriptor the input and output sections look as follows for the fix:

0x81, 0x00, // INPUT (Data, Var, Abs)
...
...
...
0x91, 0x01, // OUTPUT (Data, Var, Abs)

The first values 0x81 and 0x91 were correct, but the 2nd values needed to be changed to the above values to work. Once the firmware was modified the device immediately displayed using the WebHID device picker. Communication is working fine with WebHID now and the device still works natively on Windows as well.

karamazovbros
  • 950
  • 1
  • 11
  • 40
  • Hey! I ended up updating Chrome so that the HID blocklist does not exclude HID devices with no collections so that web developers can see them in the browser picker. It is available in Chrome 104.0.5097.0. See https://chromiumdash.appspot.com/commit/99718a7489d6877de67500d119e52d35ad4dad9b Please let me know if that works for you without your recent firmware changes. – François Beaufort Jun 02 '22 at 08:06