WICG / webhid

Web API for accessing Human Interface Devices (HID)
Other
140 stars 35 forks source link

Exclude some devices from picker #92

Closed beaufortfrancois closed 2 years ago

beaufortfrancois commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Thanks for your support folks! I've started a spec PR at https://github.com/WICG/webhid/pull/93

nondebug commented 2 years ago

Closing since #93 was merged.