{"record":{"id":"a8f25a652dc5cad6","repo":"emilk/egui","slug":"failed-to-query-about-webgl2-context","errorCode":null,"errorMessage":"Failed to query about WebGL2 context","messagePattern":"Failed to query about WebGL2 context","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eframe/src/web/web_painter_glow.rs","lineNumber":123,"sourceCode":"        // Trying WebGl2 first\n        WebGlContextOption::BestFirst => init_webgl2(canvas).or_else(|| init_webgl1(canvas)),\n        // Trying WebGl1 first (useful for testing).\n        WebGlContextOption::CompatibilityFirst => {\n            init_webgl1(canvas).or_else(|| init_webgl2(canvas))\n        }\n    };\n\n    if let Some(result) = result {\n        Ok(result)\n    } else {\n        Err(\"WebGL isn't supported\".into())\n    }\n}\n\nfn init_webgl1(canvas: &HtmlCanvasElement) -> Option<(glow::Context, &'static str)> {\n    let gl1_ctx = canvas\n        .get_context(\"webgl\")\n        .expect(\"Failed to query about WebGL2 context\");\n\n    let gl1_ctx = gl1_ctx?;\n    log::debug!(\"WebGL1 selected.\");\n\n    let gl1_ctx = gl1_ctx\n        .dyn_into::<web_sys::WebGlRenderingContext>()\n        .unwrap();\n\n    let shader_prefix = if webgl1_requires_brightening(&gl1_ctx) {\n        log::debug!(\"Enabling webkitGTK brightening workaround.\");\n        \"#define APPLY_BRIGHTENING_GAMMA\"\n    } else {\n        \"\"\n    };\n\n    let gl = glow::Context::from_webgl1_context(gl1_ctx);\n\n    Some((gl, shader_prefix))","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/eframe/src/web/web_painter_glow.rs#L105-L141","documentation":"init_webgl1 calls canvas.get_context(\"webgl\") and unwraps with a (misleadingly worded) 'Failed to query about WebGL2 context' message. get_context only returns Err when the browser fails to query the context creation path itself (JS exception path), not when WebGL is merely unsupported — that returns Ok(None) which the subsequent `?` handles.","triggerScenarios":"Calling init_glow_context_from_canvas on a canvas whose getContext('webgl') throws or cannot be queried — e.g. a detached/invalid canvas, a canvas in a weird state, or a browser where the WebGL query path raises an exception.","commonSituations":"Embedded webviews with GPU access disabled; hardware acceleration blocked by browser flags or policy; canvases created before document attachment in some engines; corrupted GPU driver state causing context queries to fail.","solutions":["Ensure the canvas is attached and the browser supports/permits WebGL (enable hardware acceleration).","Replace .expect with graceful handling: match on the Result and fall back to WebGL2 or show an error message.","Check browser settings (chrome://gpu, --disable-gpu flags, corporate policies) that block context creation."],"exampleFix":"// before\nlet gl1_ctx = canvas.get_context(\"webgl\").expect(\"Failed to query about WebGL2 context\");\n// after\nlet gl1_ctx = canvas.get_context(\"webgl\").map_err(|e| log::error!(\"WebGL query failed: {e:?}\")).ok().flatten()?;","handlingStrategy":"try-catch","validationCode":"let can_query = canvas.is_connected(); // plus feature-detect: js_sys::eval(\"!!document.createElement('canvas').getContext('webgl')\")","typeGuard":"fn webgl_queryable(canvas: &HtmlCanvasElement) -> bool { canvas.get_context(\"webgl\").is_ok() }","tryCatchPattern":"// Replace expect: canvas.get_context(\"webgl\").map_err(log).ok().flatten() and fall back to WebGL2 or an error UI.","preventionTips":["Enable hardware acceleration / WebGL in target browsers and webviews.","Attach canvases to the document before requesting contexts.","Handle both Err (query failure) and Ok(None) (unsupported) from get_context separately."],"tags":["wasm","webgl","graphics","browser-environment"],"backgroundTag":"module-init-failed","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}