Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upstream: Merge upstream commits up to 609b7fac79a552f746dc880a28927dee382cd082 #220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
81c54ab
Version Packages (alpha) (#1453)
github-actions[bot] May 22, 2024
4014305
inlineImages: Setting of `image.crossOrigin` is not always necessary …
eoghanmurray May 23, 2024
d7cf8dd
Return early for child same origin frames (#1295)
colingm May 29, 2024
f3cf092
Removing global document references (#1482)
AlfieJones Jun 4, 2024
82f6fec
No neg lookbehind (#1493)
eoghanmurray Jun 5, 2024
d38893f
Refactor to preclude the need for a continuous raf loop (#1328)
eoghanmurray Jun 5, 2024
609b7fa
perf(mutation): refactor parent removed detection to iterative proced…
JonasBa Jun 5, 2024
674c486
Merge commit '81c54abab2c786a8c58d3394d0a008571a5f9f07' into develop-…
billyvg Sep 18, 2024
b6f586a
Merge commit '40143059446cee5c042c007b1c2e976f36e172f5' into develop-…
billyvg Sep 18, 2024
35be41e
Merge commit 'd7cf8dd07547f6fb22ef82e341a88357c4053bd3' into develop-…
billyvg Sep 18, 2024
fb97970
Merge commit 'f3cf0928df30d5ed5c0d573c524be6e744c0f8d3' into develop-…
billyvg Sep 18, 2024
6ff1d39
Merge commit '82f6fecf36413ecbc994a510144487f1de20d1d5' into develop-…
billyvg Sep 18, 2024
567d281
Merge commit 'd38893f6338facf331fd1f6e63c121120b81177d' into develop-…
billyvg Sep 18, 2024
2aeb348
Merge commit '609b7fac79a552f746dc880a28927dee382cd082' into develop-…
billyvg Sep 18, 2024
48c44e5
Apply formatting changes
billyvg Sep 18, 2024
8862588
ci: fire CI after auto-formatting
billyvg Sep 18, 2024
febd76e
upstream: Merge upstream commits up to 609b7fac79a552f746dc880a28927d…
billyvg Sep 18, 2024
a5d24b4
Merge commit 'febd76ed13932cf68871d5adb63c1acbdc11afa1' into sentry-v…
billyvg Sep 18, 2024
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
6 changes: 6 additions & 0 deletions .changeset/inlineImage-maybeNot-crossOrigin.md
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions .changeset/kind-kids-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rrweb": patch
---

Optimize performance of isParentRemoved by converting it to an iterative procedure
6 changes: 6 additions & 0 deletions .changeset/no-neg-lookbehind.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"rrweb-snapshot": patch
"rrweb": patch
---

Replay: Replace negative lookbehind in regexes from css parser as it causes issues with Safari 16
9 changes: 9 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@
"cool-grapes-hug",
"cuddly-readers-warn",
"curvy-apples-lay",
"curvy-balloons-brake",
"date-now-guard",
"dirty-rules-dress",
"eight-terms-hunt",
"eleven-bobcats-peel",
"empty-bikes-cheer",
"event-single-wrap",
"fair-dragons-greet",
"fair-ducks-clean",
"fast-chefs-smell",
"fast-pets-exist",
"few-rockets-travel",
"few-turkeys-reflect",
"five-peas-lay",
"fluffy-planes-retire",
"format-head-prettier",
"forty-elephants-attack",
"fresh-cars-impress",
"fresh-spoons-drive",
Expand All @@ -45,6 +51,7 @@
"gold-terms-look",
"grumpy-ways-own",
"hip-worms-relax",
"hungry-dodos-taste",
"itchy-dryers-double",
"khaki-dots-bathe",
"large-ants-prove",
Expand All @@ -61,8 +68,10 @@
"mighty-ads-worry",
"mighty-bulldogs-begin",
"mighty-frogs-sparkle",
"modern-doors-watch",
"moody-dots-refuse",
"nervous-buses-pump",
"nervous-kiwis-nail",
"nervous-mirrors-perform",
"nervous-poets-grin",
"nervous-tables-travel",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/proud-clocks-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rrweb-snapshot": patch
---

(when `recordCanvas: true`): ensure we use doc.createElement instead of document.createElement to allow use in non-browser e.g. jsdom environments
5 changes: 5 additions & 0 deletions .changeset/shadow-dom-unbusify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rrweb": patch
---

Refactor to preclude the need for a continuous raf loop running in the background which is related to shadowDom
5 changes: 5 additions & 0 deletions .changeset/silent-plants-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rrweb": patch
---

Return early for child same origin frames
8 changes: 8 additions & 0 deletions packages/rrdom-nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# rrdom-nodejs

## 2.0.0-alpha.14

### Patch Changes

- Updated dependencies [[`03b5216`](https://github.com/rrweb-io/rrweb/commit/03b5216a9403f1509b4f69d1d71ef9874277fe91), [`46f1b25`](https://github.com/rrweb-io/rrweb/commit/46f1b252a5919c68c68e825bd6089cc2e7d34e7c), [`cbbd1e5`](https://github.com/rrweb-io/rrweb/commit/cbbd1e55f1f7fa2eed9fa11e4152b509bdfd88f7), [`5e7943d`](https://github.com/rrweb-io/rrweb/commit/5e7943dbae6e2cde76c484bdd26bc0b96f1b6dce), [`c0f83af`](https://github.com/rrweb-io/rrweb/commit/c0f83afab8f1565633de0e986b7e96fa56f2d25c), [`e96f668`](https://github.com/rrweb-io/rrweb/commit/e96f668c86bd0ab5dc190bb2957a170271bb2ebc)]:
- [email protected]
- [email protected]

## 2.0.0-alpha.13

### Patch Changes
Expand Down
7 changes: 7 additions & 0 deletions packages/rrdom/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# rrdom

## 2.0.0-alpha.14

### Patch Changes

- Updated dependencies [[`03b5216`](https://github.com/rrweb-io/rrweb/commit/03b5216a9403f1509b4f69d1d71ef9874277fe91), [`46f1b25`](https://github.com/rrweb-io/rrweb/commit/46f1b252a5919c68c68e825bd6089cc2e7d34e7c), [`cbbd1e5`](https://github.com/rrweb-io/rrweb/commit/cbbd1e55f1f7fa2eed9fa11e4152b509bdfd88f7), [`5e7943d`](https://github.com/rrweb-io/rrweb/commit/5e7943dbae6e2cde76c484bdd26bc0b96f1b6dce), [`c0f83af`](https://github.com/rrweb-io/rrweb/commit/c0f83afab8f1565633de0e986b7e96fa56f2d25c), [`e96f668`](https://github.com/rrweb-io/rrweb/commit/e96f668c86bd0ab5dc190bb2957a170271bb2ebc)]:
- [email protected]

## 2.0.0-alpha.13

### Patch Changes
Expand Down
7 changes: 7 additions & 0 deletions packages/rrvideo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# rrvideo

## 2.0.0-alpha.14

### Patch Changes

- Updated dependencies []:
- [email protected]

## 2.0.0-alpha.13

### Patch Changes
Expand Down
7 changes: 7 additions & 0 deletions packages/rrweb-player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# rrweb-player

## 2.0.0-alpha.14

### Patch Changes

- Updated dependencies [[`03b5216`](https://github.com/rrweb-io/rrweb/commit/03b5216a9403f1509b4f69d1d71ef9874277fe91), [`ae6908d`](https://github.com/rrweb-io/rrweb/commit/ae6908dcdcd7c732c1ce79eea19de5240bec1151), [`46f1b25`](https://github.com/rrweb-io/rrweb/commit/46f1b252a5919c68c68e825bd6089cc2e7d34e7c), [`cbbd1e5`](https://github.com/rrweb-io/rrweb/commit/cbbd1e55f1f7fa2eed9fa11e4152b509bdfd88f7), [`e96f668`](https://github.com/rrweb-io/rrweb/commit/e96f668c86bd0ab5dc190bb2957a170271bb2ebc)]:
- [email protected]

## 2.0.0-alpha.13

### Patch Changes
Expand Down
21 changes: 21 additions & 0 deletions packages/rrweb-snapshot/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# rrweb-snapshot

## 2.0.0-alpha.14

### Patch Changes

- [#1464](https://github.com/rrweb-io/rrweb/pull/1464) [`03b5216`](https://github.com/rrweb-io/rrweb/commit/03b5216a9403f1509b4f69d1d71ef9874277fe91) Thanks [@colingm](https://github.com/colingm)! - better support for coexistence with older libraries (e.g. MooTools & Prototype.js) which modify the in-built `Array.from` function

- [#1481](https://github.com/rrweb-io/rrweb/pull/1481) [`46f1b25`](https://github.com/rrweb-io/rrweb/commit/46f1b252a5919c68c68e825bd6089cc2e7d34e7c) Thanks [@eoghanmurray](https://github.com/eoghanmurray)! - Fix and test for bug #1457 which was affecting replay of complex tailwind css

- [#1476](https://github.com/rrweb-io/rrweb/pull/1476) [`cbbd1e5`](https://github.com/rrweb-io/rrweb/commit/cbbd1e55f1f7fa2eed9fa11e4152b509bdfd88f7) Thanks [@eoghanmurray](https://github.com/eoghanmurray)! - Fixup for multiple background-clip replacement

- [#1387](https://github.com/rrweb-io/rrweb/pull/1387) [`5e7943d`](https://github.com/rrweb-io/rrweb/commit/5e7943dbae6e2cde76c484bdd26bc0b96f1b6dce) Thanks [@H4ad](https://github.com/H4ad)! - Avoid recreating the same element every time, instead, we cache and we just update the element.

Before: 779k ops/s
After: 860k ops/s

Benchmark: https://jsbench.me/ktlqztuf95/1

- [#1440](https://github.com/rrweb-io/rrweb/pull/1440) [`c0f83af`](https://github.com/rrweb-io/rrweb/commit/c0f83afab8f1565633de0e986b7e96fa56f2d25c) Thanks [@daibhin](https://github.com/daibhin)! - better nested css selector splitting when commas or brackets happen to be in quoted text

- [#1467](https://github.com/rrweb-io/rrweb/pull/1467) [`e96f668`](https://github.com/rrweb-io/rrweb/commit/e96f668c86bd0ab5dc190bb2957a170271bb2ebc) Thanks [@eoghanmurray](https://github.com/eoghanmurray)! - Bugfix after #1434 perf improvements: fix that blob urls persist on the shared anchor element and can't be later modified

## 2.0.0-alpha.13

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/rrweb-snapshot/src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,8 @@ export function parse(css: string, options: ParserOptions = {}) {
name +
'\\s*((?:' +
[
'(?<!\\\\)"(?:\\\\"|[^"])*"',
"(?<!\\\\)'(?:\\\\'|[^'])*'",
/[^\\]"(?:\\"|[^"])*"/.source, // consume any quoted parts (checking that the double quote isn't itself escaped)
/[^\\]'(?:\\'|[^'])*'/.source, // same but for single quotes
'[^;]',
].join('|') +
')+);',
Expand Down
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tagMap,
elementNode,
BuildCache,
attributes,

Check warning on line 8 in packages/rrweb-snapshot/src/rebuild.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/rebuild.ts#L8

[@typescript-eslint/no-unused-vars] 'attributes' is defined but never used.
legacyAttributes,
} from './types';
import { isElement, Mirror, isNodeMetaEqual } from './utils';
Expand Down Expand Up @@ -278,7 +278,7 @@
const value = specialAttributes[name];
// handle internal attributes
if (tagName === 'canvas' && name === 'rr_dataURL') {
const image = document.createElement('img');
const image = doc.createElement('img');
image.onload = () => {
const ctx = (node as HTMLCanvasElement).getContext('2d');
if (ctx) {
Expand Down Expand Up @@ -502,7 +502,7 @@

for (const id of mirror.getIds()) {
if (mirror.has(id)) {
walk(mirror.getNode(id)!);

Check warning on line 505 in packages/rrweb-snapshot/src/rebuild.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/rebuild.ts#L505

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
}
}
}
Expand Down
29 changes: 20 additions & 9 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
export function ignoreAttribute(
tagName: string,
name: string,
_value: unknown,

Check warning on line 279 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L279

[@typescript-eslint/no-unused-vars] '_value' is defined but never used.
): boolean {
return (tagName === 'video' || tagName === 'audio') && name === 'autoplay';
}
Expand Down Expand Up @@ -513,7 +513,7 @@
iframeEl.addEventListener('load', listener);
}

function isStylesheetLoaded(link: HTMLLinkElement) {

Check warning on line 516 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L516

[@typescript-eslint/no-unused-vars] 'isStylesheetLoaded' is defined but never used.
if (!link.getAttribute('href')) return true; // nothing to load
return link.sheet !== null;
}
Expand Down Expand Up @@ -722,7 +722,7 @@
// So we'll be conservative and keep textContent as-is.
} else if ((n.parentNode as HTMLStyleElement).sheet?.cssRules) {
textContent = stringifyStylesheet(
(n.parentNode as HTMLStyleElement).sheet!,

Check warning on line 725 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L725

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
);
}
} catch (err) {
Expand Down Expand Up @@ -829,7 +829,7 @@
keepIframeSrcFn,
newlyAddedElement = false,
rootId,
maskAllText,

Check warning on line 832 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L832

[@typescript-eslint/no-unused-vars] 'maskAllText' is assigned a value but never used.
maskTextClass,
unmaskTextClass,
maskTextSelector,
Expand Down Expand Up @@ -871,7 +871,7 @@
if (cssText) {
delete attributes.rel;
delete attributes.href;
attributes._cssText = absoluteToStylesheet(cssText, stylesheet!.href!);

Check warning on line 874 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L874

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.

Check warning on line 874 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L874

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
}
}
// dynamic stylesheet
Expand Down Expand Up @@ -956,7 +956,7 @@
);

// create blank canvas of same dimensions
const blankCanvas = document.createElement('canvas');
const blankCanvas = doc.createElement('canvas');
blankCanvas.width = (n as HTMLCanvasElement).width;
blankCanvas.height = (n as HTMLCanvasElement).height;
const blankCanvasDataURL = blankCanvas.toDataURL(
Expand All @@ -977,26 +977,37 @@
canvasCtx = canvasService.getContext('2d');
}
const image = n as HTMLImageElement;
const oldValue = image.crossOrigin;
image.crossOrigin = 'anonymous';
const imageSrc: string =
image.currentSrc || image.getAttribute('src') || '<unknown-src>';
const priorCrossOrigin = image.crossOrigin;
const recordInlineImage = () => {
image.removeEventListener('load', recordInlineImage);
try {
canvasService!.width = image.naturalWidth;

Check warning on line 986 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L986

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
canvasService!.height = image.naturalHeight;

Check warning on line 987 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L987

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
canvasCtx!.drawImage(image, 0, 0);

Check warning on line 988 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L988

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
attributes.rr_dataURL = canvasService!.toDataURL(

Check warning on line 989 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L989

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
dataURLOptions.type,
dataURLOptions.quality,
);
} catch (err) {
console.warn(
`Cannot inline img src=${image.currentSrc}! Error: ${err as string}`,
);
if (image.crossOrigin !== 'anonymous') {
image.crossOrigin = 'anonymous';
if (image.complete && image.naturalWidth !== 0)
recordInlineImage(); // too early due to image reload
else image.addEventListener('load', 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ exports[`integration tests [html file]: mask-text.html 1`] = `
exports[`integration tests [html file]: picture.html 1`] = `
"<html xmlns=\\"http://www.w3.org/1999/xhtml\\"><head></head><body>
<picture>
<!-- these are 404 - not sure if that's intentional -->
<source type=\\"image/webp\\" srcset=\\"http://localhost:3030/assets/img/characters/robot.webp\\" />
<img src=\\"http://localhost:3030/assets/img/characters/robot.png\\" />
</picture>
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb-snapshot/test/html/picture.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<picture>
<!-- these are 404 - not sure if that's intentional -->
<source type="image/webp" srcset="assets/img/characters/robot.webp" />
<img src="assets/img/characters/robot.png" />
</picture>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 58 additions & 7 deletions packages/rrweb-snapshot/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as puppeteer from 'puppeteer';
import * as rollup from 'rollup';
import * as typescript from 'rollup-plugin-typescript2';
import * as assert from 'assert';
import { waitForRAF } from './utils';
import { waitForRAF, getServerURL } from './utils';

const _typescript = typescript as unknown as () => rollup.Plugin;

Expand Down Expand Up @@ -209,12 +209,63 @@ iframe.contentDocument.querySelector('center').clientHeight
inlineImages: true,
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,'));
// 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[];
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,/),
},
}),
);
});

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(
`
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<img src="${getServerURL(
server,
)}/images/rrweb-favicon-20x20.png" alt="CORS restricted but has access-control-allow-origin: *" />
</body>
</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); // 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: getServerURL(server) + '/images/rrweb-favicon-20x20.png',
alt: 'CORS restricted but has access-control-allow-origin: *',
rr_dataURL: expect.stringMatching(/^data:image\/webp;base64,/),
},
}),
);
});

it('correctly saves blob:images offline', async () => {
Expand Down
25 changes: 25 additions & 0 deletions packages/rrweb-snapshot/test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
_isBlockedElement,
needMaskingText,
} from '../src/snapshot';
import snapshot from '../src/snapshot';
import { serializedNodeWithId } from '../src/types';
import { Mirror } from '../src/utils';

Expand Down Expand Up @@ -578,3 +579,27 @@ describe('needMaskingText', () => {
});
});
});

describe('jsdom snapshot', () => {
const render = (html: string): Document => {
document.write(html);
return document;
};

it("doesn't rely on global browser objects", () => {
// this test is incomplete in terms of coverage,
// but the idea being that we are checking that all features use the
// passed-in `doc` object rather than the global `document`
// (which is only present in browsers)
// in any case, supporting jsdom is not a primary goal

const doc = render(`<!DOCTYPE html><p>Hello world</p><canvas></canvas>`);
const sn = snapshot(doc, {
// JSDOM Error: Not implemented: HTMLCanvasElement.prototype.toDataURL (without installing the canvas npm package)
//recordCanvas: true,
});
expect(sn).toMatchObject({
type: 0,
});
});
});
10 changes: 10 additions & 0 deletions packages/rrweb-snapshot/test/utils.ts
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand All @@ -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}`;
}
}
Loading
Loading