slint-ui/slint · error

wasm-interpreter: Could not retrieve existing HTML Canvas el

Error message

wasm-interpreter: Could not retrieve existing HTML Canvas element '{}'

What it means

Error "wasm-interpreter: Could not retrieve existing HTML Canvas element '{}'" thrown in slint-ui/slint.

Source

Thrown at api/wasm-interpreter/src/lib.rs:354

pub fn init() -> Result<(), JsValue> {
    #[cfg(feature = "console_error_panic_hook")]
    console_error_panic_hook::set_once();
    let backend = i_slint_backend_winit::Backend::builder()
        .with_spawn_event_loop(true)
        .with_window_attributes_hook(|mut attrs| {
            NEXT_CANVAS_ID.with(|next_id| {
                if let Some(canvas_id) = next_id.borrow_mut().take() {
                    use i_slint_backend_winit::winit::platform::web::WindowAttributesExtWebSys;

                    use wasm_bindgen::JsCast;

                    let html_canvas = web_sys::window()
                        .expect("wasm-interpreter: Could not retrieve DOM window")
                        .document()
                        .expect("wasm-interpreter: Could not retrieve DOM document")
                        .get_element_by_id(&canvas_id)
                        .unwrap_or_else(|| {
                            panic!(
                                "wasm-interpreter: Could not retrieve existing HTML Canvas element '{}'",
                                canvas_id
                            )
                        })
                        .dyn_into::<web_sys::HtmlCanvasElement>()
                        .unwrap_or_else(|_| {
                            panic!(
                                "winit backend: Specified DOM element '{}' is not a HTML Canvas",
                                canvas_id
                            )
                        });
                    attrs = attrs
                        .with_canvas(Some(html_canvas))
                        // Don't activate the window by default, as that will cause the page to scroll,
                        // ignoring any existing anchors.
                        .with_active(false);
                    attrs
                } else {

View on GitHub (pinned to 3fd8f2ec03)

Solutions

  1. Create a <canvas> element in the HTML page and pass its id to the Slint wasm initialization.
  2. Check the canvas id for typos.

When it happens

Trigger: Thrown at api/wasm-interpreter/src/lib.rs:354 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of slint-ui/slint@3fd8f2ec03 (2026-08-19). Data as JSON: /api/errors/2c9b4898bcdfc346. Report an issue: GitHub.