{"record":{"id":"27c970b78ad175d0","repo":"gfx-rs/wgpu","slug":"failed-to-downcast-to-canvas-type","errorCode":null,"errorMessage":"Failed to downcast to canvas type","messagePattern":"Failed to downcast to canvas type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu-hal/src/gles/web.rs","lineNumber":159,"sourceCode":"        } else {\n            Vec::new()\n        }\n    }\n\n    unsafe fn create_surface(\n        &self,\n        _display_handle: raw_window_handle::RawDisplayHandle,\n        window_handle: raw_window_handle::RawWindowHandle,\n    ) -> Result<Surface, crate::InstanceError> {\n        let canvas: web_sys::HtmlCanvasElement = match window_handle {\n            raw_window_handle::RawWindowHandle::Web(handle) => web_sys::window()\n                .and_then(|win| win.document())\n                .expect(\"Cannot get document\")\n                .query_selector(&format!(\"canvas[data-raw-handle=\\\"{}\\\"]\", handle.id))\n                .expect(\"Cannot query for canvas\")\n                .expect(\"Canvas is not found\")\n                .dyn_into()\n                .expect(\"Failed to downcast to canvas type\"),\n            raw_window_handle::RawWindowHandle::WebCanvas(handle) => {\n                let value: &JsValue = unsafe { handle.obj.cast().as_ref() };\n                value.clone().unchecked_into()\n            }\n            raw_window_handle::RawWindowHandle::WebOffscreenCanvas(handle) => {\n                let value: &JsValue = unsafe { handle.obj.cast().as_ref() };\n                let canvas: web_sys::OffscreenCanvas = value.clone().unchecked_into();\n\n                return self.create_surface_from_offscreen_canvas(canvas);\n            }\n            _ => {\n                return Err(crate::InstanceError::new(format!(\n                    \"window handle {window_handle:?} is not a web handle\"\n                )))\n            }\n        };\n\n        self.create_surface_from_canvas(canvas)","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu-hal/src/gles/web.rs#L141-L177","documentation":"Panic in the GLES/web create_surface: dyn_into::<HtmlCanvasElement>() on the queried element failed — the node is not a canvas, so the downcast to the canvas type is impossible. The faulty input is the non-canvas DOM element.","triggerScenarios":"Thrown at wgpu-hal/src/gles/web.rs:159 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the queried selector matches a <canvas> element","Bind the raw handle to the correct canvas in the windowing layer"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}