WebUSB API - connect & disconnect USB HW callbacks

673 views
Skip to first unread message

Sambor Czarski

unread,
Jun 22, 2017, 5:08:28 PM6/22/17
to blink-dev
Hello,


I am working on a project in a team that uses the WebUSB API and I have some questions I was hoping you can answer.

We have have successfully communicated with our USB device and it is returning the devices Landing Page URL, and now I am trying to detect when the device connects and disconnects from the USB port, I have tried to followed the instructions on https://wicg.github.io/webusb/#enumeration in Example 1.

Initially when the device is first plugged in, and the page is loaded I call navigator.usb.getDevices() and loop threw the devices when I get the results from that method, but the devices list is empty until I request and open the device (and close), than I can reload the page and I find 1 device in the list (which is now correct), so in the results from getDevices I loop threw the devices list and on each device I navigator.usb.addEventListener for connect and disconnect, but when I unplug and plug in the device no callbacks are triggered.

I am really unsure what I am doing wrong, may you point me in the right direction pleas? Any help would be appreciated.


Thank you,
Sambor Czarski

Stefan Zager

unread,
Jun 23, 2017, 12:37:57 PM6/23/17
to Sambor Czarski, web...@chromium.org, blink-dev
Forwarding to the webusb mailing list.

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/c1ef53b4-83ec-4004-97ab-2d1c50834bd6%40chromium.org.

Reilly Grant

unread,
Jun 23, 2017, 12:45:18 PM6/23/17
to Stefan Zager, Sambor Czarski, web...@chromium.org
[blink-dev to BCC]

It is better to ask such questions on StackOverflow because it offers search tools to help find previously answered questions.

From your description the getDevices() and requestDevice() methods are working as expected. When removing the device after the site has been granted permission to access it do you get a 'disconnect' event? After disconnecting the device, if you click on the lock icon in the address bar do you still see the device permission listed? If not the reason is that the device does not have a serial number and so the permission granted by the user cannot be persisted. You should always get a 'disconnect' event after the user removes a device they have granted the site permission to access it but you will not get a 'connect' event because the permission is automatically revoked on disconnect. If the device has a serial number then the permission will not be revoked.

If this is not the behavior you observe please file a bug on crbug.com with details about the platform and device and the contents of chrome://device-log (uncheck all the category boxes except for "USB"). 

You received this message because you are subscribed to the Google Groups "WebUSB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webusb+un...@chromium.org.
To post to this group, send email to web...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/webusb/CAHOQ7J9os3VFu8NrgEzc95HZqqjOH54ZgUfFPb_Df6rXZGjb9Q%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages