Skip to content

Commit 499079a

Browse files
committed
fix(snapshot): Do not create CDATA node on HTMLDocument
`createCDATASection` is [only supported on XMLDocument](https://developer.mozilla.org/en-US/docs/Web/API/Document/createCDATASection#notes), not HTMLDocument. Doing so on HTMLDocument will throw an exception and break playback on the player. This change will log a "Failed to rebuild" warning to the console instead of throwing.
1 parent b0b91f8 commit 499079a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/rrweb-snapshot/src/rebuild.ts

+6
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ function buildNode(
360360
: n.textContent,
361361
);
362362
case NodeType.CDATA:
363+
// `createCDATASection` only works for XML documents (not HTML)
364+
// https://developer.mozilla.org/en-US/docs/Web/API/Document/createCDATASection#notes
365+
if (!(doc instanceof XMLDocument)) {
366+
return null;
367+
}
368+
363369
return doc.createCDATASection(n.textContent);
364370
case NodeType.Comment:
365371
return doc.createComment(n.textContent);

0 commit comments

Comments
 (0)