WICG / webusb

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

Add exclusionFilters to USBDeviceRequestOptions #233

Closed beaufortfrancois closed 1 year ago

beaufortfrancois commented 1 year ago

The new "exclusionFilters" option in navigator.usb.requestDevice() allows web developers to exclude some devices from the browser picker. It can be used to exclude devices that match a broader filter but are unsupported, or are already connected for instance.

// Request access to a device from vendor ID 0xABCD. 
// The device with product ID 0x1234 has been reported as unsupported.
const device = await navigator.usb.requestDevice({
  filters: [{ vendorId: 0xABCD }],
  exclusionFilters: [{ vendorId: 0xABCD, productId: 0x1234 }],
});

Please have a look @reillyeon

FIX: https://github.com/WICG/webusb/issues/232


Preview | Diff

yume-chan commented 1 year ago

Why do requestDevice and Peromission API treat the excludionFilters options differently? requestDevice doesn't allow it to be an empty array, and didn't check whether it was set in step 7. I think an empty array should behavior the same as not set.

beaufortfrancois commented 1 year ago

LGTM with nits. I agree that we probably should unify the behavior between requestDevice() and the Permissions API integration. Of course the latter is a bit aspirational since it isn't implemented in any browser engine.

Thank you! I've addressed your nits.

Would it be okay to land this as is and file a spec issue to unify the behaviour between requestDevice() and the Permissions API?

beaufortfrancois commented 1 year ago

FYI I've started implementing this change in Chromium at https://chromium-review.googlesource.com/c/chromium/src/+/4614682.

Once the spec is updated, I'll start an intent to ship if that looks good to you @reillyeon

reillyeon commented 1 year ago

Would it be okay to land this as is and file a spec issue to unify the behaviour between requestDevice() and the Permissions API?

Yes.

beaufortfrancois commented 1 year ago

@reillyeon Can you merge?