What is the best practice of storing large optional assets?

198 views
Skip to first unread message

xmcp

unread,
Jun 17, 2025, 1:52:55 AM6/17/25
to Chromium Extensions
Hi devs,

I would like to introduce an optional AI feature in my extension that would require ~75MB assets (onnx model + the wasm of onnxruntime-web). The assets will be used by a web worker created by a content script. I'm considering how can the extension store that data.

The straightforward way is to package the assets into the crx. In this way, the web worker can reference the assets through chrome-extension:// URLs if I add them into web_accessible_resources in manifest.json. But this will affect the installation time of my extension, and also waste 75MB disk space for everyone not using this feature, which I would like to avoid.

To exclude the assets from crx and download them on demand, we have the unlimitedStorage permission and chrome.storage.local API. However, chrome.storage.local can only store strings and it's also unavailable in web workers. It will be very inefficient to load the assets in the content script, decode the string back to blob, and then pass it to the web worker.

An alternative approach is to download the assets in web worker and store it into indexedDB or cacheStorage. However, these Web APIs are bound to the injected domain, so it cannot be shared across multiple injected domains and chrome-extension:// pages. It also lacks the guarantee of data persistence.

Has anyone encountered similar use cases? Any help is appreciated.

Jackie Han

unread,
Jun 18, 2025, 4:08:00 AM6/18/25
to xmcp, Chromium Extensions
This article compares Cache API, the Origin Private File System API, and IndexedDB for saving LLM.
But your case is used in content script, In this case, the assets are not shared. Can you load LLM in your extension(e.g. offscreen document), then send message to it from the content script?

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/53394a53-add3-4894-af98-774c1a582b7dn%40chromium.org.

xmcp

unread,
Jun 18, 2025, 5:40:41 AM6/18/25
to Chromium Extensions, Jackie Han, Chromium Extensions, xmcp
Thanks for the suggestion.

There will be messaging overhead since I am doing embedding with the model. Currently chrome.tabs.sendMessage can only send JSON, so the embedding result (a Float32Array) must be serialized. Ironically window.postMessage can transfer typed arrays without copying but chrome extensions cannot.

Maybe I will investigate if the overhead is acceptable and possibly move some code into the offscreen document to avoid serializing the embedding.

Jackie Han

unread,
Jun 18, 2025, 12:26:36 PM6/18/25
to xmcp, Chromium Extensions
Currently chrome.tabs.sendMessage can only send JSON, so the embedding result (a Float32Array) must be serialized. Ironically window.postMessage can transfer typed arrays without copying but chrome extensions cannot.

It is possible to transfer data between content script and extension using Web postMessage() .
1. In the content script, create an iframe(your extension page) and inject into the page.
2. In the iframe, run your AI model.
3. pass data between content script and iframe via postMessage.

woxxom wrote a sample code here https://stackoverflow.com/a/68689866/1330598 (see the "Web messaging (two-way MessagePort)" section).
Reply all
Reply to author
Forward
0 new messages