From 3f18f91eb01553bd4a48bb6e9fe1b63c57cdbca5 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Fri, 3 May 2024 16:06:33 +0100 Subject: [PATCH 01/13] Setting of `image.crossOrigin` is not necessary for same origin images, and causes an immediate image reload necessitating the load event listener (albeit from cache) --- .../inlineImage-maybeNot-crossOrigin.md | 6 +++++ packages/rrweb-snapshot/src/snapshot.ts | 24 ++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 .changeset/inlineImage-maybeNot-crossOrigin.md diff --git a/.changeset/inlineImage-maybeNot-crossOrigin.md b/.changeset/inlineImage-maybeNot-crossOrigin.md new file mode 100644 index 0000000000..89eb7bb340 --- /dev/null +++ b/.changeset/inlineImage-maybeNot-crossOrigin.md @@ -0,0 +1,6 @@ +--- +"rrweb": patch +"rrweb-snapshot": patch +--- + +inlineImages: during snapshot avoid adding an event listener for inlining of same-origin images (async listener mutates the snapshot which can be problematic) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 81dc2133a0..9d7ccb191c 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -747,8 +747,8 @@ function serializeElementNode( canvasCtx = canvasService.getContext('2d'); } const image = n as HTMLImageElement; - const oldValue = image.crossOrigin; - image.crossOrigin = 'anonymous'; + const imageSrc = image.currentSrc || image.getAttribute('src'); + const priorCrossOrigin = image.crossOrigin; const recordInlineImage = () => { image.removeEventListener('load', recordInlineImage); try { @@ -760,13 +760,21 @@ function serializeElementNode( dataURLOptions.quality, ); } catch (err) { - console.warn( - `Cannot inline img src=${image.currentSrc}! Error: ${err as string}`, - ); + if (image.crossOrigin !== 'anonymous') { + image.crossOrigin = 'anonymous'; + recordInlineImage(); + return; + } else { + console.warn( + `Cannot inline img src=${imageSrc}! Error: ${err as string}`, + ); + } + } + if (image.crossOrigin === 'anonymous') { + priorCrossOrigin + ? (attributes.crossOrigin = priorCrossOrigin) + : image.removeAttribute('crossorigin'); } - oldValue - ? (attributes.crossOrigin = oldValue) - : image.removeAttribute('crossorigin'); }; // The image content may not have finished loading yet. if (image.complete && image.naturalWidth !== 0) recordInlineImage(); From 28175138557702330fa1e215269a37d1263c2c09 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Fri, 3 May 2024 16:44:03 +0100 Subject: [PATCH 02/13] It's good that these mutations are avoided; they were being generated by the snapshotting process --- .../__snapshots__/integration.test.ts.snap | 102 ------------------ 1 file changed, 102 deletions(-) diff --git a/packages/rrweb/test/__snapshots__/integration.test.ts.snap b/packages/rrweb/test/__snapshots__/integration.test.ts.snap index f349bd2669..1572b675b6 100644 --- a/packages/rrweb/test/__snapshots__/integration.test.ts.snap +++ b/packages/rrweb/test/__snapshots__/integration.test.ts.snap @@ -12777,40 +12777,6 @@ exports[`record integration tests should record images inside iframe with blob u } ] } - }, - { - \\"type\\": 3, - \\"data\\": { - \\"source\\": 0, - \\"texts\\": [], - \\"attributes\\": [ - { - \\"id\\": 41, - \\"attributes\\": { - \\"crossorigin\\": \\"anonymous\\" - } - } - ], - \\"removes\\": [], - \\"adds\\": [] - } - }, - { - \\"type\\": 3, - \\"data\\": { - \\"source\\": 0, - \\"texts\\": [], - \\"attributes\\": [ - { - \\"id\\": 41, - \\"attributes\\": { - \\"crossorigin\\": null - } - } - ], - \\"removes\\": [], - \\"adds\\": [] - } } ]" `; @@ -13245,40 +13211,6 @@ exports[`record integration tests should record images inside iframe with blob u } ] } - }, - { - \\"type\\": 3, - \\"data\\": { - \\"source\\": 0, - \\"texts\\": [], - \\"attributes\\": [ - { - \\"id\\": 47, - \\"attributes\\": { - \\"crossorigin\\": \\"anonymous\\" - } - } - ], - \\"removes\\": [], - \\"adds\\": [] - } - }, - { - \\"type\\": 3, - \\"data\\": { - \\"source\\": 0, - \\"texts\\": [], - \\"attributes\\": [ - { - \\"id\\": 47, - \\"attributes\\": { - \\"crossorigin\\": null - } - } - ], - \\"removes\\": [], - \\"adds\\": [] - } } ]" `; @@ -13486,40 +13418,6 @@ exports[`record integration tests should record images with blob url 1`] = ` } ] } - }, - { - \\"type\\": 3, - \\"data\\": { - \\"source\\": 0, - \\"texts\\": [], - \\"attributes\\": [ - { - \\"id\\": 24, - \\"attributes\\": { - \\"crossorigin\\": \\"anonymous\\" - } - } - ], - \\"removes\\": [], - \\"adds\\": [] - } - }, - { - \\"type\\": 3, - \\"data\\": { - \\"source\\": 0, - \\"texts\\": [], - \\"attributes\\": [ - { - \\"id\\": 24, - \\"attributes\\": { - \\"crossorigin\\": null - } - } - ], - \\"removes\\": [], - \\"adds\\": [] - } } ]" `; From d6e4fffc5cdc3cd96879e63ffc62ad1371d4bb7d Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Fri, 3 May 2024 16:56:06 +0100 Subject: [PATCH 03/13] Fixup typings --- packages/rrweb-snapshot/src/snapshot.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 9d7ccb191c..691252a57d 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -747,7 +747,7 @@ function serializeElementNode( canvasCtx = canvasService.getContext('2d'); } const image = n as HTMLImageElement; - const imageSrc = image.currentSrc || image.getAttribute('src'); + const imageSrc: string = image.currentSrc || image.getAttribute('src') || ''; const priorCrossOrigin = image.crossOrigin; const recordInlineImage = () => { image.removeEventListener('load', recordInlineImage); From 29354acf8f77641becee2237d9ea6e24f4480f5b Mon Sep 17 00:00:00 2001 From: eoghanmurray Date: Fri, 3 May 2024 15:57:09 +0000 Subject: [PATCH 04/13] Apply formatting changes --- packages/rrweb-snapshot/src/snapshot.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 691252a57d..7021be26d5 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -747,7 +747,8 @@ function serializeElementNode( canvasCtx = canvasService.getContext('2d'); } const image = n as HTMLImageElement; - const imageSrc: string = image.currentSrc || image.getAttribute('src') || ''; + const imageSrc: string = + image.currentSrc || image.getAttribute('src') || ''; const priorCrossOrigin = image.crossOrigin; const recordInlineImage = () => { image.removeEventListener('load', recordInlineImage); From 42f3ed8662c6cd3b7a18a8c0dfa54d2d6d4f5eca Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Wed, 8 May 2024 16:00:47 +0100 Subject: [PATCH 05/13] Improve jest/expect in picture test --- .../rrweb-snapshot/test/html/picture.html | 1 + .../rrweb-snapshot/test/integration.test.ts | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/rrweb-snapshot/test/html/picture.html b/packages/rrweb-snapshot/test/html/picture.html index e005310b77..2401ca0c61 100644 --- a/packages/rrweb-snapshot/test/html/picture.html +++ b/packages/rrweb-snapshot/test/html/picture.html @@ -1,6 +1,7 @@ + diff --git a/packages/rrweb-snapshot/test/integration.test.ts b/packages/rrweb-snapshot/test/integration.test.ts index dcc6a3ec0b..01c28d71ba 100644 --- a/packages/rrweb-snapshot/test/integration.test.ts +++ b/packages/rrweb-snapshot/test/integration.test.ts @@ -210,11 +210,31 @@ iframe.contentDocument.querySelector('center').clientHeight inlineStylesheet: false })`); await waitForRAF(page); - const snapshot = (await page.evaluate( - 'JSON.stringify(snapshot, null, 2);', - )) as string; - assert(snapshot.includes('"rr_dataURL"')); - assert(snapshot.includes('data:image/webp;base64,')); + const flat = (await page.evaluate(` + let flat = []; + function flatten(root) { + flat.push(root); + if (!root.childNodes) return; + for (let cn of root.childNodes) { + flatten(cn); + } + delete root.childNodes; + } + flatten(snapshot); + flat; +`)) as any[]; + expect(flat).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + tagName: 'img', + attributes: { + src: expect.stringMatching(/images\/robot.png$/), + alt: 'This is a robot', + rr_dataURL: expect.stringMatching(/^data:image\/webp;base64,/), + }, + }), + ]), + ); }); it('correctly saves blob:images offline', async () => { From 0277f436aa79890241ea86d18cff95f682e72280 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Wed, 8 May 2024 16:14:31 +0100 Subject: [PATCH 06/13] Add a test for using the `image.crossOrigin = 'anonymous';` hack --- packages/rrweb-snapshot/test/html/picture.html | 1 + packages/rrweb-snapshot/test/integration.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/packages/rrweb-snapshot/test/html/picture.html b/packages/rrweb-snapshot/test/html/picture.html index 2401ca0c61..3d59df428b 100644 --- a/packages/rrweb-snapshot/test/html/picture.html +++ b/packages/rrweb-snapshot/test/html/picture.html @@ -6,5 +6,6 @@ This is a robot + CORS restricted but has access-control-allow-origin: * diff --git a/packages/rrweb-snapshot/test/integration.test.ts b/packages/rrweb-snapshot/test/integration.test.ts index 01c28d71ba..b4695e519a 100644 --- a/packages/rrweb-snapshot/test/integration.test.ts +++ b/packages/rrweb-snapshot/test/integration.test.ts @@ -233,6 +233,14 @@ iframe.contentDocument.querySelector('center').clientHeight rr_dataURL: expect.stringMatching(/^data:image\/webp;base64,/), }, }), + expect.objectContaining({ + tagName: 'img', + attributes: { + src: 'https://avatars.githubusercontent.com/u/43396833?s=20&v=4', + alt: 'CORS restricted but has access-control-allow-origin: *', + rr_dataURL: expect.stringMatching(/^data:image\/webp;base64,/), + }, + }), ]), ); }); From f0cca66c6ca3ea2b8d6c471ecb70ef96fef86e6b Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Wed, 8 May 2024 16:32:43 +0100 Subject: [PATCH 07/13] Bugfix: after the crossOrigin change we always need to listen for the load, as calling `recordInlineImage` immediately will result in an empty data url --- packages/rrweb-snapshot/src/snapshot.ts | 2 +- packages/rrweb-snapshot/test/integration.test.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 7021be26d5..b392740c23 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -763,7 +763,7 @@ function serializeElementNode( } catch (err) { if (image.crossOrigin !== 'anonymous') { image.crossOrigin = 'anonymous'; - recordInlineImage(); + image.addEventListener('load', recordInlineImage); return; } else { console.warn( diff --git a/packages/rrweb-snapshot/test/integration.test.ts b/packages/rrweb-snapshot/test/integration.test.ts index b4695e519a..ddbf599d2f 100644 --- a/packages/rrweb-snapshot/test/integration.test.ts +++ b/packages/rrweb-snapshot/test/integration.test.ts @@ -7,6 +7,7 @@ import * as rollup from 'rollup'; import * as typescript from 'rollup-plugin-typescript2'; import * as assert from 'assert'; import { waitForRAF } from './utils'; +import { setTimeout } from 'node:timers/promises'; const _typescript = typescript as unknown as () => rollup.Plugin; @@ -209,7 +210,7 @@ iframe.contentDocument.querySelector('center').clientHeight inlineImages: true, inlineStylesheet: false })`); - await waitForRAF(page); + await setTimeout(20); // need a small wait, as after the crossOrigin="anonymous" change, the snapshot triggers a reload of the image (which mutates the snapshot when loaded) const flat = (await page.evaluate(` let flat = []; function flatten(root) { From afd72341531856ec870f8d953bf330e6275a52f7 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Wed, 8 May 2024 17:05:34 +0100 Subject: [PATCH 08/13] Improve how test failures look; flatten was overkill --- .../rrweb-snapshot/test/integration.test.ts | 52 ++++++++----------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/packages/rrweb-snapshot/test/integration.test.ts b/packages/rrweb-snapshot/test/integration.test.ts index ddbf599d2f..131da355aa 100644 --- a/packages/rrweb-snapshot/test/integration.test.ts +++ b/packages/rrweb-snapshot/test/integration.test.ts @@ -211,38 +211,28 @@ iframe.contentDocument.querySelector('center').clientHeight inlineStylesheet: false })`); await setTimeout(20); // need a small wait, as after the crossOrigin="anonymous" change, the snapshot triggers a reload of the image (which mutates the snapshot when loaded) - const flat = (await page.evaluate(` - let flat = []; - function flatten(root) { - flat.push(root); - if (!root.childNodes) return; - for (let cn of root.childNodes) { - flatten(cn); - } - delete root.childNodes; - } - flatten(snapshot); - flat; + const bodyChildren = (await page.evaluate(` + snapshot.childNodes[0].childNodes[1].childNodes.filter((cn) => cn.type === 2); `)) as any[]; - expect(flat).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - tagName: 'img', - attributes: { - src: expect.stringMatching(/images\/robot.png$/), - alt: 'This is a robot', - rr_dataURL: expect.stringMatching(/^data:image\/webp;base64,/), - }, - }), - expect.objectContaining({ - tagName: 'img', - attributes: { - src: 'https://avatars.githubusercontent.com/u/43396833?s=20&v=4', - alt: 'CORS restricted but has access-control-allow-origin: *', - rr_dataURL: expect.stringMatching(/^data:image\/webp;base64,/), - }, - }), - ]), + expect(bodyChildren[1]).toEqual( + expect.objectContaining({ + tagName: 'img', + attributes: { + src: expect.stringMatching(/images\/robot.png$/), + alt: 'This is a robot', + rr_dataURL: expect.stringMatching(/^data:image\/webp;base64,/), + }, + }), + ); + expect(bodyChildren[2]).toEqual( + expect.objectContaining({ + tagName: 'img', + attributes: { + src: 'https://avatars.githubusercontent.com/u/43396833?s=20&v=4', + alt: 'CORS restricted but has access-control-allow-origin: *', + rr_dataURL: expect.stringMatching(/^data:image\/webp;base64,/), + }, + }), ); }); From 2e466e793ff9251566e8147c66ec4ee8ec7a48cb Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Thu, 9 May 2024 18:35:03 +0100 Subject: [PATCH 09/13] Repeat image.complete check for completeness --- packages/rrweb-snapshot/src/snapshot.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index b392740c23..5a2eaa745b 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -763,7 +763,9 @@ function serializeElementNode( } catch (err) { if (image.crossOrigin !== 'anonymous') { image.crossOrigin = 'anonymous'; - image.addEventListener('load', recordInlineImage); + if (image.complete && image.naturalWidth !== 0) + recordInlineImage(); // too early due to image reload + else image.addEventListener('load', recordInlineImage); return; } else { console.warn( From c9d6a65063206843ea9b532c1910440058294b8f Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Mon, 13 May 2024 12:46:26 +0100 Subject: [PATCH 10/13] Didn't notice that the picture.html used in 'correctly saves images offline' is also separately checked against a __snapshot__ --- .../rrweb-snapshot/test/__snapshots__/integration.test.ts.snap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/rrweb-snapshot/test/__snapshots__/integration.test.ts.snap b/packages/rrweb-snapshot/test/__snapshots__/integration.test.ts.snap index 39c8c49ee1..1abf3f40fa 100644 --- a/packages/rrweb-snapshot/test/__snapshots__/integration.test.ts.snap +++ b/packages/rrweb-snapshot/test/__snapshots__/integration.test.ts.snap @@ -338,10 +338,12 @@ exports[`integration tests [html file]: mask-text.html 1`] = ` exports[`integration tests [html file]: picture.html 1`] = ` " + \\"This + \\"CORS " `; From f8cbf9c978430b41894bcae4b1f59535ab86c71f Mon Sep 17 00:00:00 2001 From: Justin Halsall Date: Wed, 22 May 2024 13:14:25 +0100 Subject: [PATCH 11/13] Update packages/rrweb-snapshot/test/integration.test.ts --- packages/rrweb-snapshot/test/integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rrweb-snapshot/test/integration.test.ts b/packages/rrweb-snapshot/test/integration.test.ts index 131da355aa..cd6cdbdcdb 100644 --- a/packages/rrweb-snapshot/test/integration.test.ts +++ b/packages/rrweb-snapshot/test/integration.test.ts @@ -210,7 +210,7 @@ iframe.contentDocument.querySelector('center').clientHeight inlineImages: true, inlineStylesheet: false })`); - await setTimeout(20); // need a small wait, as after the crossOrigin="anonymous" change, the snapshot triggers a reload of the image (which mutates the snapshot when loaded) + await waitForRAF(page); // need a small wait, as after the crossOrigin="anonymous" change, the snapshot triggers a reload of the image (which mutates the snapshot when loaded) const bodyChildren = (await page.evaluate(` snapshot.childNodes[0].childNodes[1].childNodes.filter((cn) => cn.type === 2); `)) as any[]; From d2df9bb673a13e5c78969b566c1d3b6161609fff Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Thu, 23 May 2024 09:57:33 +0100 Subject: [PATCH 12/13] Don't rely on a 3rd party url (or internet access) in the new cross-origin test --- .../__snapshots__/integration.test.ts.snap | 1 - .../rrweb-snapshot/test/html/picture.html | 1 - .../test/images/rrweb-favicon-20x20.png | Bin 0 -> 487 bytes .../rrweb-snapshot/test/integration.test.ts | 41 ++++++++++++++++-- packages/rrweb-snapshot/test/utils.ts | 10 +++++ 5 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 packages/rrweb-snapshot/test/images/rrweb-favicon-20x20.png diff --git a/packages/rrweb-snapshot/test/__snapshots__/integration.test.ts.snap b/packages/rrweb-snapshot/test/__snapshots__/integration.test.ts.snap index 1abf3f40fa..e95a718645 100644 --- a/packages/rrweb-snapshot/test/__snapshots__/integration.test.ts.snap +++ b/packages/rrweb-snapshot/test/__snapshots__/integration.test.ts.snap @@ -343,7 +343,6 @@ exports[`integration tests [html file]: picture.html 1`] = ` \\"This - \\"CORS " `; diff --git a/packages/rrweb-snapshot/test/html/picture.html b/packages/rrweb-snapshot/test/html/picture.html index 3d59df428b..2401ca0c61 100644 --- a/packages/rrweb-snapshot/test/html/picture.html +++ b/packages/rrweb-snapshot/test/html/picture.html @@ -6,6 +6,5 @@ This is a robot - CORS restricted but has access-control-allow-origin: * diff --git a/packages/rrweb-snapshot/test/images/rrweb-favicon-20x20.png b/packages/rrweb-snapshot/test/images/rrweb-favicon-20x20.png new file mode 100644 index 0000000000000000000000000000000000000000..561f9060d74151fc13e569295262908a9814c3ca GIT binary patch literal 487 zcmVdCqgrkpYYV5QE;k^z9gCZ=z3GmZ2yL^KZ8suGj1T z0JGUFg25p3B}szGWWwcgL9JH9VzJ=na4CmEA%w%>AF=cKjLBqz&1QpEtA#?LfYoaC zT7|J#41>V{`~ChAv)OEj$KyC04#;FOD3wY`r_UO)$D!nVM z8}M%QFi`4=L;}TP5vr={1Ke)6>qm_G!{LyrJ)KVB_xt&*jJ}7uSML?T4+HT= dp8)^>|Nnex$5i}|dhh@M002ovPDHLkV1i4G? rollup.Plugin; @@ -210,7 +210,7 @@ iframe.contentDocument.querySelector('center').clientHeight inlineImages: true, inlineStylesheet: false })`); - await waitForRAF(page); // need a small wait, as after the crossOrigin="anonymous" change, the snapshot triggers a reload of the image (which mutates the snapshot when loaded) + // don't wait, as we want to ensure that the same-origin image can be inlined immediately const bodyChildren = (await page.evaluate(` snapshot.childNodes[0].childNodes[1].childNodes.filter((cn) => cn.type === 2); `)) as any[]; @@ -224,11 +224,44 @@ iframe.contentDocument.querySelector('center').clientHeight }, }), ); - expect(bodyChildren[2]).toEqual( + }); + + it('correctly saves cross-origin images offline', async () => { + const page: puppeteer.Page = await browser.newPage(); + + await page.goto('about:blank', { + waitUntil: 'load', + }); + await page.setContent( + ` + + + CORS restricted but has access-control-allow-origin: * + + +`, + { + 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); // need a small wait, as after the crossOrigin="anonymous" change, the snapshot triggers a reload of the image (after which, the snapshot is mutated) + const bodyChildren = (await page.evaluate(` + snapshot.childNodes[0].childNodes[1].childNodes.filter((cn) => cn.type === 2); +`)) as any[]; + expect(bodyChildren[0]).toEqual( expect.objectContaining({ tagName: 'img', attributes: { - src: 'https://avatars.githubusercontent.com/u/43396833?s=20&v=4', + src: getServerURL(server) + '/images/rrweb-favicon-20x20.png', alt: 'CORS restricted but has access-control-allow-origin: *', rr_dataURL: expect.stringMatching(/^data:image\/webp;base64,/), }, diff --git a/packages/rrweb-snapshot/test/utils.ts b/packages/rrweb-snapshot/test/utils.ts index 43d4484bb4..631f8640a6 100644 --- a/packages/rrweb-snapshot/test/utils.ts +++ b/packages/rrweb-snapshot/test/utils.ts @@ -1,4 +1,5 @@ import * as puppeteer from 'puppeteer'; +import * as http from 'http'; export async function waitForRAF(page: puppeteer.Page) { return await page.evaluate(() => { @@ -9,3 +10,12 @@ export async function waitForRAF(page: puppeteer.Page) { }); }); } + +export function getServerURL(server: http.Server): string { + const address = server.address(); + if (address && typeof address !== 'string') { + return `http://localhost:${address.port}`; + } else { + return `${address}`; + } +} From ba7ca2d254330ba7ea5fc0d2930188dd5ec4e1b0 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Thu, 23 May 2024 10:01:41 +0100 Subject: [PATCH 13/13] fixup! Update packages/rrweb-snapshot/test/integration.test.ts --- packages/rrweb-snapshot/test/integration.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/rrweb-snapshot/test/integration.test.ts b/packages/rrweb-snapshot/test/integration.test.ts index 05f61787b0..f212b0fd4c 100644 --- a/packages/rrweb-snapshot/test/integration.test.ts +++ b/packages/rrweb-snapshot/test/integration.test.ts @@ -7,7 +7,6 @@ import * as rollup from 'rollup'; import * as typescript from 'rollup-plugin-typescript2'; import * as assert from 'assert'; import { waitForRAF, getServerURL } from './utils'; -import { setTimeout } from 'node:timers/promises'; const _typescript = typescript as unknown as () => rollup.Plugin;