WICG / webusb

Connecting hardware to the web.
https://wicg.github.io/webusb/
Other
1.32k stars 132 forks source link

How to get not paired devices list? #203

Closed qcscofield closed 3 years ago

qcscofield commented 3 years ago

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.

reillyeon commented 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.

demonguy commented 3 years ago

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

  1. never directly use paired devices. always pop up windows
  2. user will never get a chance to select unparied device is another paired device is also connected
reillyeon commented 3 years ago

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.