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

Reverse monkey patch built in methods to support LWC #1509

Merged
merged 206 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
206 commits
Select commit Hold shift + click to select a range
ceda3aa
Chore: Add move most types from rrweb to @rrweb/types package
Juice10 Oct 20, 2022
bab2941
Split off type imports
Juice10 Oct 20, 2022
d571ea3
Split off type import to its own line
Juice10 Oct 20, 2022
b3ead33
Get vite to generate type definitions
Juice10 Oct 21, 2022
cc47ee3
Apply formatting changes
Juice10 Oct 21, 2022
b9f43b8
noEmit not allowed in tsconfig, moved it to build step
Juice10 Oct 21, 2022
0c41ba3
Merge branch '@juice10/@rrweb/types' of https://github.com/rrweb-io/r…
Juice10 Oct 21, 2022
0dfad95
Migrate rrdom-nodejs build to vite
Juice10 Oct 21, 2022
2728f8f
Apply formatting changes
Juice10 Oct 21, 2022
4c2f310
Migrate rrweb-snapshot to vite
Juice10 Oct 22, 2022
d57d780
Unify configs
Juice10 Oct 22, 2022
040c2ce
Chore: Migrate rrdom to vite
Juice10 Oct 22, 2022
9182fa2
Chore: Migrate rrweb to vite WIP
Juice10 Oct 23, 2022
369db3a
build:browser was removed (for now)
Juice10 Oct 23, 2022
3e28ecf
BREAKING: moved rrweb-plugin-console to its own npm module
Juice10 Oct 23, 2022
ff02234
Support cjs files in startServer
Juice10 Oct 23, 2022
77a4c6d
Move canvas-webrtc plugin to its own package
Juice10 Oct 23, 2022
193608e
Chore: move sequential-id plugin to its own package
Juice10 Oct 23, 2022
544e774
Chore: Configure rrweb's vite bundling
Juice10 Oct 23, 2022
98d6896
`Id` had lowercase `d` before, making it lowercase again
Juice10 Oct 23, 2022
45ea94e
Test: Move console tests to their own package
Juice10 Oct 24, 2022
54728a0
Merge branch 'master' of https://github.com/rrweb-io/rrweb into @juic…
Juice10 Nov 10, 2022
62c4d8f
Merge branch 'master' of https://github.com/rrweb-io/rrweb into @juic…
Juice10 Apr 8, 2024
2b5011f
remove unused utils from rrdom
Juice10 Apr 8, 2024
2d95102
pull in latest version of master
Juice10 Apr 8, 2024
eec0d64
Fix type casting issue in diff.ts
Juice10 Apr 8, 2024
0a68b47
Fix typo
Juice10 Apr 8, 2024
726c292
Fix duplicate entries in package.json and tsconfig.json
Juice10 Apr 8, 2024
876084c
Apply formatting changes
Juice10 Apr 8, 2024
48e29a7
Update dependencies in package.json files
Juice10 Apr 8, 2024
79e02c3
Merge branch '@juice10/vite' of https://github.com/rrweb-io/rrweb int…
Juice10 Apr 8, 2024
85c389c
Update dependencies to use Vite 5.2.8 in package.json files
Juice10 Apr 8, 2024
fc59ddd
Get tests passing for rrdom
Juice10 Apr 8, 2024
acaaf10
Fix image loading issue in integration tests
Juice10 Apr 8, 2024
a5001e1
Move pack/unpack to its own @rrweb/packer module
Juice10 Apr 9, 2024
71450e2
Get tests to work in rrdom-nodejs
Juice10 Apr 9, 2024
b10c833
Port tests in rrweb-snapshot to vitest and fix them
Juice10 Apr 9, 2024
c68fa98
Fix tests for rrweb-plugin-console-record
Juice10 Apr 9, 2024
02689e4
Add @rrweb/all package
Juice10 Apr 10, 2024
ad5563c
Fix publint and attw errors for rrdom and @rrweb/types
Juice10 Apr 10, 2024
6fde13e
Use shared vitest.config.ts in rrweb-snapshot package
Juice10 Apr 10, 2024
41cc89a
Fix publint and attw issues for rrweb-snapshot
Juice10 Apr 10, 2024
799310d
Export `ReplayPlugin` type directly from rrweb
Juice10 Apr 10, 2024
e46a951
Fix publint and attw issues for packages
Juice10 Apr 10, 2024
af3bc45
Fix publint & attw issue.
Juice10 Apr 10, 2024
1cce02e
Fix publint & attw issue.
Juice10 Apr 10, 2024
439f363
move some rrdom tests that require rrweb to rrweb package
Juice10 Apr 10, 2024
34a2ee1
Use pre-jest 29 syntax for snapshotting
Juice10 Apr 10, 2024
dc91e30
get rrweb passing publint and attw
Juice10 Apr 10, 2024
4a9dd49
const enum does not work with isolated modules flag
Juice10 Apr 10, 2024
b93b687
Fix script tag type in webgl.test.ts.snap and update rrweb.umd.cjs pa…
Juice10 Apr 10, 2024
deadccb
Fix paths
Juice10 Apr 10, 2024
b9cb10b
Move tests for console record plugin and fix bundle path
Juice10 Apr 10, 2024
990cbe0
Fix tests for rrweb
Juice10 Apr 10, 2024
3188bba
pack integration tests were moved to @rrweb/all
Juice10 Apr 10, 2024
901fc12
Update rrweb bundle path in test files
Juice10 Apr 10, 2024
4a007df
Fix flaky scroll emit from test
Juice10 Apr 11, 2024
4deee29
Migrate rrweb's tests over to vitest and make them pass
Juice10 Apr 11, 2024
09bd4bf
Make sure benchmarks & updating tests work
Juice10 Apr 11, 2024
ef0643b
Remove jest from rrweb
Juice10 Apr 11, 2024
c3709c4
Fix paths
Juice10 Apr 11, 2024
8e0abd7
always use rrweb's own cssom
Juice10 Apr 11, 2024
f689436
Update tsconfig.json for rrweb-plugin-sequential-id-record
Juice10 Apr 11, 2024
5fc5615
Add tsbuildinfo config to extended tsconfig files
Juice10 Apr 11, 2024
0c1abe2
Move rrdom over to vitest
Juice10 Apr 11, 2024
c2266a7
Apply formatting changes
Juice10 Apr 11, 2024
6218b6e
Update rrweb imports to use the new package structure
Juice10 Apr 11, 2024
68fe9e4
Merge branch '@juice10/vite' of https://github.com/rrweb-io/rrweb int…
Juice10 Apr 11, 2024
9eda12e
extend rrweb-snapshot's tsconfig from monorepo base config
Juice10 Apr 11, 2024
a2876a1
extend @rrweb/types's tsconfig from monorepo base config
Juice10 Apr 11, 2024
ac79f63
extend rrdom's tsconfig from monorepo base config
Juice10 Apr 11, 2024
993573d
extend rrdom-nodejs's tsconfig from monorepo base config
Juice10 Apr 11, 2024
be097cf
extend web-extension's tsconfig from monorepo base config
Juice10 Apr 11, 2024
296ac55
unify tsconfigs
Juice10 Apr 11, 2024
5083fc2
Continue when tests fail
Juice10 Apr 11, 2024
17d707f
Add stricter type checking
Juice10 Apr 11, 2024
01533bf
Add check-types global command
Juice10 Apr 11, 2024
ac54452
remove jest
Juice10 Apr 11, 2024
e0f4b5d
Remove unused code
Juice10 Apr 11, 2024
a9ed119
Add check-types command to build script
Juice10 Apr 11, 2024
1d09c23
Fix linting issues
Juice10 Apr 11, 2024
31a93fb
Add setup Chrome action for CI/CD workflow
Juice10 Apr 11, 2024
f9447fe
Update puppeteer version in package.json for rrweb
Juice10 Apr 11, 2024
9fa2d1c
Update Chrome setup in CI/CD workflow
Juice10 Apr 11, 2024
551eeb2
Update Chrome setup in CI/CD workflow
Juice10 Apr 11, 2024
b346a8c
Add Chrome setup and test cache location
Juice10 Apr 11, 2024
db05651
Update CI/CD workflow to test chrome cache location
Juice10 Apr 11, 2024
66252be
Add chrome installation step to CI/CD workflow
Juice10 Apr 11, 2024
9870805
Update Puppeteer configuration for headless testing
Juice10 Apr 11, 2024
bb1c36d
Update dependencies and workflow configuration
Juice10 Apr 11, 2024
7dd0d6d
Use same version of chrome on CI as is run locally
Juice10 Apr 12, 2024
336b4b2
Use version of chrome that seems to work with rrdom tests
Juice10 Apr 12, 2024
a59001f
Try using puppeteerrc to define chrome version
Juice10 Apr 12, 2024
0bd230f
Add .cache directory to .gitignore
Juice10 Apr 12, 2024
55547d6
Move global flag to vitest config
Juice10 Apr 12, 2024
106b39a
Update puppeteer version to 20.9.0
Juice10 Apr 12, 2024
9332204
Update console log messages in rrweb-plugin-console-record for new pu…
Juice10 Apr 12, 2024
c5da6a4
Remove redundant Chrome setup from CI/CD workflow
Juice10 Apr 12, 2024
324a7cf
Add minification and umd for all built files
Juice10 Apr 12, 2024
19db415
Update import paths for rrweb dist files
Juice10 Apr 12, 2024
33d5380
Add @rrweb/replay and @rrweb/record
Juice10 Apr 14, 2024
cd71e93
Add script to lint packages
Juice10 Apr 14, 2024
9111005
Apply formatting changes
Juice10 Apr 14, 2024
43ea92c
exclude styles export from typescript package type checking
Juice10 Apr 14, 2024
e8dfe8d
Merge branch '@juice10/vite' of https://github.com/rrweb-io/rrweb int…
Juice10 Apr 14, 2024
da29752
WIP Move rrweb-player over to vite
Juice10 Apr 15, 2024
74bb7ff
Apply formatting changes
Juice10 Apr 16, 2024
db2ac5a
chore: Update rrweb plugin import paths
Juice10 Apr 16, 2024
6c6bb8f
Merge branch '@juice10/vite' of https://github.com/rrweb-io/rrweb int…
Juice10 Apr 16, 2024
f91fa48
Remove rollup from rrweb-player
Juice10 Apr 16, 2024
bbb4e30
Fix typing issues
Juice10 Apr 16, 2024
16cdd2f
Fix typing issues
Juice10 Apr 16, 2024
4aced12
chore: Update rrweb-player to use vite for build process
Juice10 Apr 16, 2024
4e7d0b3
Apply formatting changes
Juice10 Apr 16, 2024
8f62f62
chore: Export Player class in rrweb-player/src/main.ts
Juice10 Apr 16, 2024
1d79e67
Merge branch '@juice10/vite' of https://github.com/rrweb-io/rrweb int…
Juice10 Apr 16, 2024
4823f9b
Apply formatting changes
Juice10 Apr 16, 2024
7e4b77f
Gets wiped by yarn workspaces-to-typescript-project-references
Juice10 Apr 16, 2024
5158760
Add .eslintignore and .eslintrc.cjs files for rrweb-player package
Juice10 Apr 16, 2024
8633a55
Merge branch '@juice10/vite' of https://github.com/rrweb-io/rrweb int…
Juice10 Apr 16, 2024
a48b240
Apply formatting changes
Juice10 Apr 16, 2024
fec731f
Update dependencies in rrweb-player/package.json
Juice10 Apr 16, 2024
79c6129
Merge branch '@juice10/vite' of https://github.com/rrweb-io/rrweb int…
Juice10 Apr 16, 2024
99b889e
Apply formatting changes
Juice10 Apr 16, 2024
92a9404
chore: Update eslint configuration for rrweb-player package
Juice10 Apr 16, 2024
5ae5fda
Merge branch '@juice10/vite' of https://github.com/rrweb-io/rrweb int…
Juice10 Apr 16, 2024
14f9f2d
Apply formatting changes
Juice10 Apr 16, 2024
7075e57
chore: Remove unused files from rrweb-player package
Juice10 Apr 16, 2024
e36125f
Merge branch '@juice10/vite' of https://github.com/rrweb-io/rrweb int…
Juice10 Apr 16, 2024
4b2491f
Apply formatting changes
Juice10 Apr 16, 2024
bda50b2
chore: Update rrweb-player import path to use rrweb-player.cjs
Juice10 Apr 16, 2024
0567785
chore: Update addEventListener signature in rrweb-player
Juice10 Apr 16, 2024
a6c933a
Apply formatting changes
Juice10 Apr 16, 2024
d73021b
Add .eslintignore and update .gitignore files for to root
Juice10 Apr 17, 2024
a061d4b
Apply formatting changes
Juice10 Apr 17, 2024
c45a8fd
Update documentation
Juice10 Apr 17, 2024
e1caee8
Update @rrweb/types package description
Juice10 Apr 17, 2024
285f600
Apply formatting changes
Juice10 Apr 17, 2024
df23897
Update build and run commands in CONTRIBUTING.md
Juice10 Apr 17, 2024
9615169
Apply formatting changes
Juice10 Apr 17, 2024
9521682
Merge branch 'master' into @juice10/vite
Juice10 Apr 18, 2024
e6d33d7
Update package versions to 2.0.0-alpha.13
Juice10 Apr 18, 2024
eae4336
Apply formatting changes
Juice10 Apr 18, 2024
26d56ff
Merge branch 'master' of https://github.com/rrweb-io/rrweb into @juic…
Juice10 Apr 18, 2024
fdb8d39
Apply formatting changes
Juice10 Apr 18, 2024
8ee563c
Merge branch 'master' of https://github.com/rrweb-io/rrweb into @juic…
Juice10 May 1, 2024
5fd8bd2
Fix import statement in media/index.ts
Juice10 May 1, 2024
6f446ff
Apply formatting changes
Juice10 May 1, 2024
e0f749c
chore: Update .gitignore to exclude build and dist directories
Juice10 May 14, 2024
f61dce8
Merge branch 'master' into @juice10/vite
Juice10 May 14, 2024
2685dd8
Apply formatting changes
Juice10 May 14, 2024
397bd94
Merge branch 'master' of https://github.com/rrweb-io/rrweb into @juic…
Juice10 May 14, 2024
91fdce9
Merge branch '@juice10/vite' of https://github.com/rrweb-io/rrweb int…
Juice10 May 14, 2024
69788d9
Merge branch 'master' into @juice10/vite
Juice10 May 22, 2024
fd0b2f9
Apply formatting changes
Juice10 May 22, 2024
dd82a7e
Migrate setTimeout to vitest
Juice10 May 22, 2024
4c6bfc9
Apply formatting changes
Juice10 May 22, 2024
73f6b0b
Merge branch 'master' of https://github.com/rrweb-io/rrweb into @juic…
Juice10 May 22, 2024
282bf0d
Apply formatting changes
Juice10 May 22, 2024
5420de4
Fix isNativeShadowDom function signature in utils.ts
Juice10 May 28, 2024
0cae083
try out jsr
Juice10 May 28, 2024
02d12bc
Apply formatting changes
Juice10 May 28, 2024
88b9629
Merge branch 'master' of https://github.com/rrweb-io/rrweb into @juic…
Juice10 May 28, 2024
04a9bc3
Update package versions to 2.0.0-alpha.14
Juice10 May 28, 2024
e27ec75
Apply formatting changes
Juice10 May 28, 2024
4bfcbd6
Fix name of rrwebSnapshot object
Juice10 May 28, 2024
a47f5df
Apply formatting changes
Juice10 May 28, 2024
e7f7396
Get around monkey patched Nodes
Juice10 May 22, 2024
41022b4
inlineImages: Setting of `image.crossOrigin` is not always necessary …
eoghanmurray May 23, 2024
d8a0464
Move `childNodes` to @rrweb/utils
Juice10 May 28, 2024
05bb2fe
Apply formatting changes
Juice10 May 28, 2024
26f74d9
Use non-monkey patched versions of the `childNodes`, `parentNode` `pa…
Juice10 May 28, 2024
f26edee
Apply formatting changes
Juice10 May 28, 2024
2a7e469
Add getRootNode and contains, and add comprehensive todo list
Juice10 Jun 5, 2024
16879a2
chore: Update turbo.json tasks for better build process
Juice10 Jun 5, 2024
c400f04
Apply formatting changes
Juice10 Jun 5, 2024
8331169
Update caniuse-lite
Juice10 Jun 13, 2024
a760e6b
Apply formatting changes
Juice10 Jun 13, 2024
d141892
chore: Update eslint-plugin-compat to version 5.0.0
Juice10 Jun 13, 2024
c0b99b5
Apply formatting changes
Juice10 Jun 13, 2024
e022b8c
Merge branch 'master' of https://github.com/rrweb-io/rrweb into juice…
Juice10 Jun 13, 2024
8ed5785
chore: Bump @rrweb/utils version to 2.0.0-alpha.15
Juice10 Jun 14, 2024
1a2e630
delete unused yarn.lock files
Juice10 Jun 14, 2024
39c221a
Set correct @rrweb/utils version in package.json
Juice10 Jun 14, 2024
9440510
Migrate over some accessors to reverse-monkey-patched version
Juice10 Jun 14, 2024
2ee292d
Add missing functions
Juice10 Jun 14, 2024
a623f51
Fix illegal invocation error
Juice10 Jun 14, 2024
537b242
Revert closer to what it was.
Juice10 Jun 14, 2024
f314cad
Reverse monkey patch all methods LWC hijacks
Juice10 Jun 18, 2024
63daa7f
Make tests more stable
Juice10 Jun 18, 2024
2320348
Merge branch 'master' of https://github.com/rrweb-io/rrweb into juice…
Juice10 Jun 18, 2024
abf5d62
Safely handle rrdom nodes in hasShadowRoot
Juice10 Jun 18, 2024
8ec6489
Remove duplicated test
Juice10 Jun 19, 2024
93b4be0
Use variable `serverURL` in test
Juice10 Jun 19, 2024
95c5350
Use monorepo default browserlist
Juice10 Jun 19, 2024
7dc30c9
Merge branch 'master' into juice10/reverse-monkey-patch
Juice10 Jun 24, 2024
6255037
Create unlucky-mirrors-invite.md
Juice10 Jun 24, 2024
5862e63
Fix typing issue for new typescript
Juice10 Jun 24, 2024
b5f1ecf
Remove unused package
Juice10 Jun 24, 2024
02025a1
Remove unused code
Juice10 Jun 24, 2024
c10cf1e
Merge branch 'master' of https://github.com/rrweb-io/rrweb into juice…
Juice10 Jun 26, 2024
54e33ae
Merge branch 'master' of https://github.com/rrweb-io/rrweb into juice…
Juice10 Jul 1, 2024
494f300
Add prefix to reverse-monkey-patched methods to make them more explicit
Juice10 Jul 9, 2024
f63db4e
Add default exports to @rrweb/utils
Juice10 Aug 2, 2024
1359833
Merge branch 'master' into juice10/reverse-monkey-patch
Juice10 Aug 2, 2024
f34bfbf
Fix typo
Juice10 Aug 2, 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
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@rrweb/record",
"@rrweb/types",
"@rrweb/packer",
"@rrweb/utils",
"@rrweb/web-extension",
"rrvideo",
"@rrweb/rrweb-plugin-console-record",
Expand Down
7 changes: 7 additions & 0 deletions .changeset/unlucky-mirrors-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"rrweb-snapshot": patch
"rrweb": patch
"@rrweb/utils": patch
---

Reverse monkey patch built in methods to support LWC (and other frameworks like angular which monkey patch built in methods).
5 changes: 5 additions & 0 deletions .vscode/rrweb-monorepo.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"name": "@rrweb/types",
"path": "../packages/types"
},
{
"name": "@rrweb/utils",
"path": "../packages/utils"
},
{
"name": "@rrweb/packer",
"path": "../packages/packer"
Expand Down Expand Up @@ -88,6 +92,7 @@
"@rrweb/record",
"@rrweb/replay",
"@rrweb/types",
"@rrweb/utils",
"@rrweb/packer",
"@rrweb/rrweb-plugin-console-record",
"@rrweb/rrweb-plugin-console-replay",
Expand Down
1 change: 1 addition & 0 deletions guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Besides the `rrweb` and `@rrweb/record` packages, rrweb also provides other pack
- [@rrweb/replay](packages/replay): A package for replaying rrweb sessions.
- [@rrweb/packer](packages/packer): A package for packing and unpacking rrweb data.
- [@rrweb/types](packages/types): Contains types shared across rrweb packages.
- [@rrweb/utils](packages/utils): Contains utility functions shared across rrweb packages.
- [web-extension](packages/web-extension): A web extension for rrweb.
- [rrvideo](packages/rrvideo): A package for handling video operations in rrweb.
- [@rrweb/rrweb-plugin-console-record](packages/plugins/rrweb-plugin-console-record): A plugin for recording console logs.
Expand Down
3 changes: 2 additions & 1 deletion guide.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ rrweb 代码分为录制和回放两部分,大多数时候用户在被录制
- [@rrweb/record](packages/record):一个用于录制 rrweb 会话的包。
- [@rrweb/replay](packages/replay):一个用于回放 rrweb 会话的包。
- [@rrweb/packer](packages/packer):一个用于打包和解包 rrweb 数据的包。
- [@rrweb/types](packages/types):包含 rrweb 中使用的类型定义。
- [@rrweb/types](packages/types):包含 rrweb 包中共享的类型定义。
- [@rrweb/utils](packages/utils):包含 rrweb 包中共享的工具函数。
- [web-extension](packages/web-extension):rrweb 的网页扩展。
- [rrvideo](packages/rrvideo):一个用于处理 rrweb 中视频操作的包。
- [@rrweb/rrweb-plugin-console-record](packages/plugins/rrweb-plugin-console-record):一个用于记录控制台日志的插件。
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"cross-env": "^7.0.3",
"esbuild-plugin-umd-wrapper": "^2.0.0",
"eslint": "^8.53.0",
"eslint-plugin-compat": "^4.2.0",
"eslint-plugin-compat": "^5.0.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-tsdoc": "^0.2.17",
"markdownlint": "^0.25.1",
Expand All @@ -49,7 +49,7 @@
"check-types": "yarn turbo run check-types --continue",
"format": "yarn prettier --write '**/*.{ts,md}'",
"format:head": "git diff --name-only HEAD^ |grep '\\.ts$\\|\\.md$' |xargs yarn prettier --write",
"dev": "yarn turbo run dev --concurrency=17",
"dev": "yarn turbo run dev --concurrency=18",
"repl": "cd packages/rrweb && npm run repl",
"live-stream": "cd packages/rrweb && yarn live-stream",
"lint": "yarn run concurrently --success=all -r -m=1 'yarn run markdownlint docs' 'yarn eslint packages/*/src --ext .ts,.tsx,.js,.jsx,.svelte'",
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb-snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"homepage": "https://github.com/rrweb-io/rrweb/tree/master/packages/rrweb-snapshot#readme",
"devDependencies": {
"@rrweb/utils": "^2.0.0-alpha.16",
"@types/jsdom": "^20.0.0",
"@types/node": "^18.15.11",
"@types/puppeteer": "^5.4.4",
Expand Down
63 changes: 31 additions & 32 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
extractFileExtension,
absolutifyURLs,
} from './utils';
import dom from '@rrweb/utils';

let _id = 1;
const tagNameRegex = new RegExp('[^a-z0-9-_:]');
Expand Down Expand Up @@ -247,7 +248,7 @@
if (!node) return false;
if (node.nodeType !== node.ELEMENT_NODE) {
if (!checkAncestors) return false;
return classMatchesRegex(node.parentNode, regex, checkAncestors);
return classMatchesRegex(dom.parentNode(node), regex, checkAncestors);
}

for (let eIndex = (node as HTMLElement).classList.length; eIndex--; ) {
Expand All @@ -257,7 +258,7 @@
}
}
if (!checkAncestors) return false;
return classMatchesRegex(node.parentNode, regex, checkAncestors);
return classMatchesRegex(dom.parentNode(node), regex, checkAncestors);
}

export function needMaskingText(
Expand All @@ -269,16 +270,16 @@
let el: Element;
if (isElement(node)) {
el = node;
if (!el.childNodes.length) {
if (!dom.childNodes(el).length) {
// optimisation: we can avoid any of the below checks on leaf elements
// as masking is applied to child text nodes only
return false;
}
} else if (node.parentElement === null) {
} else if (dom.parentElement(node) === null) {
// should warn? maybe a text node isn't attached to a parent node yet?
return false;
} else {
el = node.parentElement;
el = dom.parentElement(node)!;

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
}
try {
if (typeof maskTextClass === 'string') {
Expand Down Expand Up @@ -475,7 +476,7 @@
case n.COMMENT_NODE:
return {
type: NodeType.Comment,
textContent: (n as Comment).textContent || '',
textContent: dom.textContent(n as Comment) || '',
rootId,
};
default:
Expand All @@ -501,43 +502,42 @@
const { needsMask, maskTextFn, rootId } = options;
// The parent node may not be a html element which has a tagName attribute.
// So just let it be undefined which is ok in this use case.
const parentTagName = n.parentNode && (n.parentNode as HTMLElement).tagName;
let textContent = n.textContent;
const parent = dom.parentNode(n);
const parentTagName = parent && (parent as HTMLElement).tagName;
let text = dom.textContent(n);
const isStyle = parentTagName === 'STYLE' ? true : undefined;
const isScript = parentTagName === 'SCRIPT' ? true : undefined;
if (isStyle && textContent) {
if (isStyle && text) {
try {
// try to read style sheet
if (n.nextSibling || n.previousSibling) {
// This is not the only child of the stylesheet.
// We can't read all of the sheet's .cssRules and expect them
// to _only_ include the current rule(s) added by the text node.
// 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!,
);
} else if ((parent as HTMLStyleElement).sheet?.cssRules) {
text = stringifyStylesheet((parent as HTMLStyleElement).sheet!);

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
}
} catch (err) {
console.warn(
`Cannot get CSS styles from text's parentNode. Error: ${err as string}`,
n,
);
}
textContent = absolutifyURLs(textContent, getHref(options.doc));
text = absolutifyURLs(text, getHref(options.doc));
}
if (isScript) {
textContent = 'SCRIPT_PLACEHOLDER';
text = 'SCRIPT_PLACEHOLDER';
}
if (!isStyle && !isScript && textContent && needsMask) {
textContent = maskTextFn
? maskTextFn(textContent, n.parentElement)
: textContent.replace(/[\S]/g, '*');
if (!isStyle && !isScript && text && needsMask) {
text = maskTextFn
? maskTextFn(text, dom.parentElement(n))
: text.replace(/[\S]/g, '*');
}

return {
type: NodeType.Text,
textContent: textContent || '',
textContent: text || '',
isStyle,
rootId,
};
Expand Down Expand Up @@ -594,6 +594,7 @@
}
// remote css
if (tagName === 'link' && inlineStylesheet) {
//TODO: maybe replace this `.styleSheets` with original one
const stylesheet = Array.from(doc.styleSheets).find((s) => {
return s.href === (n as HTMLLinkElement).href;
});
Expand All @@ -612,7 +613,7 @@
tagName === 'style' &&
(n as HTMLStyleElement).sheet &&
// TODO: Currently we only try to get dynamic stylesheet when it is an empty style element
!(n.innerText || n.textContent || '').trim().length
!(n.innerText || dom.textContent(n) || '').trim().length
) {
const cssText = stringifyStylesheet(
(n as HTMLStyleElement).sheet as CSSStyleSheet,
Expand Down Expand Up @@ -708,10 +709,10 @@
const recordInlineImage = () => {
image.removeEventListener('load', recordInlineImage);
try {
canvasService!.width = image.naturalWidth;

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

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

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

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

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

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

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
dataURLOptions.type,
dataURLOptions.quality,
);
Expand Down Expand Up @@ -1030,8 +1031,8 @@
recordChild = recordChild && !serializedNode.needBlock;
// this property was not needed in replay side
delete serializedNode.needBlock;
const shadowRoot = (n as HTMLElement).shadowRoot;
if (shadowRoot && isNativeShadowDom(shadowRoot))
const shadowRootEl = dom.shadowRoot(n);
if (shadowRootEl && isNativeShadowDom(shadowRootEl))
serializedNode.isShadowHost = true;
}
if (
Expand Down Expand Up @@ -1080,31 +1081,29 @@
) {
// value parameter in DOM reflects the correct value, so ignore childNode
} else {
for (const childN of Array.from(n.childNodes)) {
for (const childN of Array.from(dom.childNodes(n))) {
const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
if (serializedChildNode) {
serializedNode.childNodes.push(serializedChildNode);
}
}
}

if (isElement(n) && n.shadowRoot) {
for (const childN of Array.from(n.shadowRoot.childNodes)) {
let shadowRootEl: ShadowRoot | null = null;
if (isElement(n) && (shadowRootEl = dom.shadowRoot(n))) {
for (const childN of Array.from(dom.childNodes(shadowRootEl))) {
const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
if (serializedChildNode) {
isNativeShadowDom(n.shadowRoot) &&
isNativeShadowDom(shadowRootEl) &&
(serializedChildNode.isShadow = true);
serializedNode.childNodes.push(serializedChildNode);
}
}
}
}

if (
n.parentNode &&
isShadowRoot(n.parentNode) &&
isNativeShadowDom(n.parentNode)
) {
const parent = dom.parentNode(n);
if (parent && isShadowRoot(parent) && isNativeShadowDom(parent)) {
serializedNode.isShadow = true;
}

Expand Down
10 changes: 8 additions & 2 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
textNode,
elementNode,
} from './types';
import dom from '@rrweb/utils';
import { NodeType } from './types';

export function isElement(n: Node): n is Element {
return n.nodeType === n.ELEMENT_NODE;
}

export function isShadowRoot(n: Node): n is ShadowRoot {
const host: Element | null = (n as ShadowRoot)?.host;
return Boolean(host?.shadowRoot === n);
const hostEl: Element | null =
// anchor and textarea elements also have a `host` property
// but only shadow roots have a `mode` property
(n && 'host' in n && 'mode' in n && dom.host(n as ShadowRoot)) || null;
return Boolean(
hostEl && 'shadowRoot' in hostEl && dom.shadowRoot(hostEl) === n,
);
}

/**
Expand Down Expand Up @@ -71,7 +77,7 @@
* Browsers sometimes incorrectly escape `@import` on `.cssText` statements.
* This function tries to correct the escaping.
* more info: https://bugs.chromium.org/p/chromium/issues/detail?id=1472259
* @param cssImportRule

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

tsdoc-param-tag-missing-hyphen: The @param block should be followed by a parameter name and then a hyphen

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

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

tsdoc-param-tag-missing-hyphen: The @param block should be followed by a parameter name and then a hyphen

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/utils.ts#L80

[tsdoc/syntax] tsdoc-param-tag-missing-hyphen: The @param block should be followed by a parameter name and then a hyphen
* @returns `cssText` with browser inconsistencies fixed, or null if not applicable.
*/
export function escapeImportStatement(rule: CSSImportRule): string {
Expand Down
Loading
Loading