demo · v139

WebGL Failure Handler

Construct a context the right way: feature-detect, listen for webglcontextcreationerror, and surface a Canvas2D fallback. Toggle the failure modes the SwiftShader removal exposes — “no GPU”, “denied”, “lost mid-frame” — and see what your users see.

Status: probing…

recommended pattern

// Up-front feature detection. The error event fires synchronously with attribution
// of *why* the context failed — invaluable for telemetry and user messaging.
const canvas = document.querySelector('canvas');
canvas.addEventListener('webglcontextcreationerror', (e) => {
  // 139+: no SwiftShader fallback, getContext returns null and this fires
  telemetry('webgl_failed', { statusMessage: e.statusMessage });
  fallbackToCanvas2D(canvas);
});
const gl = canvas.getContext('webgl2', { failIfMajorPerformanceCaveat: true });
if (!gl) {
  // Either feature is gone or we lost the major-perf race.
  fallbackToCanvas2D(canvas);
}
canvas.addEventListener('webglcontextlost', (e) => {
  e.preventDefault();          // request restoration if possible
  pauseRender();
});
canvas.addEventListener('webglcontextrestored', () => restoreRender());

see also