我似乎无法使用 webusb 声明隐藏接口(interface)。我正在尝试编写 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.
关于javascript - 使用 webusb 声明 HID 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45701516/