Registering onInstalled handler from WASM

38 views
Skip to first unread message

Liam Bowen

unread,
Sep 28, 2022, 9:58:10 AM9/28/22
to Chromium Extensions
I'm building an extension whose service worker is written in WASM with Rust. It has been a good experience so far. There are only a few lines of JS in the worker, and those lines just load the WASM asynchronously. It could be loaded semi-synchronously, by which I mean that the loading could be synchronous except that the WASM file has to be retrieved via fetch(), which would make it miss the first iteration of the event loop, and therefore wouldn't be really synchronous.

I've read this in this group in other posts, which seems to be accurate based on my tests: "The `addListener` must be called synchronously in the first iteration of the event loop."

Is there any way that I can use WASM to handle the onInstalled event?

Thanks in advance!

Jackie Han

unread,
Sep 28, 2022, 10:43:33 AM9/28/22
to Liam Bowen, Chromium Extensions
// in service worker
var promise = WebAssembly.instantiateStreaming(......);
async function onInstall() {
  let obj = await promise;
  // use obj 
}
chrome.runtime.onInstalled.addListener(onInstall);



--
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 on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/4738c29a-93bd-4cbe-8211-e7a5c6a59729n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages