From 1c5acb69be8b9daef5efe9535fc35d6eda3d0b4c Mon Sep 17 00:00:00 2001 From: sky Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] improve: some websites rebuild imcomplete (#1163) * improve: mutation.ts, loop use Set replace Array * improve: add a try-catch to utils.ts to make it robust * Create yellow-mails-cheat.md --------- Co-authored-by: Yun Feng --- .changeset/yellow-mails-cheat.md | 8 ++++++++ packages/rrweb/src/record/mutation.ts | 4 ++-- packages/rrweb/src/utils.ts | 14 +++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 .changeset/yellow-mails-cheat.md diff --git a/.changeset/yellow-mails-cheat.md b/.changeset/yellow-mails-cheat.md new file mode 100644 index 00000000..28946967 --- /dev/null +++ b/.changeset/yellow-mails-cheat.md @@ -0,0 +1,8 @@ +--- +'rrweb': patch +--- + +Fix: some websites rebuild imcomplete + +1. Some websites, addedSet in emit function is not empty, but the result converted from Array.from is empty. +2. Some websites polyfill classList functions of HTML elements. Their implementation may throw errors and cause the snapshot to fail. I add try-catch statements to make the code robust. diff --git a/packages/rrweb/src/record/mutation.ts b/packages/rrweb/src/record/mutation.ts index c6d20b7f..704a965b 100644 --- a/packages/rrweb/src/record/mutation.ts +++ b/packages/rrweb/src/record/mutation.ts @@ -333,7 +333,7 @@ export default class MutationBuffer { this.mirror.removeNodeFromMap(this.mapRemoves.shift()!); } - for (const n of Array.from(this.movedSet.values())) { + for (const n of this.movedSet) { if ( isParentRemoved(this.removes, n, this.mirror) && !this.movedSet.has(n.parentNode!) @@ -343,7 +343,7 @@ export default class MutationBuffer { pushAdd(n); } - for (const n of Array.from(this.addedSet.values())) { + for (const n of this.addedSet) { if ( !isAncestorInSet(this.droppedSet, n) && !isParentRemoved(this.removes, n, this.mirror) diff --git a/packages/rrweb/src/utils.ts b/packages/rrweb/src/utils.ts index 510139af..26dc6388 100644 --- a/packages/rrweb/src/utils.ts +++ b/packages/rrweb/src/utils.ts @@ -229,11 +229,15 @@ export function isBlocked( : node.parentElement; if (!el) return false; - if (typeof blockClass === 'string') { - if (el.classList.contains(blockClass)) return true; - if (checkAncestors && el.closest('.' + blockClass) !== null) return true; - } else { - if (classMatchesRegex(el, blockClass, checkAncestors)) return true; + try { + if (typeof blockClass === 'string') { + if (el.classList.contains(blockClass)) return true; + if (checkAncestors && el.closest('.' + blockClass) !== null) return true; + } else { + if (classMatchesRegex(el, blockClass, checkAncestors)) return true; + } + } catch (e) { + // e } if (blockSelector) { if (el.matches(blockSelector)) return true;