{"record":{"id":"5e5178a932a78e7b","repo":"BabylonJS/Babylon.js","slug":"offscreencanvas-not-supported-cannot-create-play","errorCode":null,"errorMessage":"OffscreenCanvas not supported - cannot create Player","messagePattern":"OffscreenCanvas not supported - cannot create Player","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/lottiePlayer/src/player.ts","lineNumber":55,"sourceCode":"    private _preWarmReject: ((reason?: any) => void) | null = null;\r\n    private _worker: Nullable<globalThis.Worker> = null;\r\n    private _canvas: Nullable<HTMLCanvasElement> = null;\r\n    private _animationWidth: number = 0;\r\n    private _animationHeight: number = 0;\r\n    private _scaleFactors: ScaleFactors = { canvasScale: 1 };\r\n    private _resizeObserver: Nullable<ResizeObserver> = null;\r\n    private _resizeDebounceHandle: number | null = null;\r\n    private _resizeDebounceMs: number = 1000 / 60; // Debounce resize updates to approximately 60 FPS\r\n\r\n    /**\r\n     * Creates a new instance of the LottiePlayer.\r\n     * If OffscreenCanvas is not supported by the browser, the animation will not play. Try using LocalLottiePlayer instead.\r\n     * @throws Error if OffscreenCanvas is not supported\r\n     */\r\n    public constructor() {\r\n        // Check if OffscreenCanvas is supported\r\n        if (!(\"OffscreenCanvas\" in window)) {\r\n            throw new Error(\"OffscreenCanvas not supported - cannot create Player\");\r\n        }\r\n    }\r\n\r\n    /**\r\n     * Pre-warms the worker and base renderer code. Animation-specific text or image renderer chunks\r\n     * load later, after the animation data is known.\r\n     * @returns A Promise that resolves to this Player instance when the worker is ready\r\n     * @throws Error if the player is already playing or disposed\r\n     */\r\n    public async preWarmPlayerAsync(): Promise<Player> {\r\n        if (this._playing || this._disposed) {\r\n            throw new Error(\"Invalid call to preWarmPlayerAsync - player is already playing or disposed\");\r\n        }\r\n\r\n        if (this._preWarmed) {\r\n            return this;\r\n        }\r\n\r","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/lottiePlayer/src/player.ts#L37-L73","documentation":"The WorkerLottiePlayer (Player) constructor throws immediately if the browser lacks OffscreenCanvas support, because the player renders on a worker using OffscreenCanvas. The class docs direct you to LocalLottiePlayer in that case.","triggerScenarios":"Constructing the worker-based Player in browsers without OffscreenCanvas (older Safari/Firefox, some WebViews, non-browser environments lacking `window`).","commonSituations":"Legacy Safari (<16.4-ish) or Firefox (<105) users; embedded WebViews (older iOS WKWebView configs); SSR/unit-test environments without OffscreenCanvas.","solutions":["Use LocalLottiePlayer instead when OffscreenCanvas is unavailable","Feature-detect `\"OffscreenCanvas\" in window` before constructing and branch player choice","Drop a runtime polyfill is not viable — instead target modern browsers or fall back to the main-thread renderer"],"exampleFix":"// before\nconst player = new Player();\n// after\nconst player = \"OffscreenCanvas\" in window ? new Player() : new LocalLottiePlayer();","handlingStrategy":"fallback","validationCode":"if (!(\"OffscreenCanvas\" in window)) {\n  player = new LocalLottiePlayer();\n} else {\n  player = new Player();\n}","typeGuard":"function supportsOffscreenCanvas(w: Window): w is Window & { OffscreenCanvas: typeof OffscreenCanvas } {\n  return \"OffscreenCanvas\" in w;\n}","tryCatchPattern":"let player;\ntry {\n  player = new Player();\n} catch (e) {\n  if (e.message.includes('OffscreenCanvas not supported')) {\n    player = new LocalLottiePlayer();\n  } else throw e;\n}","preventionTips":["Feature-detect OffscreenCanvas before choosing the worker player","Document browser support requirements (modern Chrome/Edge/Safari/Firefox)","Test in target WebViews; default to LocalLottiePlayer there"],"tags":["browser-compatibility","offscreen-canvas","lottie"],"backgroundTag":"unsupported-browser-feature","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}