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 <[email protected]> wrote: > 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: > >> Contact [email protected], [email protected] >> Explainerwebhid/WEBHID_IN_EXTENSION_SERVICE_WORKERS_EXPLAINER.md at main >> <https://github.com/WICG/webhid/blob/main/WEBHID_IN_EXTENSION_SERVICE_WORKERS_EXPLAINER.md> >> SpecificationWebHID API <https://wicg.github.io/webhid/> >> SummaryAllows 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 componentBlink >> <https://bugs.chromium.org/p/chromium/issues/list?q=component:Blink>>HID >> MotivationAs Chrome Apps APIs will soon be deprecated >> <https://developer.chrome.com/docs/apps/migration/>, 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 >> <https://developer.chrome.com/docs/extensions/mv3/migrating_to_service_workers/>. >> As a result, it is required to support WebHID in Extension Service Workers. >> RisksInteroperability and CompatibilityGecko: No signal, we have asked >> for a position on WebHID in extensions (WebHID (Human Interface Device) >> API · Issue #459 · mozilla/standards-positions · GitHub >> <https://github.com/mozilla/standards-positions/issues/459#issuecomment-1162459878> >> ). >> 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 >> <https://docs.google.com/document/d/1s01BVkz-mb18p-gwXmzhM6DdioOh0JMzx_kCJzsLd7U/edit?usp=sharing>, >> internal-only) >> WebView application risksN/A. WebHID isn’t available on Android. >> DebuggabilityDevtools >> Is this feature fully tested by web-platform-tests >> <https://chromium.googlesource.com/chromium/src/+/main/docs/testing/web_platform_tests.md> >> ?No, testing for Extensions is covered by Chrome browser tests but the >> WebHID API in general is fully tested by web-platform-tests. >> Flag namechrome://flags/#enable-web-hid-on-extension-service-worker >> Requires code in //chrome?Yes >> Tracking bughttps://bugs.chromium.org/p/chromium/issues/detail?id=1303195 >> Launch bug >> >> https://launch.corp.google.com/launch/4200800 (sorry, Googlers only) >> >> Estimated milestones112 >> Link to entry on the Chrome Platform Status >> https://chromestatus.com/feature/6305751386554368 >> >> -- >> Tarek >> > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CADQ2FkQ7goV2rZ15v7GFcaFGYsdeDPBFDp%2BemKMPRgxG-dcp2w%40mail.gmail.com.
