{"record":{"id":"c215f74090685fab","repo":"BabylonJS/Babylon.js","slug":"dumpdata-no-webgl-context-available-cannot-dump","errorCode":null,"errorMessage":"DumpData: No WebGL context available. Cannot dump data.","messagePattern":"DumpData: No WebGL context available\\. Cannot dump data\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Misc/dumpTools.pure.ts","lineNumber":39,"sourceCode":"        renderer: EffectRenderer;\r\n        wrapper: EffectWrapper;\r\n    };\r\n};\r\n\r\nlet ResourcesPromise: Promise<DumpResources> | null = null;\r\n\r\nasync function _CreateDumpResourcesAsync(): Promise<DumpResources> {\r\n    // Create a compatible canvas. Prefer an HTMLCanvasElement if possible to avoid alpha issues with OffscreenCanvas + WebGL in many browsers.\r\n    const canvas = (EngineStore.LastCreatedEngine?.createCanvas(100, 100) ?? new OffscreenCanvas(100, 100)) as HTMLCanvasElement | OffscreenCanvas; // will be resized later\r\n    if (canvas instanceof OffscreenCanvas) {\r\n        Logger.Warn(\"DumpData: OffscreenCanvas will be used for dumping data. This may result in lossy alpha values.\");\r\n    }\r\n\r\n    // If WebGL via ThinEngine is not available, we cannot encode the data.\r\n    // If https://github.com/whatwg/html/issues/10142 is resolved, we can migrate to just BitmapRenderer and avoid an engine dependency altogether.\r\n    const { ThinEngine: thinEngineClass } = await import(\"../Engines/thinEngine.pure\");\r\n    if (!thinEngineClass.IsSupported) {\r\n        throw new Error(\"DumpData: No WebGL context available. Cannot dump data.\");\r\n    }\r\n\r\n    const options = {\r\n        preserveDrawingBuffer: true,\r\n        depth: false,\r\n        stencil: false,\r\n        alpha: true,\r\n        premultipliedAlpha: false,\r\n        antialias: false,\r\n        failIfMajorPerformanceCaveat: false,\r\n    };\r\n    const engine = new thinEngineClass(canvas, false, options);\r\n\r\n    // remove this engine from the list of instances to avoid using it for other purposes\r\n    EngineStore.Instances.pop();\r\n    // However, make sure to dispose it when no other engines are left\r\n    EngineStore.OnEnginesDisposedObservable.add((e) => {\r\n        // guaranteed to run when no other instances are left\r","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Misc/dumpTools.pure.ts#L21-L57","documentation":"DumpTools' pure (DOM-independent) dump path lazily imports ThinEngine to get a GPU context for encoding dump data. If ThinEngine.IsSupported is false — no usable WebGL — there is no way to encode the dump, so the library throws this explicit error instead of failing later with an opaque context error.","triggerScenarios":"Calling dump-data APIs (e.g. DumpData/DumpDataAsync via _CreateDumpResourcesAsync) in an environment without WebGL support — headless Node, workers with no canvas/GL, browsers with WebGL disabled, or after a context-loss.","commonSituations":"Running screenshot/dump tests in CI (headless, no GPU or no swiftshader); WebGL blocked by browser flags or driver blocklists; using the pure dump tools outside a browser page that provides a WebGL context.","solutions":["Run in an environment with WebGL available, or enable SwiftShader/llvmpipe software GL in headless CI (e.g. --use-gl=swiftshader in Chromium)","Check ThinEngine.IsSupported (or create an engine and check engine.isSupported) before attempting a dump and surface a friendly message instead","Use a non-WebGL dump path if available (e.g. plain canvas 2D rendering of the data) instead of the GPU-encoded dump tools","If WebGL worked before, investigate context loss / driver blocklist (chrome://gpu) and request a new context"],"exampleFix":"// before\nawait DumpDataAsync(texture, dumpOptions);\n// after\nif (!ThinEngine.IsSupported) {\n  console.warn('WebGL unavailable; skipping dump');\n} else {\n  await DumpDataAsync(texture, dumpOptions);\n}","handlingStrategy":"try-catch","validationCode":"const { ThinEngine } = await import('../Engines/thinEngine.pure');\nif (!ThinEngine.IsSupported) {\n  throw new Error('WebGL is not available in this environment; dump tools cannot run');\n}","typeGuard":"function webglAvailable(): boolean {\n  try {\n    const c = document.createElement('canvas');\n    return !!(c.getContext('webgl2') || c.getContext('webgl'));\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  await DumpDataAsync(target, options);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('No WebGL context available')) {\n    console.warn('Skipping dump: WebGL not supported in this environment');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Feature-check WebGL (ThinEngine.IsSupported or canvas.getContext('webgl')) before enabling dump features","In headless CI, launch browsers with software GL (SwiftShader) enabled","Handle WebGL context-loss events and re-check support before re-dumping","Provide a CPU/canvas fallback rendering path when GPU encoding is unavailable"],"tags":["webgl","dump-tools","environment","headless"],"backgroundTag":"webgl-not-supported","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}