{"record":{"id":"110f6360edcb3569","repo":"gfx-rs/wgpu","slug":"cannot-query-for-canvas","errorCode":null,"errorMessage":"Cannot query for canvas","messagePattern":"Cannot query for canvas","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu-hal/src/gles/web.rs","lineNumber":156,"sourceCode":"            }\n            .into_iter()\n            .collect()\n        } 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            }","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu-hal/src/gles/web.rs#L138-L174","documentation":"Panic in the GLES/web create_surface: query_selector for the canvas matching the raw handle's data-raw-handle attribute returned None, so the canvas element tied to the window handle could not be located. The faulty input is the canvas id/handle association.","triggerScenarios":"Thrown at wgpu-hal/src/gles/web.rs:156 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the canvas element with the matching data-raw-handle attribute exists in the document","Register the canvas with the windowing system before creating the surface"],"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"}