WebGLRenderingContext.isContextLost()

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.

WebGLRenderingContext.isContextLost() 方法返回一个Boolean 标记 WebGL 的上下文是否已经丢失。

语法

gl.isContextLost();

返回值

Boolean。如果上下文丢失则返回 true,否则返回 false。

样例

比如,当检查程序链接成功时,你也可以检查是否上下文已经丢失。

js
gl.linkProgram(program);

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

规范

Specification
WebGL Specification
# 5.14.13

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
isContextLost

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见