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 diff --git a/packages/rrweb/src/replay/index.ts b/packages/rrweb/src/replay/index.ts index 5dacdc104d..5e6ed981a9 100644 --- a/packages/rrweb/src/replay/index.ts +++ b/packages/rrweb/src/replay/index.ts @@ -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)) {