使用 webusb 声明一个 HID 设备

Claiming an HID device using webusb

我似乎无法使用 webusb 声明隐藏接口。我正在尝试编写一个 yubikey OATH 包装器

navigator.usb.requestDevice({filters: filters}).then(...);

USBDevice {usbVersionMajor: 2, usbVersionMinor: 0, usbVersionSubminor: 0, deviceClass: 0, deviceSubclass: 0, …}configuration: USBConfiguration {configurationValue: 1, configurationName: null, interfaces: Array(2)}configurations: [USBConfiguration]deviceClass: 0deviceProtocol: 0deviceSubclass: 0deviceVersionMajor: 3deviceVersionMinor: 4deviceVersionSubminor: 9manufacturerName: "Yubico"opened: falseproductId: 273productName: "Yubikey NEO OTP+CCID"serialNumber: "0005610818"usbVersionMajor: 2usbVersionMinor: 0usbVersionSubminor: 0vendorId: 4176__proto__: USBDevice // ykey contains the device now USBDevice {usbVersionMajor: 2, usbVersionMinor: 0, usbVersionSubminor: 0, deviceClass: 0, deviceSubclass: 0, …}

ykey.open(...).then(...);
ykey.claimInterface(0)

Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined} Uncaught (in promise) DOMException: Unable to claim interface.

我怀疑这是一个与 chrome.usb api 类似的问题。我是否应该编写一个 udev 规则以不在该设备上使用 usbhid 驱动程序来使其工作?

来自 IRC 对话,Reilly 提到

The HID driver must not be loaded, so a udev rule is the way to go.

The restriction comes from the OS because when the HID driver is loaded that interface is "claimed" so Chrome can't claim it for itself.