This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The webglcontextlost event of the WebGL API is fired if the user agent detects that the drawing buffer associated with a WebGLRenderingContext object has been lost.
This event does not bubble.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("webglcontextlost", (event) => { })
onwebglcontextlost = (event) => { }
A WebGLContextEvent. Inherits from Event.
This interface inherits properties from its parent interface, Event.
WebGLContextEvent.statusMessageA read-only property containing additional information about the event.
With the help of the WEBGL_lose_context extension, you can simulate the webglcontextlost event:
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
canvas.addEventListener("webglcontextlost", (event) => {
console.log(event);
});
gl.getExtension("WEBGL_lose_context").loseContext();
// "webglcontextlost" event is logged.
| Specification |
|---|
| WebGL Specification> # 5.15.2> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
webglcontextlost_event |
9 | 12 | 4 | 12 | 5.1 | 25 | 4 | 12 | 8 | 1.5 | 4.4 | 8 |
WebGLContextEventWebGLRenderingContext.isContextLost()WEBGL_lose_context, WEBGL_lose_context.loseContext(), WEBGL_lose_context.restoreContext()
© 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/HTMLCanvasElement/webglcontextlost_event