{"record":{"id":"f9dc2d360f4fb00c","repo":"remotion-dev/remotion","slug":"could-not-get-2d-canvas-context","errorCode":null,"errorMessage":"Could not get 2D canvas context","messagePattern":"Could not get 2D canvas context","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/convert/app/lib/canvas-capture-conversion.ts","lineNumber":241,"sourceCode":"\treturn {\n\t\tprocess: async (sample: VideoSample) => {\n\t\t\tconst moments = getCanvasCaptureSampleMoments({\n\t\t\t\ttimestamp: sample.timestamp,\n\t\t\t\tduration: sample.duration,\n\t\t\t\tcursorStateChanges,\n\t\t\t});\n\t\t\tconst sourceFrame = sample.toVideoFrame();\n\t\t\tconst outputSamples: VideoSample[] = [];\n\n\t\t\ttry {\n\t\t\t\tfor (const moment of moments) {\n\t\t\t\t\tconst canvas = new OffscreenCanvas(\n\t\t\t\t\t\tsample.displayWidth,\n\t\t\t\t\t\tsample.displayHeight,\n\t\t\t\t\t);\n\t\t\t\t\tconst context = canvas.getContext('2d');\n\t\t\t\t\tif (!context) {\n\t\t\t\t\t\tthrow new Error('Could not get 2D canvas context');\n\t\t\t\t\t}\n\n\t\t\t\t\tcontext.translate(\n\t\t\t\t\t\tmirrorHorizontal ? sample.displayWidth : 0,\n\t\t\t\t\t\tmirrorVertical ? sample.displayHeight : 0,\n\t\t\t\t\t);\n\t\t\t\t\tcontext.scale(mirrorHorizontal ? -1 : 1, mirrorVertical ? -1 : 1);\n\t\t\t\t\tcontext.drawImage(\n\t\t\t\t\t\tsourceFrame,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tsample.displayWidth,\n\t\t\t\t\t\tsample.displayHeight,\n\t\t\t\t\t);\n\n\t\t\t\t\tconst cursor = findCanvasCaptureCursorAtTime(\n\t\t\t\t\t\tmouseMovements,\n\t\t\t\t\t\tmoment.cursorLookupTimestamp,","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/convert/app/lib/canvas-capture-conversion.ts#L223-L259","documentation":"Thrown when OffscreenCanvas.getContext('2d') returns null inside the canvas-capture video processor. The 2D context is required to drawImage the source frame with mirroring/flipping before re-encoding; without it, sample processing cannot continue.","triggerScenarios":"Running in an environment where OffscreenCanvas exists but 2D context is unavailable (some headless/embedded browsers, hardened contexts, or memory pressure causing context allocation to fail). Also possible if OffscreenCanvas is polyfilled incompletely.","commonSituations":"Headless browser automation without GPU/2D canvas support; very low memory causing context creation to fail; older Safari without full OffscreenCanvas 2D support; browser privacy/incognito restrictions.","solutions":["Run Convert in a current desktop Chrome/Edge where OffscreenCanvas 2D is fully supported.","Detect getContext('2d') === null up front and show a 'browser unsupported' message instead of starting the conversion.","Free other GPU/canvas contexts before allocating to avoid resource exhaustion."],"exampleFix":"// before\nconst context = canvas.getContext('2d');\nif (!context) throw new Error('Could not get 2D canvas context');\n\n// after\nconst context = canvas.getContext('2d');\nif (!context) {\n  throw new Error('This browser cannot provide a 2D canvas context. Use the latest Chrome or Edge.');\n}","handlingStrategy":"validation","validationCode":"const supported = typeof OffscreenCanvas !== 'undefined'\n  && (() => { try { return new OffscreenCanvas(1,1).getContext('2d') != null; } catch { return false; } })();\nif (!supported) { showError('Use the latest Chrome or Edge to convert canvas captures.'); return; }","typeGuard":"function supportsOffscreen2d(): boolean {\n  if (typeof OffscreenCanvas === 'undefined') return false;\n  try {\n    const c = new OffscreenCanvas(1, 1);\n    return c.getContext('2d') !== null;\n  } catch { return false; }\n}","tryCatchPattern":"try {\n  await process(sample);\n} catch (e) {\n  if (e.message === 'Could not get 2D canvas context') showUnsupportedBrowser();\n  else throw e;\n}","preventionTips":["Feature-detect OffscreenCanvas 2D support before enabling Convert.","Use current Chrome/Edge for canvas-capture conversion.","Free other canvas contexts to avoid resource exhaustion."],"tags":["typescript","convert","canvas-capture","offscreen-canvas","browser-support"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}