Handle negative ids in rrdom correctly + extra tests (#927)

* inline stylesheets when loaded

* set empty link elements to loaded by default

* Clean up stylesheet manager

* Remove attribute mutation code

* Update packages/rrweb/test/record.test.ts

* Update packages/rrweb/test/record.test.ts

* Update packages/rrweb/test/record.test.ts

* Update packages/rrweb/scripts/repl.js

* Update packages/rrweb/test/record.test.ts

* Update packages/rrweb/src/record/index.ts

* Add todo

* Move require out of time sensitive assert

* Add waitForRAF, its more reliable than waitForTimeout

* Remove flaky tests

* Add recording stylesheets in iframes

* Remove variability from flaky test

* Make test more robust

* Fix naming

* Add test cases for inlineImages

* Add test cases for inlineImages

* Record iframe mutations cross page

* Test: should record images inside iframe with blob url after iframe was reloaded

* Handle negative ids in rrdom correctly

When iframes get inserted they create untracked elements, both on the dom and rrdom side.
Because they are untracked they generate negative numbers when fetching the id from mirror.
This creates a problem when comparing and fetching ids across mirrors.
This commit tries to get away from using negative ids as much as possible in rrdom's comparisons

* Update packages/rrdom/src/diff.ts

Co-authored-by: Yun Feng <yun.feng@anu.edu.au>

* Start unserialized nodes at -2

This way we don't accidentally think of them as mirror misses

* Set unserialized id starting number at -2

* Remove duplication

Co-authored-by: Yun Feng <yun.feng@anu.edu.au>
This commit is contained in:
Justin Halsall
2026-04-01 12:00:00 +08:00
committed by GitHub
parent c405e31e01
commit f07682ea8b
22 changed files with 2064 additions and 193 deletions

View File

@@ -499,6 +499,57 @@ describe('record integration tests', function (this: ISuite) {
assertSnapshot(snapshots);
});
it('should record images with blob url', async () => {
const page: puppeteer.Page = await browser.newPage();
page.on('console', (msg) => console.log(msg.text()));
await page.goto(`${serverURL}/html`);
page.setContent(
getHtml.call(this, 'image-blob-url.html', { inlineImages: true }),
);
await page.waitForResponse(`${serverURL}/html/assets/robot.png`);
await page.waitForSelector('img'); // wait for image to get added
await waitForRAF(page); // wait for image to be captured
const snapshots = await page.evaluate('window.snapshots');
assertSnapshot(snapshots);
});
it('should record images inside iframe with blob url', async () => {
const page: puppeteer.Page = await browser.newPage();
page.on('console', (msg) => console.log(msg.text()));
await page.goto(`${serverURL}/html`);
await page.setContent(
getHtml.call(this, 'frame-image-blob-url.html', { inlineImages: true }),
);
await page.waitForResponse(`${serverURL}/html/assets/robot.png`);
await page.waitForTimeout(50); // wait for image to get added
await waitForRAF(page); // wait for image to be captured
const snapshots = await page.evaluate('window.snapshots');
assertSnapshot(snapshots);
});
it('should record images inside iframe with blob url after iframe was reloaded', async () => {
const page: puppeteer.Page = await browser.newPage();
page.on('console', (msg) => console.log(msg.text()));
await page.goto(`${serverURL}/html`);
await page.setContent(
getHtml.call(this, 'frame2.html', { inlineImages: true }),
);
await page.waitForSelector('iframe'); // wait for iframe to get added
await waitForRAF(page); // wait for iframe to load
page.evaluate(() => {
const iframe = document.querySelector('iframe')!;
iframe.setAttribute('src', '/html/image-blob-url.html');
});
await page.waitForResponse(`${serverURL}/html/assets/robot.png`); // wait for image to get loaded
await page.waitForTimeout(50); // wait for image to get added
await waitForRAF(page); // wait for image to be captured
const snapshots = await page.evaluate('window.snapshots');
assertSnapshot(snapshots);
});
it('should record shadow DOM', async () => {
const page: puppeteer.Page = await browser.newPage();
await page.goto('about:blank');
@@ -589,6 +640,34 @@ describe('record integration tests', function (this: ISuite) {
assertSnapshot(snapshots);
});
it('should record mutations in iframes accross pages', async () => {
const page: puppeteer.Page = await browser.newPage();
await page.goto(`${serverURL}/html`);
page.on('console', (msg) => console.log(msg.text()));
await page.setContent(getHtml.call(this, 'frame2.html'));
await page.waitForSelector('iframe'); // wait for iframe to get added
await waitForRAF(page); // wait for iframe to load
page.evaluate((serverURL) => {
const iframe = document.querySelector('iframe')!;
iframe.setAttribute('src', `${serverURL}/html`); // load new page
}, serverURL);
await page.waitForResponse(`${serverURL}/html`); // wait for iframe to load pt1
await waitForRAF(page); // wait for iframe to load pt2
await page.evaluate(() => {
const iframeDocument = document.querySelector('iframe')!.contentDocument!;
const div = iframeDocument.createElement('div');
iframeDocument.body.appendChild(div);
});
await waitForRAF(page); // wait for snapshot to be updated
const snapshots = await page.evaluate('window.snapshots');
assertSnapshot(snapshots);
});
// https://github.com/webcomponents/polyfills/tree/master/packages/shadydom
it('should record shadow doms polyfilled by shadydom', async () => {
const page: puppeteer.Page = await browser.newPage();