-
Notifications
You must be signed in to change notification settings - Fork 133
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
Allow WebUSB to be used within a Web Worker #130
Conversation
This change adds a Web Workers subsection in the Integrations section of the spec. The subsection describes how the WebUSB interface is accessed from the context of a worker.
This change adds a base WindowOrWorkerUSB interface that contains all of the existing USB interfaces minus requestDevice. Two derived interfaces use WindowOrWorkerUSB. WindowUSB adds the requestDevice function, and it will only be used within the window context. WorkerUSB is the same as WindowOrWorkerUSB, and will only be used within a worker context.
This change adds an extended attribute to the requestDevice method of the USB interface to expose that function only in the Window context. Additionally, the Web Workers section adds the USB interface to the WorkerNavigator interface.
This change adds an extended attribute to the requestDevice method of the USB interface to expose that function only in the Window context. Additionally, the Web Workers section adds the USB interface to the WorkerNavigator interface.
… worker-integration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking the Permissions API as an example I think we can do without any additional text explaining the web worker integration but we should explicitly mark USB as exposed in Window and Worker and the partial Navigator as exposed only in Window.
index.bs
Outdated
allowed to request a device. | ||
|
||
<pre class="idl"> | ||
[Exposed=Worker, SecureContext] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per your blink-dev email you said you didn't want this to end up in service workers, but this does exactly that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I should do Exposed=(DedicatedWorker,SharedWorker)]
instead. I didn't realize that Service Workers also uses Abstract Worker as a base interface. Thanks for pointing that out.
This change exposes the USB interface only to Dedicated and Shared Workers. It also removes unnecessary explanations from the Web Worker section.
index.bs
Outdated
@@ -425,14 +426,15 @@ scheme, is encoded in the <code>URL</code> field. | |||
required sequence<USBDeviceFilter> filters; | |||
}; | |||
|
|||
[Exposed=(DedicatedWorker,SharedWorker,Window)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be SecureContext too.
This change adds the SecureContext attribute to the USB interface.
Thanks for the feedback @annevk. |
index.bs
Outdated
The web [[workers]] API provides a method for running scripts in the background | ||
independently of user interface scripts. | ||
|
||
<pre class="idl"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this below the partial interface Navigator
in the IDL section above. We don't need to separately introduce the concept of Web Workers here.
I don't think anything needs to change in the algorithms to support Web Workers but we should add a worker example to the spec. I don't think we have to do that in this patch. Wait until we've added a worker to an existing WebUSB app and have a sense of the best practices.
This change removes the Web Worker section that I added and moves the IDL for WorkerNavigator to the Device Enumeration section.
Sounds good Reilly, I'll do that when we're at the stage where we can add an example. |
This change to the spec will allow the WebUSB interface to be accessible within the context of a Web Worker.
I created an explainer document for this addition.
Additionally, this feature was mentioned before in issue WebUSB#73.
I checked if the change to the IDL in chromium compiled successfully in change 1014196.
Feedback on the change is welcome :)