尝试通过 WebUSB10.14.1
在 Google Chrome 版本中读取 MacOS 上的 USB 条码扫描仪。71.0.3578.98
设备在 requestDevice 对话框中可见Usb211
并成功打开,我在这里使用的代码:
const VENDOR_ID = 0x8888
navigator.usb.requestDevice({ filters: [{ vendorId: VENDOR_ID }] })
.then(selectedDevice => {
device = selectedDevice;
return device.open();
})
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(device.configuration.interfaces[0].interfaceNumber)) # interfaceNumber is 0
.catch(error => { console.log(error); });
当我尝试claimInterface(0)
(这是对象中唯一可用的接口时,它会因错误(或DOMException )device
而失败- 由于最近的更改,这是预期的:https ://groups.google.com/a/chromium.org /forum/#!msg/blink-dev/LZXocaeCwDw/GLfAffGLAAAJAn attempt to claim a USB device interface has been blocked because it implements a protected interface class.
SecurityError
The requested interface implements a protected class.
有没有办法以某种方式“更深入地调试”,因为我看不到只使用可用接口的方法。
谢谢!