【问题标题】:WebUSB getDevices empty listWebUSB getDevices 空列表
【发布时间】:2017-01-26 15:24:08
【问题描述】:

在 Windows 10 PRO 版本 1511(操作系统内部版本 10586.753)上运行 Chrome 56.0.2924.76(64 位)。已在 chrome 上启用了 Experimental-web-platform-features,使用标志 --disable-webusb-security 并以管理员身份运行它。我尝试使用 getDevices 在 localhost(使用 https)上获取 USB 设备列表,但我得到空列表,尽管 chrome://device-log 向我显示了很多设备。可能是什么问题?

navigator.usb.getDevices().then(function(devices){
    console.log(devices);
});
// console outputs []

【问题讨论】:

    标签: javascript google-chrome webusb


    【解决方案1】:

    您应该在之前使用requestDevice() 以获得所选设备的访问权限。

    navigator.usb.requestDevice({filters:[]}).then(function(device){
       console.log(device);
    });
    

    之后您就可以拨打getDevices()

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    相关资源
    最近更新 更多