WebUSB getDevices空列表

时间:2017-01-26 15:24:09

标签: javascript google-chrome webusb

在Windows 10 PRO 1511版(OS Build 10586.753)上运行Chrome 56.0.2924.76(64位)。已经在chrome上启用了实验性网络平台功能,使用标志--disable-webusb-security和管理员运行它。我尝试使用getDevices在localhost(使用https)上获取USB设备列表,但我得到空列表,尽管chrome:// device-log向我显示了大量设备。可能是什么问题?

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

1 个答案:

答案 0 :(得分:7)

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

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

之后,您就可以致电getDevices()