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: 155Edge
12–98Not supported
99+Supportedsince Mar 3, 2022
Current: 154Firefox
1–124Not supported
125+Supportedsince Apr 16, 2024
Current: 157Safari
✕Not supportedup to 27
Current: 27MobileChrome Android
18–98Not supported
99+Supportedsince Mar 1, 2022
Current: 155Firefox Android
4–124Not supported
125+Supportedsince Apr 16, 2024
Current: 157Safari iOS
✕Not supportedup to 27
Current: 27How 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-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| CanvasRenderingContext2D.isContextLost | 99 | 99 | 125 | ✕ | 99 | 125 | ✕ |
| HTMLCanvasElement.contextlost_event | 99 | 99 | 125 | ✕ | 99 | 125 | ✕ |
| HTMLCanvasElement.contextrestored_event | 99 | 99 | 125 | ✕ | 99 | 125 | ✕ |
| OffscreenCanvas.contextlost_event | 99 | 99 | 125 | ✕ | 99 | 125 | ✕ |
| OffscreenCanvas.contextrestored_event | 99 | 99 | 125 | ✕ | 99 | 125 | ✕ |
| OffscreenCanvasRenderingContext2D.isContextLost | 99 | 99 | 125 | ✕ | 99 | 125 | ✕ |