HTMLCanvasElement: webglcontextlost イベント

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.

webglcontextlostWebGL API のイベントで、WebGLRenderingContext オブジェクトに関連づけられた描画バッファーが失われたことをユーザーエージェントが検出した場合に発行されます。

このイベントはバブリングしません。

構文

このイベント名を addEventListener() などのメソッドで使用したり、イベントハンドラープロパティを設定したりしてください。

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

onwebglcontextlost = (event) => {};

イベント型

WebGLContextEvent です。Event を継承しています。

Event WebGLContextEvent

イベントプロパティ

このインターフェイスには親インターフェイスである Event から継承したプロパティもあります。

WebGLContextEvent.statusMessage

読み取り専用のプロパティで、イベントに関する追加情報を保持します。

WEBGL_lose_context 拡張機能の助けにより、webglcontextlost イベントをシミュレートすることができます。

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.

仕様書

Specification
WebGL Specification
# 5.15.2

ブラウザーの互換性

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
webglcontextlost event

Legend

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

Full support
Full support

関連情報