-
Describe the BugWhen opening a window (e.g. a popup) with Steps to Reproducehave the following code: let foo: Window = window()
.unwrap()
.open_with_url_and_target_and_features(
"http://localhost:8080/",
"_blank",
"{popup:true}",
)
.unwrap()
.unwrap();
let closure: Closure<dyn Fn(BeforeUnloadEvent)> =
Closure::new(|event: BeforeUnloadEvent| {
event.prevent_default();
log::error!("closed?");
});
foo.set_onbeforeunload(Some(closure.as_ref().unchecked_ref()));
foo.add_event_listener_with_callback(
"beforeunload",
closure.as_ref().unchecked_ref(),
)
.unwrap();
closure.forget() neither the Expected Behaviorit should trigger Additional Contextin contrast the following simple javascript snippet works as intended for this let foo = window.open("https://localhost:8080/", "_blank", { popup: true });
foo.onbeforeunload = (event) => { event.preventDefault(); console.log("closed?") }; Am I doing anything wrong here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I'm unfortunately not particularly familiar with the APIs in use here, but if it works in JS then it should work in Wasm as well unless there is race condition. See Bugzilla, which I don't actually think applies here. Maybe try to more exactly replicate JS, e.g. use
According to the MDN documentation you can use |
Beta Was this translation helpful? Give feedback.
ok I found out what the issue is, one has to wait for the page to load before one can set the beforeunload event.
if i do it in javascript all at once (so not by hand like previously) it also does not work, what i have to do is to wait for the
load
event to finish: