const ctx = canvas.getContext("2d");
if (ctx.isContextLost()) {
console.log("Context is lost");
}CanvasRenderingContext2D: isContextLost() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.