coderef

contextlost and contextrestoredLimited availability

The contextlost event for <canvas> fires when the canvas backing storage is lost, while the contextrestored event fires when it is recreated.

Not yet supported in all major browsers — check the table and provide a fallback.

Browser support

DesktopChrome
1–98Not supported
99+Supportedsince Mar 1, 2022
Current: 155
Edge
12–98Not supported
99+Supportedsince Mar 3, 2022
Current: 154
Firefox
1–124Not supported
125+Supportedsince Apr 16, 2024
Current: 157
Safari
✕Not supportedup to 27
Current: 27
MobileChrome Android
18–98Not supported
99+Supportedsince Mar 1, 2022
Current: 155
Firefox Android
4–124Not supported
125+Supportedsince Apr 16, 2024
Current: 157
Safari iOS
✕Not supportedup to 27
Current: 27

How to use

Not supported in Safari, Safari iOS. Use feature detection below and provide a fallback (or a polyfill) for those browsers.

Example

Full syntax and examples are on MDN: isContextLost.

Feature detection

JS · check before using
if ("CanvasRenderingContext2D" in globalThis && "isContextLost" in CanvasRenderingContext2D.prototype) {
  // CanvasRenderingContext2D.isContextLost is available
}

Sub-features

Support for each part of the feature (6). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
CanvasRenderingContext2D.isContextLost9999125✕99125✕
HTMLCanvasElement.contextlost_event9999125✕99125✕
HTMLCanvasElement.contextrestored_event9999125✕99125✕
OffscreenCanvas.contextlost_event9999125✕99125✕
OffscreenCanvas.contextrestored_event9999125✕99125✕
OffscreenCanvasRenderingContext2D.isContextLost9999125✕99125✕