Skip to content

Commit

Permalink
upstream: Merge upstream commits up to 609b7fa (#219)
Browse files Browse the repository at this point in the history
Merges upstream commits up to 609b7fa
  • Loading branch information
billyvg authored Sep 18, 2024
2 parents d665218 + 8862588 commit febd76e
Show file tree
Hide file tree
Showing 38 changed files with 337 additions and 172 deletions.
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)]:
- rrweb-snapshot@2.0.0-alpha.14
- rrdom@2.0.0-alpha.14

## 2.0.0-alpha.13

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/rrdom-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rrdom-nodejs",
"version": "2.0.0-alpha.13",
"version": "2.0.0-alpha.14",
"scripts": {
"dev": "rollup -c -w",
"bundle": "rollup --config",
Expand Down Expand Up @@ -48,8 +48,8 @@
"cssom": "^0.5.0",
"cssstyle": "^2.3.0",
"nwsapi": "^2.2.0",
"rrdom": "^2.0.0-alpha.13",
"rrweb-snapshot": "^2.0.0-alpha.13"
"rrdom": "^2.0.0-alpha.14",
"rrweb-snapshot": "^2.0.0-alpha.14"
},
"browserslist": [
"supports es6-class"
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)]:
- rrweb-snapshot@2.0.0-alpha.14

## 2.0.0-alpha.13

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/rrdom/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rrdom",
"version": "2.0.0-alpha.13",
"version": "2.0.0-alpha.14",
"homepage": "https://github.com/rrweb-io/rrweb/tree/main/packages/rrdom#readme",
"license": "MIT",
"main": "lib/rrdom.cjs",
Expand Down Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"@rollup/plugin-commonjs": "^20.0.0",
"@rrweb/types": "^2.0.0-alpha.13",
"@rrweb/types": "^2.0.0-alpha.14",
"@types/jest": "^27.4.1",
"@types/puppeteer": "^5.4.4",
"@typescript-eslint/eslint-plugin": "^5.23.0",
Expand All @@ -47,6 +47,6 @@
"ts-jest": "^27.1.3"
},
"dependencies": {
"rrweb-snapshot": "^2.0.0-alpha.13"
"rrweb-snapshot": "^2.0.0-alpha.14"
}
}
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 []:
- rrweb-player@2.0.0-alpha.14

## 2.0.0-alpha.13

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/rrvideo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rrvideo",
"version": "2.0.0-alpha.13",
"version": "2.0.0-alpha.14",
"description": "transform rrweb session into video",
"main": "build/index.js",
"bin": {
Expand All @@ -26,13 +26,13 @@
"@types/node": "^18.15.11",
"jest": "^27.5.1",
"ts-jest": "^27.1.3",
"@rrweb/types": "^2.0.0-alpha.13"
"@rrweb/types": "^2.0.0-alpha.14"
},
"dependencies": {
"@open-tech-world/cli-progress-bar": "^2.0.2",
"fs-extra": "^11.1.1",
"minimist": "^1.2.5",
"playwright": "^1.32.1",
"rrweb-player": "^2.0.0-alpha.13"
"rrweb-player": "^2.0.0-alpha.14"
}
}
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)]:
- rrweb@2.0.0-alpha.14

## 2.0.0-alpha.13

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/rrweb-player/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "rrweb-player",
"version": "2.0.0-alpha.13",
"version": "2.0.0-alpha.14",
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-node-resolve": "^13.2.1",
"@rrweb/types": "^2.0.0-alpha.13",
"@rrweb/types": "^2.0.0-alpha.14",
"@types/offscreencanvas": "^2019.6.4",
"eslint-config-google": "^0.14.0",
"eslint-plugin-svelte3": "^4.0.0",
Expand All @@ -24,7 +24,7 @@
},
"dependencies": {
"@tsconfig/svelte": "^1.0.0",
"rrweb": "^2.0.0-alpha.13"
"rrweb": "^2.0.0-alpha.14"
},
"scripts": {
"build": "rollup -c",
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
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rrweb-snapshot",
"version": "2.0.0-alpha.13",
"version": "2.0.0-alpha.14",
"description": "rrweb's component to take a snapshot of DOM, aka DOM serializer",
"scripts": {
"prepare": "npm run prepack",
Expand Down
18 changes: 14 additions & 4 deletions packages/rrweb-snapshot/src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
* Parse selector.
*/

// originally from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1
const selectorMatcher = new RegExp(
'^((' +
[
/[^\\]"(?:\\"|[^"])*"/.source, // consume any quoted parts (checking that the double quote isn't itself escaped)
/[^\\]'(?:\\'|[^'])*'/.source, // same but for single quotes
'[^{]',
].join('|') +
')+)',
);

function selector() {
whitespace();
while (css[0] == '}') {
Expand All @@ -432,8 +443,7 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
whitespace();
}

// Use match logic from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1
const m = match(/^(((?<!\\)"(?:\\"|[^"])*"|(?<!\\)'(?:\\'|[^'])*'|[^{])+)/);
const m = match(selectorMatcher);
if (!m) {
return;
}
Expand Down Expand Up @@ -869,8 +879,8 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
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 @@ -300,7 +300,7 @@ function buildNode(
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
29 changes: 20 additions & 9 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ function serializeElementNode(
);

// 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 @@ -750,8 +750,9 @@ function serializeElementNode(
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 {
Expand All @@ -763,13 +764,23 @@ 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';
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 @@ -337,6 +337,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.
Loading

0 comments on commit febd76e

Please sign in to comment.