英文:
Can webusb automatically connect without user-gesture, when device has no serial number?
问题
我正在编写一个 Web 应用程序,我的用户使用 DS2490 ibutton 读卡器、Zebra 扫描仪、Zebra 打印机和 Loadstar di1000 Loadcell。我在运行此 Web 应用程序的设备上使用 Chrome OS Flex,并通过 Google 管理控制台进行管理。我正在使用以下策略:WebUsbAllowDevicesForUrls、UsbDetachableAllowlist,以授予 Web 应用程序对 USB 设备的访问权限。
所有设备,在加载页面时都会自动连接,除了 ibutton 读卡器。
我找到了这篇帖子,提问者遇到了与我类似的问题。看起来问题是因为他的自定义 USB 设备没有序列号,他通过提供一个解决了这个问题。当我查看 ibutton 读卡器的 USB 数据时,它显示序列号字符串为空。缺少序列号是否可能与设备不自动连接有关?
连接函数:
async connect(e) {
try {
this.device = await navigator.usb.requestDevice(this.requestParams);
}
catch (e) {
console.log(e);
let devices = await navigator.usb.getDevices();
devices.forEach((element) => {
if (element.vendorId == this.deviceFilter.vendorId && element.productId == this.deviceFilter.productId) {
this.device = element
}
});
}
if (this.device) {
this.eventTarget.dispatchEvent(new Event('connect'));
await this.device.open();
await this.device.selectConfiguration(1);
await this.device.claimInterface(0);
this.connected = true
this.eventTarget.dispatchEvent(new Event('open'));
this.search = true
this.searchLoop()
} else {
}
}
希望这些信息对你有所帮助。如果有任何其他问题,请随时提出。
英文:
I am writing a web-app, where my users use, a DS2490 ibutton reader, zebra scanner, zebra printer and Loadstar di1000 Loadcell. I run chrome os flex on the devices, that run this webapp, and i manage them via the google admin console. I am using the following policies: WebUsbAllowDevicesForUrls, UsbDetachableAllowlist, to give the web-app access to the usb devices
All devices, but the ibutton reader connect automatically, when the page is loaded.
I found this post, where the asker had kind of the same problem as me. It looks like the problem was that his custom usb device didn't have a serial number, and he solved it by giving it a one. When i look at the usb data of the ibutton reader, it shows that the serial number string is empty. Can the lack of a serial number have anything to do with the device not automatically connecting?
Connect function:
async connect(e) {
try {
this.device = await navigator.usb.requestDevice(this.requestParams);
}
catch (e) {
console.log(e);
let devices = await navigator.usb.getDevices();
devices.forEach((element) => {
if (element.vendorId == this.deviceFilter.vendorId && element.productId == this.deviceFilter.productId) {
this.device = element
}
});
}
if (this.device) {
this.eventTarget.dispatchEvent(new Event('connect'));
await this.device.open();
await this.device.selectConfiguration(1);
await this.device.claimInterface(0);
this.connected = true
this.eventTarget.dispatchEvent(new Event('open'));
this.search = true
this.searchLoop()
} else {
}
}
答案1
得分: 0
这似乎是一个错误或用户错误。请确保对于所有您想要根据策略获取权限的设备,您已正确设置了供应商和产品ID。基于策略的权限逻辑不要求设备具有序列号。
如果您正在使用Web串行或WebHID用于其中一些设备,请注意它们使用不同的策略,即“SerialAllowUsbDevicesForUrls”和“WebHidAllowDevicesForUrls”。如果您在管理控制台中找不到这些策略,请联系您的企业支持代表。
注意:除非其中某个设备具有在连接设备时自动附加的驱动程序,否则您可能不需要设置“UsbDetachableAllowlist”策略。
英文:
That seems like a bug or user error. Make sure you have the vendor and product IDs set correctly for all the devices you want to get permission for by policy. The policy-based permission logic does not require the device to have a serial number.
If you are using Web Serial or WebHID for some of these devices note that they use different policies, SerialAllowUsbDevicesForUrls
and WebHidAllowDevicesForUrls
. Please reach out to your Enterprise support representative if you can't find these policies in the Admin Console.
Note: You probably don't need to set the UsbDetachableAllowlist
policy unless one of those devices have a driver that automatically attaches when the device is connected.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论