From 3c4284a7278add279b4819462950719a348e458e Mon Sep 17 00:00:00 2001 From: io agudo Date: Mon, 13 Jan 2025 17:30:09 -0500 Subject: [PATCH 1/4] fix: workarounf to avoid the replayer cratches when trying to append a document to a non iframe --- packages/rrweb/src/replay/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/rrweb/src/replay/index.ts b/packages/rrweb/src/replay/index.ts index 5dacdc104d..ecb5362600 100644 --- a/packages/rrweb/src/replay/index.ts +++ b/packages/rrweb/src/replay/index.ts @@ -173,7 +173,7 @@ export class Replayer { | styleSheetRuleData | styleDeclarationData )[] = []; - + // Similar to the reason for constructedStyleMutations. private adoptedStyleSheets: adoptedStyleSheetData[] = []; @@ -1509,6 +1509,18 @@ export class Replayer { return queue.push(mutation); } + if ( + mutation.node.type === NodeType.Document && + parent?.nodeName?.toLowerCase() !== 'iframe' + ) { + console.warn( + '[Replayer] Skipping invalid document append to a non-iframe parent.', + mutation, + parent + ); + return; + } + if (mutation.node.isShadow) { // If the parent is attached a shadow dom after it's created, it won't have a shadow root. if (!hasShadowRoot(parent)) { From 9c286b9785d9ec142b013d2a027535a91c34425a Mon Sep 17 00:00:00 2001 From: io agudo Date: Mon, 13 Jan 2025 17:31:22 -0500 Subject: [PATCH 2/4] fix: delete space --- packages/rrweb/src/replay/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rrweb/src/replay/index.ts b/packages/rrweb/src/replay/index.ts index ecb5362600..e84d8e3974 100644 --- a/packages/rrweb/src/replay/index.ts +++ b/packages/rrweb/src/replay/index.ts @@ -173,7 +173,7 @@ export class Replayer { | styleSheetRuleData | styleDeclarationData )[] = []; - + // Similar to the reason for constructedStyleMutations. private adoptedStyleSheets: adoptedStyleSheetData[] = []; From befdb8671cee8b83c4da3c5f87f807221e32774d Mon Sep 17 00:00:00 2001 From: io agudo Date: Tue, 14 Jan 2025 10:50:12 -0500 Subject: [PATCH 3/4] fix: fix format --- packages/rrweb/src/replay/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rrweb/src/replay/index.ts b/packages/rrweb/src/replay/index.ts index e84d8e3974..5e6ed981a9 100644 --- a/packages/rrweb/src/replay/index.ts +++ b/packages/rrweb/src/replay/index.ts @@ -1516,7 +1516,7 @@ export class Replayer { console.warn( '[Replayer] Skipping invalid document append to a non-iframe parent.', mutation, - parent + parent, ); return; } From acf9fbf1781e64c74ac86c920f957e36d37d9d58 Mon Sep 17 00:00:00 2001 From: io agudo Date: Wed, 15 Jan 2025 09:09:07 -0500 Subject: [PATCH 4/4] feat: add changeset --- .changeset/brave-planes-begin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/brave-planes-begin.md diff --git a/.changeset/brave-planes-begin.md b/.changeset/brave-planes-begin.md new file mode 100644 index 0000000000..4913852244 --- /dev/null +++ b/.changeset/brave-planes-begin.md @@ -0,0 +1,5 @@ +--- +"rrweb": patch +--- + +Workaround for avoid the replayer from crashing when there's an error when trying to attach a document to a non-iframe