Adding a event listener with
let closure: Closure<dyn Fn(JsValue)> = Closure::new(move |js: JsValue| {
let reason = js.as_string().expect("reason string");
// ...
});
web_extensions_sys::chrome
.runtime()
.on_installed()
.add_listener(closure.as_ref().unchecked_ref());
closure.forget();
but the event is never fired because the JS API runtime.onInstalled.addListener has to be called synchronously in the background script. And because WASM is asynchronously loaded, the execution of the web-extensions-sys wrapper is called too late
import init from './pkg/background.js';
// here we have to call runtime.onInstalled.addListener
init()
.then(() => {
// but it's called by the WASM module here
})
.catch(console.error)
There is a method that can init the module synchronously but the fetch is still asynchronous:
fetch("./pkg/background_bg.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => {
wasm.initSync(bytes);
})
.catch(console.error);
So does anybody have an idea how to solve this problem?
Adding a event listener with
but the event is never fired because the JS API
runtime.onInstalled.addListenerhas to be called synchronously in the background script. And because WASM is asynchronously loaded, the execution of theweb-extensions-syswrapper is called too lateThere is a method that can init the module synchronously but the
fetchis still asynchronous:So does anybody have an idea how to solve this problem?