Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Fix for issue with inlineImages causing images to reload and never be…
Browse files Browse the repository at this point in the history
… inlined. See rrweb-io#1218
  • Loading branch information
econte-sprig committed May 2, 2023
1 parent 0fedb8e commit 4cf2b1b
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,10 +744,8 @@ function serializeElementNode(
canvasCtx = canvasService.getContext('2d');
}
const image = n as HTMLImageElement;
const oldValue = image.crossOrigin;
image.crossOrigin = 'anonymous';
const recordInlineImage = () => {
image.removeEventListener('load', recordInlineImage);
// The image content may not have finished loading yet.
if (image.complete && image.naturalWidth !== 0) {
try {
canvasService!.width = image.naturalWidth;
canvasService!.height = image.naturalHeight;
Expand All @@ -761,13 +759,7 @@ 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') {
Expand Down

0 comments on commit 4cf2b1b

Please sign in to comment.