a-b-street/abstreet · error · anyhow::Error
error getting context for WebGL 1.0
Error message
error getting context for WebGL 1.0: {:?} What it means
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.
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.
Example fix
// before
let maybe_context: Option<_> = canvas
.get_context("webgl")
.map_err(|err| anyhow!("error getting context for WebGL 1.0: {:?}", err))?;
// after: caller-side clear diagnostics
let ctx = webgl1_glow_context(canvas)
.map_err(|e| anyhow!("GPU rendering unavailable (enable WebGL/hardware acceleration): {}", e))?; Defensive patterns
Strategy: try-catch
Validate before calling
// Detect any WebGL support before setup
if (!document.createElement('canvas').getContext('webgl')) {
renderNoWebGLMessage(); // block app start early with guidance
} Try / catch
// Catch and show actionable user guidance
let ctx = webgl1_glow_context(canvas).map_err(|e| {
anyhow!("Enable GPU/WebGL in your browser settings. details: {}", e)
})?; Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
- error getting context for WebGL 2.0
- Browser doesn't support WebGL 2.0
- Browser doesn't support WebGL 1.0
- no window?
- local_storage failed
AI-assisted analysis of a-b-street/abstreet@0964f29315 (2026-09-13).
Data as JSON: /api/errors/9061e1b71c916b6c.
Report an issue: GitHub.
Appendix: source
Thrown at widgetry/src/backend_glow_wasm.rs:97
})
.unwrap();
fn webgl2_glow_context(canvas: &web_sys::HtmlCanvasElement) -> Result<glow::Context> {
let maybe_context: Option<_> = canvas
.get_context("webgl2")
.map_err(|err| anyhow!("error getting context for WebGL 2.0: {:?}", err))?;
let js_webgl2_context =
maybe_context.ok_or(anyhow!("Browser doesn't support WebGL 2.0"))?;
let webgl2_context = js_webgl2_context
.dyn_into::<web_sys::WebGl2RenderingContext>()
.map_err(|err| anyhow!("unable to cast to WebGl2RenderingContext. error: {:?}", err))?;
Ok(glow::Context::from_webgl2_context(webgl2_context))
}
fn webgl1_glow_context(canvas: &web_sys::HtmlCanvasElement) -> Result<glow::Context> {
let maybe_context: Option<_> = canvas
.get_context("webgl")
.map_err(|err| anyhow!("error getting context for WebGL 1.0: {:?}", err))?;
let js_webgl1_context =
maybe_context.ok_or(anyhow!("Browser doesn't support WebGL 1.0"))?;
let webgl1_context = js_webgl1_context
.dyn_into::<web_sys::WebGlRenderingContext>()
.map_err(|err| anyhow!("unable to cast to WebGlRenderingContext. error: {:?}", err))?;
Ok(glow::Context::from_webgl1_context(webgl1_context))
}
(
PrerenderInnards::new(gl, is_gl2, program, Some(WindowAdapter(winit_window))),
event_loop,
)
}
fn webgl2_program(gl: glow::Context) -> Result<(glow::Context, glow::Program)> {
let program = unsafe {
build_program(
&gl,View on GitHub (pinned to 0964f29315)