WICG / webhid

Web API for accessing Human Interface Devices (HID)
Other
142 stars 35 forks source link

open() returns "NotAllowedError" #87

Closed jonathan-longe closed 2 years ago

jonathan-longe commented 2 years ago

Thanks for creating this great API! I'm trying to connect a mag stripe scanner and I'm getting a "NotAllowedError" when calling open() using Chrome (Version 97.0) from Pop!_OS 20.04 LTS.

Here's the steps I'm following from the Chrome console:

let device = await navigator.hid.requestDevice({filters:[{ vendorId: 0x0801, productId: 0x0002}]}); console.log(device[0])

HIDDevice {oninputreport: null, opened: false, vendorId: 2049, productId: 2, productName: 'Mag-Tek USB Swipe Reader', …}

device[0].open()

[[PromiseResult]]: DOMException: Failed to open the device. code: 0 message: "Failed to open the device." name: "NotAllowedError"

I tried creating a udev rule for the scanner by creating a file with the following line: KERNEL=="hiddev*", ATTRS{idVendor}=="0801", ATTRS{idProduct}=="0002", MODE="0666"

Then running: $ sudo udevadm control --reload-rules but that didn't seem to make a difference.

I know the hardware works because the same set of commands from Windows using Edge Version 97.0 can successfully read a bar code.

Apologies, I'm a newbie at WebHID.

jonathan-longe commented 2 years ago

Found the issue. Posting the resolution in case this helps someone else.

Replaced the following udev rule: KERNEL=="hiddev*", ATTRS{idVendor}=="0801", ATTRS{idProduct}=="0002", MODE="0666"

With: KERNEL=="hidraw*" ATTRS{idVendor}=="0801", ATTRS{idProduct}=="0002", MODE="0444"

beaufortfrancois commented 2 years ago

FYI I'm updating web.dev/hid/ with your findings. Thank you @jonathan-longe! See https://github.com/GoogleChrome/web.dev/pull/7141