{"record":{"id":"9061e1b71c916b6c","repo":"a-b-street/abstreet","slug":"error-getting-context-for-webgl-1-0","errorCode":null,"errorMessage":"error getting context for WebGL 1.0: {:?}","messagePattern":"error getting context for WebGL 1\\.0: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"widgetry/src/backend_glow_wasm.rs","lineNumber":97,"sourceCode":"        })\n        .unwrap();\n\n    fn webgl2_glow_context(canvas: &web_sys::HtmlCanvasElement) -> Result<glow::Context> {\n        let maybe_context: Option<_> = canvas\n            .get_context(\"webgl2\")\n            .map_err(|err| anyhow!(\"error getting context for WebGL 2.0: {:?}\", err))?;\n        let js_webgl2_context =\n            maybe_context.ok_or(anyhow!(\"Browser doesn't support WebGL 2.0\"))?;\n        let webgl2_context = js_webgl2_context\n            .dyn_into::<web_sys::WebGl2RenderingContext>()\n            .map_err(|err| anyhow!(\"unable to cast to WebGl2RenderingContext. error: {:?}\", err))?;\n        Ok(glow::Context::from_webgl2_context(webgl2_context))\n    }\n\n    fn webgl1_glow_context(canvas: &web_sys::HtmlCanvasElement) -> Result<glow::Context> {\n        let maybe_context: Option<_> = canvas\n            .get_context(\"webgl\")\n            .map_err(|err| anyhow!(\"error getting context for WebGL 1.0: {:?}\", err))?;\n        let js_webgl1_context =\n            maybe_context.ok_or(anyhow!(\"Browser doesn't support WebGL 1.0\"))?;\n        let webgl1_context = js_webgl1_context\n            .dyn_into::<web_sys::WebGlRenderingContext>()\n            .map_err(|err| anyhow!(\"unable to cast to WebGlRenderingContext. error: {:?}\", err))?;\n        Ok(glow::Context::from_webgl1_context(webgl1_context))\n    }\n\n    (\n        PrerenderInnards::new(gl, is_gl2, program, Some(WindowAdapter(winit_window))),\n        event_loop,\n    )\n}\n\nfn webgl2_program(gl: glow::Context) -> Result<(glow::Context, glow::Program)> {\n    let program = unsafe {\n        build_program(\n            &gl,","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/widgetry/src/backend_glow_wasm.rs#L79-L115","documentation":"webgl1_glow_context requests a \"webgl\" (WebGL 1.0) context from the canvas. If the get_context call itself errors (a JS-level failure, not a null return), the JsValue is wrapped in this anyhow error. It is the GL1 counterpart of error 216 and occurs during setup's fallback path.","triggerScenarios":"setup() falls back to webgl1_glow_context (after WebGL 2 is unavailable) and canvas.get_context(\"webgl\") rejects — tainted canvas, WebGL blocked entirely, or binding-level JS exception.","commonSituations":"Environments with all WebGL disabled (privacy hardening, headless servers, blocked GPU acceleration); canvas previously acquired with a different context type; browsers whose getContext throws under strict security policies.","solutions":["Enable WebGL/hardware acceleration in the browser; verify about:gpu or browser diagnostics.","Ensure no prior 2d/experimental context was requested on the same canvas.","If neither WebGL 1 nor 2 works, the environment cannot run the renderer — switch browsers or run natively (non-wasm).","In setup, surface both errors to the user with guidance to enable GPU acceleration."],"exampleFix":"// before\nlet maybe_context: Option<_> = canvas\n    .get_context(\"webgl\")\n    .map_err(|err| anyhow!(\"error getting context for WebGL 1.0: {:?}\", err))?;\n// after: caller-side clear diagnostics\nlet ctx = webgl1_glow_context(canvas)\n    .map_err(|e| anyhow!(\"GPU rendering unavailable (enable WebGL/hardware acceleration): {}\", e))?;","handlingStrategy":"try-catch","validationCode":"// Detect any WebGL support before setup\nif (!document.createElement('canvas').getContext('webgl')) {\n  renderNoWebGLMessage(); // block app start early with guidance\n}","typeGuard":null,"tryCatchPattern":"// Catch and show actionable user guidance\nlet ctx = webgl1_glow_context(canvas).map_err(|e| {\n    anyhow!(\"Enable GPU/WebGL in your browser settings. details: {}\", e)\n})?;","preventionTips":["Feature-detect WebGL 1 in JS before loading the renderer","Ensure the canvas is fresh (no prior non-WebGL context)","Provide a clear 'enable hardware acceleration' message on failure","Run smoke tests in hardened/headless browsers to catch blocking policies"],"tags":["webgl","wasm","browser","rendering"],"backgroundTag":"unsupported-platform","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}