docs.rodeo

MDN Web Docs mirror

HTMLCanvasElement: webglcontextlost event

{{APIRef}} 

The webglcontextlost event of the WebGL API is fired if the user agent detects that the drawing buffer associated with a {{domxref("WebGLRenderingContext")}}  object has been lost.

This event does not bubble.

Syntax

Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}} , or set an event handler property.

addEventListener("webglcontextlost", (event) => {});

onwebglcontextlost = (event) => {};

Event type

A {{domxref("WebGLContextEvent")}} . Inherits from {{domxref("Event")}} .

{{InheritanceDiagram("WebGLContextEvent")}} 

Event properties

This interface inherits properties from its parent interface, {{domxref("Event")}} .

Example

With the help of the {{domxref("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.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN