admin管理员组文章数量:1433509
I am trying to access my USB device through web pages (over HTTPS). My USB device is up and running and has also enabled Experimental Web Platform features chrome://flags/#enable-experimental-web-platform-features. Even though I have provided the correct vendorId and productId in the code, chrome shows the message "No patible devices found". Where am I going wrong? Below is my code
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<button id="request-device">Request Device</button>
<script>
document.getElementById("request-device").addEventListener("click", ()=>{
navigator.usb.requestDevice({filters: [{vendorId: 0x03F0}, {productId: 0x5A07}]})
.then((usbDevice)=>{
console.log("product name: "+usbDevice.productName);
})
.catch((e)=>{
console.log("There is no devie...."+e);
});
});
</script>
</body>
</html>
I am trying to access my USB device through web pages (over HTTPS). My USB device is up and running and has also enabled Experimental Web Platform features chrome://flags/#enable-experimental-web-platform-features. Even though I have provided the correct vendorId and productId in the code, chrome shows the message "No patible devices found". Where am I going wrong? Below is my code
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<button id="request-device">Request Device</button>
<script>
document.getElementById("request-device").addEventListener("click", ()=>{
navigator.usb.requestDevice({filters: [{vendorId: 0x03F0}, {productId: 0x5A07}]})
.then((usbDevice)=>{
console.log("product name: "+usbDevice.productName);
})
.catch((e)=>{
console.log("There is no devie...."+e);
});
});
</script>
</body>
</html>
Share
Improve this question
edited May 24, 2023 at 12:49
djvg
14.5k7 gold badges84 silver badges116 bronze badges
asked Apr 25, 2021 at 13:01
Rishi AnandRishi Anand
511 silver badge2 bronze badges
1 Answer
Reset to default 4There are a few reasons why the device may not appear:
The first is that Chrome is not detecting that the device has been connected. Chrome logs each USB device it discovers in chrome://device-log. Check there that your device has been detected. It will also provide detailed device information in the "Devices" tab of chrome://usb-internals.
The other reason is that Chrome may be hiding the device because it does not implement any interfaces which a website is allowed to claim using the WebUSB API. For example, if the device is a USB mass storage device that interface is not claimable and if there are no other interfaces the device will be hidden. Due to a bug in Chrome 90, if the device has no interfaces it will not appear either. This will be fixed in Chrome 91 and you can verify that fix in the latest beta-channel update.
本文标签: javascriptWebUSB API not able to find compatible deviceStack Overflow
版权声明:本文标题:javascript - WebUSB API not able to find compatible device - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745579523a2664537.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论