{"record":{"id":"31e255ca85a8bca3","repo":"remotion-dev/remotion","slug":"could-not-create-canvas-context","errorCode":null,"errorMessage":"Could not create canvas context","messagePattern":"Could not create canvas context","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts","lineNumber":67,"sourceCode":"): Element | null => {\n\tif (element?.tagName === 'CANVAS' || element?.tagName === 'VIDEO') {\n\t\treturn element;\n\t}\n\n\treturn element?.querySelector('canvas, video') ?? null;\n};\n\nconst copyImageToClipboard = async (element: Element): Promise<void> => {\n\tlet canvas: HTMLCanvasElement;\n\n\tif (element.tagName === 'CANVAS') {\n\t\tconst sourceCanvas = element as HTMLCanvasElement;\n\t\tcanvas = document.createElement('canvas');\n\t\tcanvas.width = sourceCanvas.width;\n\t\tcanvas.height = sourceCanvas.height;\n\t\tconst context = canvas.getContext('2d');\n\t\tif (!context) {\n\t\t\tthrow new Error('Could not create canvas context');\n\t\t}\n\n\t\tcontext.drawImage(sourceCanvas, 0, 0);\n\t} else if (element.tagName === 'IMG') {\n\t\tconst image = element as HTMLImageElement;\n\t\tif (image.naturalWidth === 0 || image.naturalHeight === 0) {\n\t\t\tthrow new Error('Image has not loaded');\n\t\t}\n\n\t\tcanvas = document.createElement('canvas');\n\t\tcanvas.width = image.naturalWidth;\n\t\tcanvas.height = image.naturalHeight;\n\t\tconst context = canvas.getContext('2d');\n\t\tif (!context) {\n\t\t\tthrow new Error('Could not create canvas context');\n\t\t}\n\n\t\tcontext.drawImage(image, 0, 0);","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts#L49-L85","documentation":"When copying a frame as an image from the sequence context menu, copyImageToClipboard creates an offscreen canvas and draws the source canvas into it. document.createElement('canvas')'s getContext('2d') returning null (rare, e.g. canvas blocked by browser policy or memory pressure) throws this error.","triggerScenarios":"Right-clicking a canvas-based frame in the Timeline and choosing the copy-image action while getContext('2d') returns null — typically when the browser cannot allocate a 2D context (out of memory, too many contexts, or canvas disabled by policy/privacy setting).","commonSituations":"Browsers at the ~16 active canvas-context limit in long Studio sessions; embedded browsers or kiosk modes with canvas disabled; very large canvases exhausting memory on low-RAM machines.","solutions":["Retry the copy action — context allocation failures are often transient; closing unused tabs frees contexts.","Reduce timeline zoom/thumbnail size or the composition resolution to lower canvas memory pressure.","Check browser settings/enterprise policy that disables canvas (e.g. canvas readback blocking).","Use an alternative export path (e.g. render a still via the CLI) if clipboard copy keeps failing."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const probe = document.createElement('canvas').getContext('2d');\nif (!probe) console.warn('2D canvas context unavailable in this environment');","typeGuard":"const has2d = (c: HTMLCanvasElement): c is HTMLCanvasElement & {getContext: (t: '2d') => CanvasRenderingContext2D} =>\n  c.getContext('2d') !== null;","tryCatchPattern":"try {\n  await copyImageToClipboard(el);\n} catch (e) {\n  if (e.message === 'Could not create canvas context') {\n    // free contexts / retry once, else show a toast suggesting remotion still export\n  } else throw e;\n}","preventionTips":["Close unused canvases/tabs in long Studio sessions to stay under browser context limits.","Avoid enterprise policies that disable canvas readback on dev machines.","Keep compositions at moderate preview resolutions."],"tags":["canvas","clipboard","browser","memory"],"backgroundTag":"resource-exhaustion","analyzedSha":"46a3a6bf13ca367376ff18bbb06dae2e87e0d068","analyzedAt":"2026-09-18T00:12:20.256Z","contentChangedAt":"2026-09-18T00:12:20.256Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}