HTMLCanvasElement: contextrestored event

Limited availability

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

The contextrestored event of the Canvas API is fired if the user agent restores the backing storage for a CanvasRenderingContext2D.

You can redraw, re-retrieve resources, and reinitialize the state of your context after receiving this event.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

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

oncontextrestored = (event) => { }

Event type

A generic Event.

Example

The code fragment below detects the context restored event.

js
const canvas = document.getElementById("canvas");

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

Specifications

Specification
HTML
# event-contextrestored

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
contextrestored event
Chrome – Full support
Chrome 99 (Release date: 2022-03-01)
footnote Full support
Edge – Full support
Edge 99 (Release date: 2022-03-03)
footnote Full support
Firefox – Full support
Firefox 125 (Release date: 2024-04-16)
footnote Full support
Opera – Full support
Opera 85 (Release date: 2022-03-23)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 99 (Release date: 2022-03-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 125 (Release date: 2024-04-16)
footnote Full support
Opera Android – Full support
Opera Android 68 (Release date: 2022-03-30)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 18 (Release date: 2022-08-08)
footnote Full support
WebView Android – Full support
WebView Android 99 (Release date: 2022-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

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

Full support
Full support
No support
No support

See also