HTMLCanvasElement: webglcontextlost event
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thewebglcontextlost event of theWebGL API is fired if the user agent detects that the drawing buffer associated with aWebGLRenderingContext object has been lost.
This event does not bubble.
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
js
addEventListener("webglcontextlost", (event) => { })onwebglcontextlost = (event) => { }Event type
AWebGLContextEvent. Inherits fromEvent.
Event properties
This interface inherits properties from its parent interface,Event.
WebGLContextEvent.statusMessageA read-only property containing additional information about the event.
Example
With the help of theWEBGL_lose_context extension, you can simulate thewebglcontextlost event:
js
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.Specifications
| Specification |
|---|
| WebGL Specification> # 5.15.2> |