Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

PSA: WebHID in Extension Service Workers

186 views
Skip to first unread message

Tarek ElBahnasawy

unread,
Feb 16, 2023, 5:29:14 PM2/16/23
to blink-dev, Matt Reynolds, Jack Hsieh

Contact emails

mattre...@chromium.org, chen...@chromium.org


Explainer

webhid/WEBHID_IN_EXTENSION_SERVICE_WORKERS_EXPLAINER.md at main


Specification

WebHID API


Summary

Allows web developers to use WebHID API when responding to extension events by exposing WebHID API to Service Workers registered by browser extensions. This API will not yet be exposed to Service Workers registered by sites but the implementation experience gained by supporting the API for extensions will be valuable for such a future project.


Blink component

Blink>HID


Motivation

As Chrome Apps APIs will soon be deprecated, developers are encouraged to migrate to web apps or Chrome Extensions. For the Chrome Extension case, Manifest V3 deprecates the background page and requires developers to migrate to service workers. As a result, it is required to support WebHID in Extension Service Workers.


Risks

Interoperability and Compatibility

Gecko: No signal, we have asked for a position on WebHID in extensions (WebHID (Human Interface Device) API · Issue #459 · mozilla/standards-positions · GitHub).


WebKit: No signal, opposed to the Web Serial API in general.


Web developers: Extension developers previously used WebHID and other device APIs from the background page and have requested that it continues to be available after migrating to Manifest V3.


Other signals: Extension team approves of exposing these APIs to extension service workers. (https://docs.google.com/document/d/1s01BVkz-mb18p-gwXmzhM6DdioOh0JMzx_kCJzsLd7U/edit, internal-only)


WebView application risks

N/A. WebHID isn’t available on Android.


Debuggability

Devtools


Is this feature fully tested by web-platform-tests?

No, testing for Extensions is covered by Chrome browser tests but the WebHID API in general is fully tested by web-platform-tests.


Flag name

chrome://flags/#enable-web-hid-on-extension-service-worker


Requires code in //chrome?

Yes


Tracking bug

https://bugs.chromium.org/p/chromium/issues/detail?id=1303195


Launch bug

https://launch.corp.google.com/launch/4200800 (sorry, Googlers only)


Estimated milestones

112


Link to entry on the Chrome Platform Status

https://chromestatus.com/feature/6305751386554368


--
Tarek

Jack Hsieh

unread,
Sep 17, 2023, 1:33:09 PM9/17/23
to Ali Zarei, blink-dev, Tarek ElBahnasawy, Matt Reynolds
Hi Ali,

`navigator.hid.requestDevice` would need to be called inside a chrome extension page for granting the device to the extension. Please refer to https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/functional-samples/sample.co2meter for an example.

Best Regards
Jack


On Sun, Sep 17, 2023 at 6:57 AM Ali Zarei <zarei...@gmail.com> wrote:
Hi there,
Calling navigator.hid.requestDevice in service worker is not possible, so what is correct way of requesting a device?

Rick Byers

unread,
Sep 17, 2023, 4:48:08 PM9/17/23
to Tarek ElBahnasawy, blink-dev, Matt Reynolds, Jack Hsieh
Makes sense to me, thanks for the heads up!

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAKfE4fJQqcigBxG_3qNzWjBdUSwU5kQ7zg-L-Wf0AVxCx_Emzg%40mail.gmail.com.

Ali Zarei

unread,
Sep 18, 2023, 8:50:26 AM9/18/23
to blink-dev, Tarek ElBahnasawy, Matt Reynolds, Jack Hsieh
Hi there,
Calling navigator.hid.requestDevice in service worker is not possible, so what is correct way of requesting a device?

On Friday, February 17, 2023 at 1:59:14 AM UTC+3:30 Tarek ElBahnasawy wrote:
Reply all
Reply to author
Forward
0 new messages