Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webhid: avoid unecessary device selection prompt if device already connected #100

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion webhid.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ class MessageQueue {
export async function getWebHIDDevice(vendorId, productId, onCloseCb) {
let device;
try {
const devices = await navigator.hid.requestDevice({filters: [{vendorId, productId}]});
// Try to get directly the device. This will work without prompting user
// permission if it has already been validated before on the current website.
let devices = await navigator.hid.getDevices({filters: [{vendorId, productId}]});
if (devices.length == 0){
// If direct access failed, which happen for new websites, ask user
// confirmation.
devices = await navigator.hid.requestDevice({filters: [{vendorId, productId}]});
}
const d = devices[0];
// Filter out other products that might be in the list presented by the Browser.
if (d.productName.includes('BitBox02')) {
Expand Down