diff --git a/front_end/Cargo.toml b/front_end/Cargo.toml index 0166b84..a4094ca 100644 --- a/front_end/Cargo.toml +++ b/front_end/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" yew = "0.19" log = "0.4.6" wasm-logger = "0.2.0" -web-sys = { version = "0.3.56", features = ["Window", "Document", "Element", "Request", "RequestInit", "Headers", "RequestMode", "Response", "ReadableStream"] } +web-sys = { version = "0.3.56", features = ["Window", "Document", "Element", "Request", "RequestInit", "Headers", "RequestMode", "Response", "ReadableStream", "AddEventListenerOptions", "EventTarget"] } js-sys = "0.3.56" oorandom = "11.1.3" wasm-bindgen = { version = "0.2.79", features = ["serde-serialize"] } diff --git a/front_end/src/yew_components.rs b/front_end/src/yew_components.rs index 03f6b67..defc412 100644 --- a/front_end/src/yew_components.rs +++ b/front_end/src/yew_components.rs @@ -29,7 +29,7 @@ use std::rc::Rc; use js_sys::{Function, Promise}; use wasm_bindgen::JsCast; -use web_sys::{Document, Response}; +use web_sys::{AddEventListenerOptions, Document, Response}; use serde_json::Value as SerdeJSONValue; @@ -1238,12 +1238,17 @@ impl Component for Wrapper { let binded_func = outer_function.bind1(&outer_function, &resolve); window - .add_event_listener_with_callback("pagehide", &binded_func) + .add_event_listener_with_callback_and_add_event_listener_options( + "pagehide", + &binded_func, + AddEventListenerOptions::new().capture(true).once(true) + ) .expect("Should be able to set \"pagehide\" callback"); window - .add_event_listener_with_callback( + .add_event_listener_with_callback_and_add_event_listener_options( "beforeunload", &binded_func, + AddEventListenerOptions::new().capture(true).once(true) ) .expect("Should be able to set \"beforeunload\" callback"); });