{"record":{"id":"7baa8951d1a761d2","repo":"slint-ui/slint","slug":"winit-backend-specified-dom-element-is-not-a","errorCode":null,"errorMessage":"winit backend: Specified DOM element '{}' is not a HTML Canvas","messagePattern":"winit backend: Specified DOM element '(.+?)' is not a HTML Canvas","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"api/wasm-interpreter/src/lib.rs","lineNumber":399,"sourceCode":"                if let Some(canvas_id) = next_id.borrow_mut().take() {\n                    use i_slint_backend_winit::winit::platform::web::WindowAttributesExtWebSys;\n\n                    use wasm_bindgen::JsCast;\n\n                    let html_canvas = web_sys::window()\n                        .expect(\"wasm-interpreter: Could not retrieve DOM window\")\n                        .document()\n                        .expect(\"wasm-interpreter: Could not retrieve DOM document\")\n                        .get_element_by_id(&canvas_id)\n                        .unwrap_or_else(|| {\n                            panic!(\n                                \"wasm-interpreter: Could not retrieve existing HTML Canvas element '{}'\",\n                                canvas_id\n                            )\n                        })\n                        .dyn_into::<web_sys::HtmlCanvasElement>()\n                        .unwrap_or_else(|_| {\n                            panic!(\n                                \"winit backend: Specified DOM element '{}' is not a HTML Canvas\",\n                                canvas_id\n                            )\n                        });\n                    attrs = attrs\n                        .with_canvas(Some(html_canvas))\n                        // Don't activate the window by default, as that will cause the page to scroll,\n                        // ignoring any existing anchors.\n                        .with_active(false);\n                    attrs\n                } else {\n                    attrs\n                }\n            })\n        })\n        .build()\n        .unwrap();\n    i_slint_core::platform::set_platform(Box::new(backend))","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/api/wasm-interpreter/src/lib.rs#L381-L417","documentation":"The wasm-interpreter found a DOM element with the requested id, but `dyn_into::<HtmlCanvasElement>()` failed, meaning the element exists yet is not a `<canvas>` (e.g. a `<div>`). The message text says 'winit backend' for historical reasons but is raised by the wasm-interpreter canvas lookup. Rendering requires an actual HTMLCanvasElement to pass to the winit WebSys backend.","triggerScenarios":"Calling init with a canvas id that resolves to a non-canvas DOM element (div, span, iframe) so the dyn_into cast fails.","commonSituations":"Index.html updated so the element became a div or the id was reused on another element; copy-pasted boilerplate keeping the wrong tag; mistakenly passing a container element id instead of the canvas id.","solutions":["Change the element with that id to a `<canvas>` element in the HTML","Pass the id of the actual `<canvas>` element to init instead of a container div","Ensure ids are unique so getElementById resolves the canvas, not another element","Use `<canvas id=\"canvas\">` boilerplate matching the default expected id"],"exampleFix":"// before\n<div id=\"canvas\"></div>\n// after\n<canvas id=\"canvas\"></canvas>","handlingStrategy":"type-guard","validationCode":"const el = document.getElementById(canvasId);\nif (!(el instanceof HTMLCanvasElement)) throw new Error(`#${canvasId} is not a <canvas>`);","typeGuard":"const isCanvas = (el: Element | null): el is HTMLCanvasElement => el instanceof HTMLCanvasElement;","tryCatchPattern":"try { await init(canvasId); } catch (e) { if (String(e).includes('not a HTML Canvas')) console.error(`#${canvasId} must be <canvas>`); else throw e; }","preventionTips":["Use <canvas> tags in boilerplate HTML","Keep element ids unique across the document","Pass the canvas element's id, not a container div's"],"tags":["wasm","dom","canvas","type-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}