Webusb: Access Denied trying to open printer on Windows

試著忘記壹切 提交于 2019-12-01 08:25:38

问题


I am trying to allow a POS web app to print directly to a StarMicronics (or any receipt printer, for that matter) using the Chrome webusb API.

I am using the example here almost exactly except I have modified the vendorId filter to the Vendor ID of StarMicronics. I have also tried it with a completely empty filter. It works great on the Mac computers I have tested it on, but the problem is on Windows.

When I click the print button, Chrome opens up the connection window, my device is listed and I can select it and click Connect. So navigator.usb.getDevices() is working great. When I refresh the window, after having connected the website to the device, Chrome finds the device again with no problem.

The problem comes when I try to do device.open(). I get this error in the console: DOMException: Access Denied. From this point, I can't do either device.selectConfiguration() or device.claimInterface() because I get the error that the device must first be opened, obviously.

I have enabled all the flags I know of in Chrome: #enable-experimental-web-platform-features #enable-webusb #new-usb-backend

But none of this has helped. I have also tried using other printers, such as an HP deskjet and a Dymo Label Writer all with the same resulting error message that access is denied.

Again, it is working fine on Macs.

Any help on this would be greatly appreciated.


回答1:


You get the "Access Denied" error on Windows because there is already a driver that has claimed the device. The Windows driver model requires that the "winusb.sys" driver be loaded for any device that will be accessed by a userspace application like Chrome.

See my answer to this earlier question about smartcard readers which encounter the same difficulty on Windows.



来源:https://stackoverflow.com/questions/47143148/webusb-access-denied-trying-to-open-printer-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!