WebGLRenderingContext: isContextLost() method

Note: This feature is available in Web Workers.

The WebGLRenderingContext.isContextLost() method returns a boolean value indicating whether or not the WebGL context has been lost and must be re-established before rendering can resume.

Syntax

js
isContextLost()

Parameters

None.

Return value

A boolean value which is true if the context is lost, or false if not.

Usage notes

There are several reasons why a WebGL context may be lost, making it necessary to re-establish the context before resuming rendering. Examples include:

Examples

For example, when checking for program linking success, you could also check if the context is not lost:

js
gl.linkProgram(program);

if (!gl.getProgramParameter(program, gl.LINK_STATUS) && !gl.isContextLost()) {
  const info = gl.getProgramInfoLog(program);
  console.log(`Error linking program:\n${info}`);
}

Specifications

See also