{"record":{"id":"08bcc1980f89b219","repo":"remotion-dev/remotion","slug":"failed-to-acquire-2d-context-for-color-parsing-08bcc1","errorCode":null,"errorMessage":"Failed to acquire 2D context for color parsing","messagePattern":"Failed to acquire 2D context for color parsing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/effects/src/thermal-vision.ts","lineNumber":272,"sourceCode":"\n\tgl.bindBuffer(gl.ARRAY_BUFFER, vbo);\n\tgl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);\n\n\tconst aPos = gl.getAttribLocation(program, 'aPos');\n\tconst aUv = gl.getAttribLocation(program, 'aUv');\n\tgl.enableVertexAttribArray(aPos);\n\tgl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);\n\tgl.enableVertexAttribArray(aUv);\n\tgl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);\n\n\tgl.bindVertexArray(null);\n\n\tconst colorCanvas = document.createElement('canvas');\n\tcolorCanvas.width = 1;\n\tcolorCanvas.height = 1;\n\tconst colorCtx = colorCanvas.getContext('2d', {willReadFrequently: true});\n\tif (!colorCtx) {\n\t\tthrow new Error('Failed to acquire 2D context for color parsing');\n\t}\n\n\treturn {\n\t\tgl,\n\t\tprogram,\n\t\tvao,\n\t\tvbo,\n\t\tsourceTexture: createTexture(gl, gl.LINEAR),\n\t\tpaletteTexture: createTexture(gl, gl.LINEAR),\n\t\tcolorCtx,\n\t\tuniforms: {\n\t\t\tuSource: gl.getUniformLocation(program, 'uSource'),\n\t\t\tuPalette: gl.getUniformLocation(program, 'uPalette'),\n\t\t\tuPaletteLength: gl.getUniformLocation(program, 'uPaletteLength'),\n\t\t\tuAmount: gl.getUniformLocation(program, 'uAmount'),\n\t\t},\n\t\tcachedPaletteKey: '',\n\t\tpalettePixelData: new Uint8Array(0),","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/effects/src/thermal-vision.ts#L254-L290","documentation":"During thermal vision effect `setup`, an internal offscreen 1x1 canvas is created to parse palette colors via the 2D API. If `canvas.getContext('2d', {willReadFrequently: true})` returns `null`, this error is thrown. This is unusual because a fresh offscreen canvas should always support a 2D context; failure typically indicates an environment where the 2D canvas backend is unavailable or blocked.","triggerScenarios":"Running in an environment where the Canvas 2D backend is unavailable or disabled; a browser/JS engine configuration that denies 2D context creation; extremely constrained headless environments. The canvas is created with `document.createElement('canvas')` so it is not shared with the GL context.","commonSituations":"A JS runtime or browser build with the 2D canvas backend stripped/disabled; a custom rendering host that overrides `document.createElement` or `HTMLCanvasElement.getContext`; edge-case headless configurations.","solutions":["Run in a standard browser or headless Chrome build that supports the Canvas 2D API.","If using a custom host/jsdom-like environment, ensure `HTMLCanvasElement.prototype.getContext` returns a real 2D context.","Verify no browser setting or extension is disabling canvas 2D rendering.","Update the browser/runtime to a version with full Canvas 2D support."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify a 2D context can be obtained before relying on thermalVision.\nconst supportsCanvas2D = (): boolean => {\n  try {\n    return !!document\n      .createElement('canvas')\n      .getContext('2d', {willReadFrequently: true});\n  } catch {\n    return false;\n  }\n};\nif (!supportsCanvas2D()) { /* thermalVision will fail; use fallback */ }","typeGuard":null,"tryCatchPattern":"try {\n  thermalVision({...params});\n} catch (e) {\n  if (/Failed to acquire 2D context for color parsing/.test((e as Error).message)) {\n    console.error('Canvas 2D unavailable in this environment');\n    renderFallbackFrame();\n  } else throw e;\n}","preventionTips":["Run in a standard browser or headless Chrome build with Canvas 2D support.","If using a custom host (jsdom-like), ensure `getContext('2d')` returns a real context.","Probe for Canvas 2D availability before mounting webgl2 effects that parse colors."],"tags":["thermal-vision","canvas2d","context","setup","environment"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}