{"record":{"id":"d1223698dafe13f6","repo":"gfx-rs/wgpu","slug":"canvas-context-is-not-a-webgl2renderingcontext","errorCode":null,"errorMessage":"canvas context is not a WebGl2RenderingContext","messagePattern":"canvas context is not a WebGl2RenderingContext","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu-hal/src/gles/web.rs","lineNumber":90,"sourceCode":"                return Err(crate::InstanceError::new(String::from(concat!(\n                    \"canvas.getContext() returned null; \",\n                    \"webgl2 not available or canvas already in use\"\n                ))));\n            }\n            Err(js_error) => {\n                // <https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-getcontext>\n                // A thrown exception indicates misuse of the canvas state.\n                return Err(crate::InstanceError::new(format!(\n                    \"canvas.getContext() threw exception {js_error:?}\",\n                )));\n            }\n        };\n\n        // Not returning this error because it is a type error that shouldn't happen unless\n        // the browser, JS builtin objects, or wasm bindings are misbehaving somehow.\n        let webgl2_context: web_sys::WebGl2RenderingContext = context_object\n            .dyn_into()\n            .expect(\"canvas context is not a WebGl2RenderingContext\");\n\n        Ok(Surface {\n            canvas,\n            webgl2_context,\n            srgb_present_program: Mutex::new(None),\n            swapchain: RwLock::new(None),\n            texture: Mutex::new(None),\n            presentable: true,\n        })\n    }\n\n    fn create_context_options() -> js_sys::Object {\n        let context_options = js_sys::Object::new();\n        js_sys::Reflect::set(&context_options, &\"antialias\".into(), &JsValue::FALSE)\n            .expect(\"Cannot create context options\");\n        context_options\n    }\n}","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu-hal/src/gles/web.rs#L72-L108","documentation":"Panic in the GLES/web backend: the object returned by canvas.getContext('webgl2') is not a WebGl2RenderingContext, so it cannot be used to build a glow context. The faulty input is the canvas's context object (wrong type or backend mismatch).","triggerScenarios":"Thrown at wgpu-hal/src/gles/web.rs:90 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the canvas is fresh (getContext not already called with another type) and webgl2 is available","Check the context type before handing the canvas to wgpu"],"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"}