WebUSB getDevices empty list
Asked Answered
C

1

10

Running Chrome 56.0.2924.76 (64-bit) on Windows 10 PRO Version 1511 (OS Build 10586.753). Have enabled experimental-web-platform-features on chrome, running it with flag --disable-webusb-security and as administrator. I try to get USB device list on localhost (using https) with getDevices but I get empty list, although chrome://device-log is showing me plenty of devices. What could be the issue?

navigator.usb.getDevices().then(function(devices){
    console.log(devices);
});
// console outputs []
Cupronickel answered 26/1, 2017 at 15:24 Comment(0)
S
31

You should use requestDevice() before in order to get access permissions on selected devices.

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

After that you'll be able to call getDevices().

Shrievalty answered 3/2, 2017 at 1:4 Comment(2)
From the Google documentation : developers.google.com/web/updates/2016/03/…Shrievalty
Looks like I did not read it carefully enough because I was following the same article. Thanks.Cupronickel

© 2022 - 2024 — McMap. All rights reserved.