Contact emails
odej...@chromium.org, cho...@chromium.org, rei...@chromium.org
Explainer
https://github.com/odejesush/webusb-on-workers/blob/master/EXPLAINER.md
Spec
https://wicg.github.io/webusb/
In the Device Enumeration section, the USB interface is now exposed to Dedicated Workers, and WorkerNavigator has a usb attribute available in Dedicated Workers.
Summary
This change exposes all of the WebUSB API except navigator.usb.requestDevice() to Dedicated Workers. This method is not exposed because it requires a chooser prompt to be shown to the user. Exposing this API to workers enables I/O operations and data processing for a USB device to be moved off the main thread.
Link to "Intent to Implement" blink-dev discussion
https://groups.google.com/a/chromium.org/d/msg/blink-dev/MReOVYgRpKk/1jY8MiyACQAJ
Is this feature supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?
All except for Android WebView. WebUSB is not supported on Android WebView.
Demo link
Apologies in advance because this demo is internal only. The application has not been released yet.
I used performance.now() to time the file preview demo. There's a function called fileCapture() that performs the I/O to the camera and processes the data into a blob that is used to create an Image object. The function returns once all files are read. This is when the timer stops on the window context, while the worker context sends a "finished" message to the window, which stops the timer. In addition to this metric, I also recorded a profile of the file preview demo using DevTools to measure the total time that the main thread spent rendering a frame for each image drawn on the page. I measured the total time starting from when the last image finished rendering to when the current image finished rendering. In this time frame, I took the total time that the main thread spent rendering versus the total time spent idle. I performed the profile three times for each context, and I measured the times for three images in each profile. I used the averages from these to find the average percentage of time spent idle and rendering.
The measurements can be found in this document: https://docs.google.com/spreadsheets/d/1uDQqAoWZcoiKyhOhzV3z5EtH08gv8sDfnuGmjb7lMgY
Debuggability
The feature relies on the JavaScript debugging support provided by DevTools for Dedicated Workers.
Risks
Interoperability and Compatibility Risks
The interoperability and compatibility risks are the same as WebUSB however, if other browsers do implement WebUSB, then this specific feature should have low risk, since it would allow developers to move heavy data processing off of the main thread. Additionally, it is a small addition to an existing API.
Edge: No signals for the WebUSB API in general
Firefox: No signals for the WebUSB API in general
Safari: Not considering the WebUSB API in general
Web Developers: Positive, developers have specifically requested this feature:
Ergonomics
Allowing WebUSB to be used in a Dedicated Worker enables the I/O operations and data processing to be removed from the main thread. In the demo linked above, moving processing off the main thread reduces page jank while retrieving images stored on a DSLR camera.
Activation
This feature should be fairly simple for developers to use. The only requirement for the worker to use a USB device is that the page must already have requested access to the USB device by using navigator.usb.requestDevice in the window context first.
Is this feature fully tested by web platform tests?
The existing WebUSB web platform tests were modified to be multi-global tests. Therefore, the same tests are performed for Dedicated Workers. Since navigator.usb.requestDevice is not exposed to workers, it is not tested in the worker context. There is one test that is not yet implemented, and that is to check if a device that is opened in the worker is closed upon the termination of the worker. This test requires the MojoInterfaceInterceptor from a worker context to be sent to the window context to allow the window context to detect if the device was closed.
Entry on the feature dashboard
--
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/aeec0c99-cf73-47c5-bd6b-105c5f360d33%40chromium.org.
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/CAARdPYeNBPD2-Q0wWqze4ARuCgPq77mfWffv9cCwGwzwpEExYw%40mail.gmail.com.