This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.
The WEBGL_lose_context extension is part of the WebGL API and exposes functions to simulate losing and restoring a WebGLRenderingContext.
WebGL extensions are available using the WebGLRenderingContext.getExtension() method. For more information, see also Using Extensions in the WebGL tutorial.
WEBGL_lose_context.loseContext()Simulates losing the context.
WEBGL_lose_context.restoreContext()Simulates restoring the context.
With this extension, you can simulate the webglcontextlost and webglcontextrestored events:
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
canvas.addEventListener("webglcontextlost", (event) => {
console.log(event);
});
gl.getExtension("WEBGL_lose_context").loseContext();
// WebGLContextEvent event with type "webglcontextlost" is logged.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
WEBGL_lose_context |
2618 | 17 | 2219–58 | 1515 | 8 | 2618 | 2219–58 | 1414 | 8 | 1.51.0 | 4.44.4 | 8 |
loseContext |
26 | 17 | 2219–58 | 15 | 8 | 26 | 2219–58 | 14 | 8 | 1.5 | 4.4 | 8 |
restoreContext |
26 | 17 | 2219–58 | 15 | 8 | 26 | 2219–58 | 14 | 8 | 1.5 | 4.4 | 8 |
WebGLRenderingContext.isContextLost()webglcontextlost, webglcontextrestored, webglcontextcreationerror
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context