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

Add exclusionFilters to USBDeviceRequestOptions #233

Merged
merged 2 commits into from
Jun 20, 2023

Conversation

beaufortfrancois
Copy link
Contributor

@beaufortfrancois beaufortfrancois commented Jun 16, 2023

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: #232


Preview | Diff

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 16, 2023
This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some known devices that are known to
not work as expected.

Intent to Ship: TODO
Spec: WICG/webusb#233
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
@yume-chan
Copy link

yume-chan commented Jun 16, 2023

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.

Copy link
Collaborator

@reillyeon reillyeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

index.bs Outdated
filter</a> in <code>|options|.{{USBPermissionDescriptor/filters}}</code>.
6. Display a prompt to the user requesting they select a device from
7. Remove devices from |enumerationResult| if they do <a>match a device filter</a>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
7. Remove devices from |enumerationResult| if they do <a>match a device filter</a>
7. Remove devices from |enumerationResult| if they <a>match a device filter</a>

index.bs Outdated
@@ -2370,10 +2389,14 @@ defined as follows:
and |device| does not <a>match a device filter</a> in
<code>|desc|.{{USBPermissionDescriptor/filters}}</code>, continue
to the next |device|.
2. Get the {{USBDevice}} representing |device| and add it to
2. If <code>|desc|.{{USBPermissionDescriptor/exclusionFilters}}</code>
is set and |device| does <a>match a device filter</a> in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
is set and |device| does <a>match a device filter</a> in
is set and |device| <a>matches a device filter</a> in

You might need to add an attribute to the definition of "match a device filter" for it to understand this version is the same definition. I forget how smart it is about this.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 19, 2023
This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some devices that are known to not work
as expected.

Intent to Ship: TODO
Spec: WICG/webusb#233
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 19, 2023
This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some devices that are known to not work
as expected.

Intent to Ship: TODO
Spec: WICG/webusb#233
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
@beaufortfrancois
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Collaborator

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
Copy link
Contributor Author

@reillyeon Can you merge?

@reillyeon reillyeon merged commit 1ebe98c into WICG:main Jun 20, 2023
github-actions bot added a commit that referenced this pull request Jun 20, 2023
SHA: 1ebe98c
Reason: push, by reillyeon

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Jun 20, 2023
SHA: 1ebe98c
Reason: push, by reillyeon

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 21, 2023
This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some devices that are known to not work
as expected.

Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
Spec: WICG/webusb#233
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 22, 2023
This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some devices that are known to not work
as expected.

Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
Spec:
- WICG/webusb#233
- WICG/webusb#235
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 23, 2023
This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some devices that are known to not work
as expected.

Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
Spec:
- WICG/webusb#233
- WICG/webusb#235
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
aarongable pushed a commit to chromium/chromium that referenced this pull request Jun 23, 2023
This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some devices that are known to not work
as expected.

Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
Spec:
- WICG/webusb#233
- WICG/webusb#235
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4614682
Reviewed-by: Arthur Sonzogni <[email protected]>
Reviewed-by: Reilly Grant <[email protected]>
Commit-Queue: Fr <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1161953}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 23, 2023
This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some devices that are known to not work
as expected.

Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
Spec:
- WICG/webusb#233
- WICG/webusb#235
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4614682
Reviewed-by: Arthur Sonzogni <[email protected]>
Reviewed-by: Reilly Grant <[email protected]>
Commit-Queue: Fr <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1161953}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 23, 2023
This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some devices that are known to not work
as expected.

Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
Spec:
- WICG/webusb#233
- WICG/webusb#235
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4614682
Reviewed-by: Arthur Sonzogni <[email protected]>
Reviewed-by: Reilly Grant <[email protected]>
Commit-Queue: Fr <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1161953}
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Jul 5, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Jul 6, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jul 6, 2023
…stDeviceOptions, a=testonly

Automatic update from web-platform-tests
WebUSB: Add exclusionFilters to USBRequestDeviceOptions

This CL adds a new "exclusionFilters" option in
navigator.usb.requestDevice() options so that web developers can
exclude from the browser picker some devices that are known to not work
as expected.

Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
Spec:
- WICG/webusb#233
- WICG/webusb#235
Demo: https://usb-exclusion-filters.glitch.me/

Bug: 1455392
Change-Id: I1b61d9daae3e14accedb24e493ae656316427893
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4614682
Reviewed-by: Arthur Sonzogni <[email protected]>
Reviewed-by: Reilly Grant <[email protected]>
Commit-Queue: Fr <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1161953}

--

wpt-commits: b7727490c96a87eb3f40fe43f266ad05368ab2b0
wpt-pr: 40582
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Jul 7, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Aug 9, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Aug 14, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Aug 15, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Aug 17, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Aug 21, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Aug 22, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Sep 5, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
cdesouza-chromium added a commit to brave/brave-core that referenced this pull request Sep 6, 2023
Upstream has done changes to the constructor of `UsbChooserController`.
We happen to depend on this class for one of our tests, as way to insert
a fake.

This change makes the necessary adjustments to reflect the upstream
change.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/19b0f58776f13112c4490e912ff0850b52720a36

commit 19b0f58776f13112c4490e912ff0850b52720a36
Author: François Beaufort <[email protected]>
Date:   Fri Jun 23 21:18:39 2023 +0000

    WebUSB: Add exclusionFilters to USBRequestDeviceOptions

    This CL adds a new "exclusionFilters" option in
    navigator.usb.requestDevice() options so that web developers can
    exclude from the browser picker some devices that are known to not work
    as expected.

    Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/e1mgO-m8zvQ
    Spec:
    - WICG/webusb#233
    - WICG/webusb#235
    Demo: https://usb-exclusion-filters.glitch.me/

    Bug: 1455392
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

Successfully merging this pull request may close these issues.

Exclusive filter in requestDevice
3 participants