From 3aaf62f31641e39a8680049751302e5a82871ecc Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Fri, 5 Apr 2024 13:42:34 +0100 Subject: [PATCH 1/2] Add `absoluteToDoc` test in the presence of a window.history change --- packages/rrweb-snapshot/src/index.ts | 2 ++ .../rrweb-snapshot/test/integration.test.ts | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) 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..8398344146 100644 --- a/packages/rrweb-snapshot/test/integration.test.ts +++ b/packages/rrweb-snapshot/test/integration.test.ts @@ -287,6 +287,26 @@ 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`, { From 00901cba3e4b5fd4a30eeb36a7ff794ea2fb5d32 Mon Sep 17 00:00:00 2001 From: eoghanmurray Date: Thu, 2 May 2024 12:49:11 +0000 Subject: [PATCH 2/2] Apply formatting changes --- packages/rrweb-snapshot/test/integration.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/rrweb-snapshot/test/integration.test.ts b/packages/rrweb-snapshot/test/integration.test.ts index 8398344146..103586fec2 100644 --- a/packages/rrweb-snapshot/test/integration.test.ts +++ b/packages/rrweb-snapshot/test/integration.test.ts @@ -303,8 +303,12 @@ iframe.contentDocument.querySelector('center').clientHeight 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'); + 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 () => {