-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Labels
help wantedExtra attention is neededExtra attention is neededquestionFurther information is requestedFurther information is requested
Description
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?
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is neededquestionFurther information is requestedFurther information is requested