API should be exposed to ServiceWorker
Would be nice to have and I can't think of any reason not to expose WebGPU to a service worker considering Webgl is accessible.
It's only exposed to the Window and DedicatedWorkers at the moment. Reference: https://gpuweb.github.io/gpuweb/#navigator-gpu [Exposed=(Window, DedicatedWorker), SecureContext]
Similar issue regarding exposing webGPU to a dedicated worker:
Thanks for filing this, I didn't realize we didn't have an issue for this :)
I think we should do it. It seems WebGL just uses Worker. I don't know how to find an official listing of the Worker types but Chromium documents it as DedicatedWorker, SharedWorker, and ServiceWorker:
https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/bindings/IDLExtendedAttributes.md#exposed
So along with this, likely we should expose it in SharedWorker too.
No Problem, thanks for the prompt response!
Let me know if there is anything I can do to help get this to the finish line
@MiguelsPizza Is there no way to use webgpu in webview in android?
hi there, as far as I know, Tensorflow.js recomend using AI models in background.js (using service worker) for chrome-extension . So, I am really looking forward to this new feature
Also love to see WebGPU being exposed to service worker. This would open up quite a bit opportunities building AI extensions with WebGPU
This seems appropriate.
The only reason not to spec this would be if, somehow, all browsers never planned to actually get around to implementing it - but that's not the case. Once Firefox has its resource consumption controls firmed up, this makes sense for us to implement.
FYI I've started https://github.com/gpuweb/gpuweb/pull/4464 that adds ServiceWorker support to the WebGPU spec.
I don't know how to find an official listing of the
Workertypes but Chromium documents it asDedicatedWorker,SharedWorker, andServiceWorker:
MDN also documents it as those 3. https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope
Thank you @beaufortfrancois @kainino0x, would be great to know how we are doing in terms of support status, love to followup and try out as soon as it lands
We'll let you know when it's available behind a flag in Chrome so that you can play around.
@tqchen @MiguelsPizza You can now play with WebGPU in a service worker in Chrome Canary 123.0.6271.0 by enabling the "Experimental Web Platform features" flag at chrome://flags/#enable-experimental-web-platform-features.
Here's an extension sample I've created to demonstrate its usage: https://gist.github.com/beaufortfrancois/4795c20bc4d147e0400303d0b8ec02d6
Let me know how it goes ;)
@tqchen @MiguelsPizza Did you have a chance to experiment with Service Worker support in Chrome? Did you find some limitations or bugs we should be aware of?
https://github.com/mlc-ai/web-llm/pull/296 @rickzx should be able to comment more :) really excited about what it can enable
@beaufortfrancois @tqchen Thanks a lot for putting the effort to support WebGPU in service worker. I was able to put up a sample Chrome extension running LLM in the service worker in the background, and a popup window as a chat assistant. It's much simpler and more elegant to implement this now with the service worker support. Haven't encountered any bugs so far.
@tqchen @MiguelsPizza @rickzx I'm happy to report that Chrome nows supports WebGPU in service worker by default as of Chrome 124.0.6359.0 (Canary at this moment) 🎉
And to close the loop, here's the official announcement: https://developer.chrome.com/blog/new-in-webgpu-124?hl=en#service_workers_and_shared_workers_support