OffscreenCanvas: contextrestored-Ereignis

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Das contextrestored-Ereignis des OffscreenCanvas-Interfaces wird ausgelöst, wenn der Browser einen OffscreenCanvasRenderingContext2D-Kontext wiederherstellt, der zuvor verloren gegangen war.

Sie können nach Empfang dieses Ereignisses Ihre Zeichenoperationen erneut ausführen, Ressourcen erneut abrufen und den Zustand Ihres Kontextes neu initialisieren.

Syntax

Verwenden Sie den Ereignisnamen in Methoden wie addEventListener() oder setzen Sie eine Event-Handler-Eigenschaft.

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

oncontextrestored = (event) => {};

Ereignistyp

Ein generisches Event.

Beispiele

Das folgende Codefragment erkennt das Kontext-wiederhergestellt-Ereignis.

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

canvas.addEventListener(
  "contextrestored",
  (e) => {
    console.log(e);
    // call to redrawCanvas() or similar
  },
  false,
);

Spezifikationen

Specification
HTML
# event-contextrestored
HTML
# handler-offscreencanvas-oncontextrestored

Browser-Kompatibilität

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

Legend

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

Full support
Full support
No support
No support

Siehe auch