This feature is not Baseline because it does not work in some of the most widely-used browsers.
The CanvasRenderingContext2D.isContextLost() method of the Canvas 2D API returns true if the rendering context is lost (and has not yet been reset). This might occur due to driver crashes, running out of memory, and so on.
If the user agent detects that the canvas backing storage is lost it will fire the contextlost event at the associated HTMLCanvasElement. If this event is not cancelled it will attempt to reset the backing storage to the default state (this is equivalent to calling CanvasRenderingContext2D.reset()). On success it will fire the contextrestored event, indicating that the context is ready to reinitialize and redraw.
isContextLost()
None.
true if the rendering context was lost; false otherwise.
const ctx = canvas.getContext("2d");
if (ctx.isContextLost()) {
console.log("Context is lost");
}
| Specification |
|---|
| HTML> # dom-context-2d-iscontextlost> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
isContextLost |
99 | 99 | 125 | 85 | No | 99 | 125 | 68 | No | 18.0 | 99 | No |
CanvasRenderingContext2D
HTMLCanvasElement: contextlost eventHTMLCanvasElement: contextrestored event
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/isContextLost