Home > Back-end >  Understanding the WebUSB connection workflow
Understanding the WebUSB connection workflow

Time:03-02

I am working on an Chrome webapp that uses WebUSB running on an Android device, and am trying to understand how the connection management works.

If I am reading the spec right, if you don't already have permission to interact with the USB device, you call requestDevice to get permission from the user to trigger the initial connection workflow. You can also call getDevices() first to see if permission has already been granted, and if so can proceed from there without going through the initial connection workflow.

Assuming that's an accurate summary (please correct me if not!), then how does that connection information get stored and managed? If I go to chrome://usb-devices, I don't see the devices if they are not currently plugged in. If I go to Local Storage, I din't see anything that looks like a list of devices. Where does the permission-has-already-been-granted information live? Is it possible to forget connection information, manually or programmatically?

Thanks in advance!

CodePudding user response:

A call to navigator.usb.requestDevice() will prompt user to pick a USB device in a browser picker. When chosen, the browser will remember internally which devices user have granted access to. From there, when plugged in, those devices will be accessible without user prompting from a call to navigator.usb.getDevices().

It is possible in Chrome 101 for a website to revoke access to a device by calling the forget() method on a USB device object. See enter image description here

CodePudding user response:

Permissions are stored in Chrome's user preferences file which, if you're curious, you can view the raw data at chrome://prefs-internals and search for "usb_chooser_data".

To see and edit USB permissions you can either open the page info dialog as suggested by the other answer or visit chrome://settings/content/usbDevices. This will show permissions for devices that are not currently connected.

  • Related