From d860a4b5338385254d316ad5d82ac10f681de40d Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Fri, 15 Mar 2024 14:55:14 +0100 Subject: [PATCH] code review --- .../src/record/observers/canvas/canvas-manager.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/rrweb/src/record/observers/canvas/canvas-manager.ts b/packages/rrweb/src/record/observers/canvas/canvas-manager.ts index d46cf89a6a..d4c1f06a42 100644 --- a/packages/rrweb/src/record/observers/canvas/canvas-manager.ts +++ b/packages/rrweb/src/record/observers/canvas/canvas-manager.ts @@ -184,6 +184,12 @@ export class CanvasManager { .forEach(async (canvas: HTMLCanvasElement) => { const id = this.mirror.getId(canvas); if (snapshotInProgressMap.get(id)) return; + + // The browser throws if the canvas is 0 in size + // Uncaught (in promise) DOMException: Failed to execute 'createImageBitmap' on 'Window': The source image width is 0. + // Assuming the same happens with height + if (canvas.width === 0 || canvas.height === 0) return; + snapshotInProgressMap.set(id, true); if (['webgl', 'webgl2'].includes((canvas as ICanvas).__context)) { // if the canvas hasn't been modified recently, @@ -208,11 +214,6 @@ export class CanvasManager { } } - // The browser throws if the canvas is 0 in size - // Uncaught (in promise) DOMException: Failed to execute 'createImageBitmap' on 'Window': The source image width is 0. - // Assuming the same happens with height - if (canvas.width === 0 || canvas.height === 0) return; - const bitmap = await createImageBitmap(canvas); worker.postMessage( {