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
API should be exposed to ServiceWorker #4197
Comments
Thanks for filing this, I didn't realize we didn't have an issue for this :) So along with this, likely we should expose it in |
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? |
This PR updates the Chrome extension to run in two modes: - Using the `ChatRestModule`, which uses a local/hosted server to run the model. - This requires the user to launch the server before using the Chrome extension, which interacts with the server using the REST API. - The `ChatRestModule` will be created in the background service worker, so it should persist between interactions. - Using the `ChatModule`, which runs the model using WebGPU. - This does not require any additional user actions before using the extension. - The `ChatModule` cannot be created in the background service worker, so it needs to be loaded from cache every time the user interacts with the extension. This takes several seconds. Some additional observations / limitations: - As far as I can tell, Chrome extensions can only [support](https://developer.chrome.com/docs/extensions/mv3/service_workers/) background service workers, which don't currently have support for WebGPU yet, as mentioned in gpuweb/gpuweb#4197. This means that the WebGPU mode will only work from the main script and not the background worker. - This approach does not work with Manifest v3 because of the following error: ``` Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'". ``` I suspect it is because we are evaluating some third party code which is not in the extension. There seems to be a dependency on 'unsafe-eval' in the Content Security Policy, but according to the Chrome extension [documentation](https://developer.chrome.com/docs/extensions/mv3/manifest/content_security_policy/), this is not allowed starting v3. I managed to get it to work in Manifest v2, but Manifest v2 will be getting deprecated this year.
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 #4464 that adds ServiceWorker support to the WebGPU spec. |
MDN also documents it as those 3. |
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 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? |
mlc-ai/web-llm#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) 🎉 |
This PR updates Chrome Extension using WebGPU Service Worker README.md following gpuweb/gpuweb#4197 (comment)
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 |
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:
The text was updated successfully, but these errors were encountered: