MDN self-hosted library · e01.org

OffscreenCanvas: contextlost event

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const canvas = new OffscreenCanvas(256, 256);
const gl = offscreen.getContext("2d");

// Do drawing etc

canvas.addEventListener("contextlost", (event) => {
  console.log(event);
});
js
canvas.addEventListener("contextlost", (event) => {
  event.preventDefault();
});