slint-ui/slint · error
wasm-interpreter: Could not retrieve DOM document
Error message
wasm-interpreter: Could not retrieve DOM document
What it means
Error "wasm-interpreter: Could not retrieve DOM document" thrown in slint-ui/slint.
Source
Thrown at api/wasm-interpreter/src/lib.rs:351
);
#[wasm_bindgen(start)]
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.View on GitHub (pinned to 3fd8f2ec03)
Solutions
- Run the wasm module in a browser context where document exists.
- Provide a DOM shim only for testing, not production.
When it happens
Trigger: Thrown at api/wasm-interpreter/src/lib.rs:351 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/5976637a8c3c4bfe.
Report an issue: GitHub.