diff --git a/packages/rrweb-snapshot/src/index.ts b/packages/rrweb-snapshot/src/index.ts index c9f91a9100..1ca918cdee 100644 --- a/packages/rrweb-snapshot/src/index.ts +++ b/packages/rrweb-snapshot/src/index.ts @@ -8,6 +8,7 @@ import snapshot, { classMatchesRegex, IGNORED_NODE, genId, + absoluteToDoc, } from './snapshot'; import rebuild, { buildNodeWithSN, @@ -32,4 +33,5 @@ export { classMatchesRegex, IGNORED_NODE, genId, + absoluteToDoc, }; diff --git a/packages/rrweb-snapshot/test/integration.test.ts b/packages/rrweb-snapshot/test/integration.test.ts index dcc6a3ec0b..103586fec2 100644 --- a/packages/rrweb-snapshot/test/integration.test.ts +++ b/packages/rrweb-snapshot/test/integration.test.ts @@ -287,6 +287,30 @@ iframe.contentDocument.querySelector('center').clientHeight assert(snapshot.includes('data:image/webp;base64,')); }); + it('correctly deals with changes in window.history', async () => { + const page: puppeteer.Page = await browser.newPage(); + + await page.goto('http://localhost:3030/html/basic.html', { + waitUntil: 'load', + }); + await waitForRAF(page); // wait for page to render + await page.evaluate(`${code} + window.val1 = rrweb.absoluteToDoc(document, './rel'); + window.history.replaceState({}, null, window.document.location.href + '/artificial/'); + window.val2 = rrweb.absoluteToDoc(document, './rel'); + `); + await waitForRAF(page); + const snapshot = (await page.evaluate( + 'JSON.stringify(window.snapshot, null, 2);', + )) as string; + expect((await page.evaluate('window.val1')) as string).toEqual( + 'http://localhost:3030/html/rel', + ); + expect((await page.evaluate('window.val2')) as string).toEqual( + 'http://localhost:3030/html/basic.html/artificial/rel', + ); + }); + it('should save background-clip: text; as the more compatible -webkit-background-clip: test;', async () => { const page: puppeteer.Page = await browser.newPage(); await page.goto(`http://localhost:3030/html/background-clip-text.html`, {