WEBGL_lose_context 扩展属于 WebGL API and exposes functions to simulate losing and restoring a WebGLRenderingContext .

WebGL extensions are available using the WebGLRenderingContext.getExtension() method. For more information, see also 使用扩展 WebGL 教程 .

可用性: This extension is available to both, WebGL1 and WebGL2 上下文。

方法

WEBGL_lose_context.loseContext()

Simulates losing the context.

WEBGL_lose_context.restoreContext()

Simulates restoring the context.

范例

With this extension, you can simulate the webglcontextlost and webglcontextrestored 事件:

const canvas = document.getElementById('canvas');
const gl = canvas.getContext('webgl');
canvas.addEventListener('webglcontextlost', (event) => {
  console.log(event);
});
gl.getExtension('WEBGL_lose_context').loseContext();
// WebGLContextEvent event with type "webglcontextlost" is logged.
					

规范

规范 状态 注释
WEBGL_lose_context
The definition of 'WEBGL_lose_context' in that specification.
推荐 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
loseContext Chrome Yes Edge 17 Firefox 22
22
不支持 19 — 58 Prefixed
Prefixed Implemented with the vendor prefix: MOZ_
IE ? Opera Yes Safari ? WebView Android Yes Chrome Android Yes Firefox Android ? Opera Android Yes Safari iOS ? Samsung Internet Android Yes

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改: