Skip to content

Commit 50ac31f

Browse files
committed
webhid: avoid unecessary device selection prompt if device already connected
1 parent 49e5ab8 commit 50ac31f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

webhid.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ class MessageQueue {
3636
export async function getWebHIDDevice(vendorId, productId, onCloseCb) {
3737
let device;
3838
try {
39-
const devices = await navigator.hid.requestDevice({filters: [{vendorId, productId}]});
39+
// Try to get directly the device. This will work without prompting user
40+
// permission if it has already been validated before on the current website.
41+
let devices = await navigator.hid.getDevices({filters: [{vendorId, productId}]});
42+
if (devices.length == 0){
43+
// If direct access failed, which happen for new websites, ask user
44+
// confirmation.
45+
devices = await navigator.hid.requestDevice({filters: [{vendorId, productId}]});
46+
}
4047
const d = devices[0];
4148
// Filter out other products that might be in the list presented by the Browser.
4249
if (d.productName.includes('BitBox02')) {

0 commit comments

Comments
 (0)