Closed qcscofield closed 3 years ago
This is intentionally impossible. getDevices()
only returns the devices the user has granted the site permission to access. requestDevice()
allows the site to ask for permission to access additional devices. If the site could get the list of devices that the user hasn't granted it permission to access then that would leak information to the site without the user's consent.
however, is it possible to add an interface to tell there is device not paired? we developed a tool, which for convenient, directly use paired device. However there is bug, if 2 device are connected, one device is paired and the other one is not, what we can do is
Unfortunately letting the site know that there are unpaired devices would still leak too much information without user consent. My recommendation is that the site can still automatically use the paired device but give the user the option to select a different device before taking any action the user might want to select a different device for. This is generally a good idea anyways, the site shouldn't make any irreversible actions without asking the user first.
The demo site https://sowbug.github.io/weblight is built this way. It will show the current status of any paired devices on load but also provides a button for the user to select a new device.
I used
let devices = await navigator.usb.getDevices();
to get already paired devices. But please tell me without using "requestDevice()" how to get not paired devices list.