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

Device chooser for WebUSB #14545

Open
gniezen opened this issue Sep 11, 2018 · 15 comments
Open

Device chooser for WebUSB #14545

gniezen opened this issue Sep 11, 2018 · 15 comments

Comments

@gniezen
Copy link
Contributor

@gniezen gniezen commented Sep 11, 2018

Is your feature request related to a problem? Please describe.
Electron has a chooser for Web Bluetooth (#5565), but no chooser for WebUSB. Even if there is only one device, WebUSB still requires the chooser to be used, currently resulting in a DOMException: No device selected when calling navigator.usb.requestDevice().

WebUSB has been available (without an experimental flag) since Chromium 61.

Describe the solution you'd like
Implement a chooser window like the one in Chromium (see https://cs.chromium.org/chromium/src/chrome/browser/usb/web_usb_chooser.h) to request permission from a user to access a USB device.

Describe alternatives you've considered
node-usb is an alternative that can be used, but it is barely maintained. WebUSB is well supported by the Chrome team and seems to be the way forward.

Additional context

@welcome
Copy link

@welcome welcome bot commented Sep 11, 2018

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

@MarshallOfSound
Copy link
Member

@MarshallOfSound MarshallOfSound commented Sep 11, 2018

Implement a chooser window like the one in Chromium (see

Just commenting here that we won't implement any UI for this, if someone gets to implementing this it would follow the same pattern as the bluetooth API which emits an event with the possible bluetooth devices and leaves the UI up to individual apps.

@reillyeon
Copy link

@reillyeon reillyeon commented Sep 12, 2018

Let me know if you have any questions about enabling this. Right now WebUSB isn't hooked up in the easiest way for content embedders but we are refactoring it right now so it should get better.

@MarshallOfSound
Copy link
Member

@MarshallOfSound MarshallOfSound commented Sep 12, 2018

@reillyeon Yeah I took a look at this and it's not hooked up to webcontents observer like blueooth is. Might just wait for a refactor 😄

@Venryx
Copy link

@Venryx Venryx commented Dec 8, 2018

Any update on this? Would be helpful for the Electron app of a website I'm building which needs to get the output from a TRNG (true/hardware random-number-generator) usb device.

Like mentioned above, there are some NodeJS alternatives, but it would be nice to use the web standard if possible since it means the USB-access code can be shared between the Electron app and the web-only version.

@reillyeon
Copy link

@reillyeon reillyeon commented Dec 10, 2018

While you are waiting for this you can use webusb which is a polyfill of WebUSB on top of the Node-specific usb package.

@dilushan
Copy link

@dilushan dilushan commented Jun 1, 2019

Any update on this issue? Seems NW.js fixed this over a year ago
nwjs/nw.js#6500

@rampageservices
Copy link

@rampageservices rampageservices commented Aug 21, 2019

Hi @MarshallOfSound @reillyeon Would you kindly take a look at this and let us know if the refactor has taken place at this point to enable this to go ahead? I checked the USB code in the chromium browser folder and I did not see a WebContentsObserver. Also, I did not see a ticket open to implement this on bugs.chromium.org. I'd like to open a ticket but I do not have your expertise on this matter. Your guidance would be appreciate so that we can get this working in electron.

@reillyeon
Copy link

@reillyeon reillyeon commented Aug 21, 2019

The refactoring in Chromium is tracked by issue 991759. This unblocks a whole bunch of things that will help embedders like Electron as well as Headless Chrome and Android WebView.

@gniezen
Copy link
Contributor Author

@gniezen gniezen commented Nov 14, 2019

@reillyeon Looking at the issue you linked to, am I understanding correctly that Web Serial and WebHID are hooked up to WebContentsObserver?

@nondebug
Copy link

@nondebug nondebug commented Nov 14, 2019

I don't believe that either API registers as a WebContentsObserver. They do both access WebContents, but only to update whether or not there are open connections to Serial or HID devices.

@reillyeon
Copy link

@reillyeon reillyeon commented Nov 22, 2019

As a subclass of content::FrameServiceBase the content::HidService class implementing the browser-process side of the WebHID API is a content::WebContentsObserver. For the WebUSB API, instances of WebUsbServiceImpl are owned by a UsbTabHelper which is a content::WebContentsObserver.

@robertguyser
Copy link

@robertguyser robertguyser commented Dec 31, 2019

Sorry to bring back this dead issue, but there is no other real discussion of it anywhere on the internet. I am attempting to use the webusb polyfill method, and when I try to call requestDevice(), it disconnects the debugger and I do not get a chooser. I have manually specified a device, but when it attempts the requestDevice, it crashes.

With the polyfill is there a way to over-ride and select the device manually or was the suggestion above of using a polyfill library misguided? Thank you in advance for any advice.
This is the script to easily recreate the issue:
https://github.com/thegecko/webusb/blob/master/examples/selector.js

@reillyeon
Copy link

@reillyeon reillyeon commented Jan 2, 2020

@robertguyser this issue is not dead but your question is off-topic. For issues with thegecko/webusb please use that repository's issue tracker.

@NessDan
Copy link

@NessDan NessDan commented Aug 7, 2020

Any update on this? Looking to use Electron to talk to a piece of hardware I'm making, would love to use navigator.usb as described here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants
You can’t perform that action at this time.