Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/small-olives-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb-snapshot': patch
---

Fix: [#1172](https://github.com/rrweb-io/rrweb/issues/1172) don't replace original onload function of Images
3 changes: 2 additions & 1 deletion packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ function serializeElementNode(
const oldValue = image.crossOrigin;
image.crossOrigin = 'anonymous';
const recordInlineImage = () => {
image.removeEventListener('load', recordInlineImage);
try {
canvasService!.width = image.naturalWidth;
canvasService!.height = image.naturalHeight;
Expand All @@ -755,7 +756,7 @@ function serializeElementNode(
};
// The image content may not have finished loading yet.
if (image.complete && image.naturalWidth !== 0) recordInlineImage();
else image.onload = recordInlineImage;
else image.addEventListener('load', recordInlineImage);
}
// media elements
if (tagName === 'audio' || tagName === 'video') {
Expand Down
10 changes: 10 additions & 0 deletions packages/rrweb-snapshot/test/html/picture-with-inline-onload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<img
src="/images/robot.png"
alt="This is a robot"
style="opacity: 0;"
onload="this.style.opacity=1"
/>
</body>
</html>
22 changes: 22 additions & 0 deletions packages/rrweb-snapshot/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,28 @@ iframe.contentDocument.querySelector('center').clientHeight
)) as string;
assert(snapshot.includes('-webkit-background-clip: text;'));
});

it('images with inline onload should work', async () => {
const page: puppeteer.Page = await browser.newPage();

await page.goto(
'http://localhost:3030/html/picture-with-inline-onload.html',
{
waitUntil: 'load',
},
);
await page.waitForSelector('img', { timeout: 1000 });
await page.evaluate(`${code}var snapshot = rrweb.snapshot(document, {
dataURLOptions: { type: "image/webp", quality: 0.8 },
inlineImages: true,
inlineStylesheet: false
})`);
await waitForRAF(page);
const fnName = (await page.evaluate(
'document.querySelector("img").onload.name',
)) as string;
assert(fnName === 'onload');
});
});

describe('iframe integration tests', function (this: ISuite) {
Expand Down