From 936a4225cdde4837c4ca9554a81e3b292fc558b2 Mon Sep 17 00:00:00 2001 From: Elliot Conte Date: Tue, 9 May 2023 04:21:50 -0400 Subject: [PATCH] Revert "Fix for issue with inlineImages causing images to reload and never be inlined. See https://github.com/rrweb-io/rrweb/issues/1218" This reverts commit 4cf2b1bdec09fe8b579ecc778ec367c4583172d9. --- packages/rrweb-snapshot/src/snapshot.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 826793f1ce..0eeb289b4f 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -744,8 +744,10 @@ function serializeElementNode( canvasCtx = canvasService.getContext('2d'); } const image = n as HTMLImageElement; - // The image content may not have finished loading yet. - if (image.complete && image.naturalWidth !== 0) { + const oldValue = image.crossOrigin; + image.crossOrigin = 'anonymous'; + const recordInlineImage = () => { + image.removeEventListener('load', recordInlineImage); try { canvasService!.width = image.naturalWidth; canvasService!.height = image.naturalHeight; @@ -759,7 +761,13 @@ function serializeElementNode( `Cannot inline img src=${image.currentSrc}! Error: ${err as string}`, ); } - } + oldValue + ? (attributes.crossOrigin = oldValue) + : image.removeAttribute('crossorigin'); + }; + // The image content may not have finished loading yet. + if (image.complete && image.naturalWidth !== 0) recordInlineImage(); + else image.addEventListener('load', recordInlineImage); } // media elements if (tagName === 'audio' || tagName === 'video') {