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

Exclude some devices from picker #92

Closed
beaufortfrancois opened this issue Feb 17, 2022 · 4 comments
Closed

Exclude some devices from picker #92

beaufortfrancois opened this issue Feb 17, 2022 · 4 comments

Comments

@beaufortfrancois
Copy link
Contributor

beaufortfrancois commented Feb 17, 2022

Here's a feature request I received from developers:

Is there any consideration for supporting 'negative' filters in requestDevice?

Basically, providing a way to exclude known devices that are known to not work as expected.

Currently, developers let users pick a device, then check against a custom helper function (like deviceIsBlocklisted()) if device is known to be malfunctioning.

CURRENT

const [device] = await navigator.hid.requestDevice({
  filters: [{ usagePage: 0x0b }],
});

if (deviceIsBlocklisted(device.vendorId, device.productId)) {
  alert("Sorry! This device is not supported... even though you picked it ;(");
}

How about providing some new "excludes" HIDDeviceRequestOptions option to help developers with this use case?

PROPOSAL

// Prompt user to select a telephony device...
const [device] = await navigator.hid.requestDevice({
  filters: [{ usagePage: 0x0b }], 
  excludes: [{ vendorId: 0x1234, productId: 0x5678 }], // <-- NEW!
});

@nondebug @reillyeon

@reillyeon
Copy link
Contributor

That seems like a nice feature. It wasn't an issue for WebUSB but since you can filter HID devices by usage page and so would match a much broader range of devices the ability to then exclude some by another property seems useful.

@nondebug
Copy link
Collaborator

That seems very useful.

I'd also like to be able to filter on whether the device permission is already granted. That would allow apps to exclude already-granted device permissions so the user is only choosing between new devices. The inverse could also be useful: filtering to show only the already-granted device permissions. You won't grant any permissions with that filter but it's a cheap way to add a chooser to your app.

@beaufortfrancois
Copy link
Contributor Author

Thanks for your support folks!
I've started a spec PR at #93

@nondebug
Copy link
Collaborator

nondebug commented Apr 8, 2022

Closing since #93 was merged.

@nondebug nondebug closed this as completed Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants