From f31a23bedf487f370ce57e521e47b0b4f1bf91a7 Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Sun, 29 Sep 2024 20:27:12 +0200 Subject: [PATCH] Fix wasm build --- crates/egui_router/src/history/mod.rs | 1 + fancy-example/src/main.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/egui_router/src/history/mod.rs b/crates/egui_router/src/history/mod.rs index 2af8719..5c595aa 100644 --- a/crates/egui_router/src/history/mod.rs +++ b/crates/egui_router/src/history/mod.rs @@ -45,6 +45,7 @@ type HistoryResult = Result; /// History error #[derive(Debug, thiserror::Error)] pub enum HistoryError { + /// Updating the browser history failed #[cfg(target_arch = "wasm32")] #[error("History error: {0:?}")] JsError(wasm_bindgen::JsValue), diff --git a/fancy-example/src/main.rs b/fancy-example/src/main.rs index a4dab7d..70cf83d 100644 --- a/fancy-example/src/main.rs +++ b/fancy-example/src/main.rs @@ -165,11 +165,20 @@ fn main() -> eframe::Result<()> { // when compiling to web using trunk. #[cfg(target_arch = "wasm32")] fn main() { + use wasm_bindgen::JsCast; let web_options = eframe::WebOptions::default(); + let element = eframe::web_sys::window() + .expect("failed to get window") + .document() + .expect("failed to get document") + .get_element_by_id("canvas") + .expect("failed to get canvas element") + .dyn_into::() + .unwrap(); wasm_bindgen_futures::spawn_local(async { eframe::WebRunner::new() .start( - "canvas", + element, web_options, Box::new(|a| { egui_extras::install_image_loaders(&a.egui_ctx);