Skip to content

Commit

Permalink
[HIG-2269] ensure invalid DOM nesting doesn't crash rrweb (#73)
Browse files Browse the repository at this point in the history
Replaying an app with invalid DOM nesting may crash rrweb.
Print console warning instead of crashing.
  • Loading branch information
Vadman97 authored May 11, 2022
1 parent a3c43bb commit 5c10bf7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@highlight-run/rrweb",
"version": "1.2.0",
"version": "1.2.1",
"description": "record and replay the web",
"scripts": {
"test": "npm run bundle:browser && cross-env TS_NODE_CACHE=false TS_NODE_FILES=true mocha -r ts-node/register -r ignore-styles -r jsdom-global/register test/**.test.ts",
Expand Down
12 changes: 9 additions & 3 deletions src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1964,9 +1964,15 @@ export class Replayer {
) {
((parent as unknown) as HTMLTextAreaElement).value = frag.textContent;
}
parent.appendChild(frag);
// restore state of elements after they are mounted
this.restoreState(parent);
try {
parent.appendChild(frag);
// restore state of elements after they are mounted
this.restoreState(parent);
} catch (error) {
// this is likely due to a recording with
// invalid DOM nesting (a div under a p). don't crash rrweb in this case.
console.warn(error)
}
}

/**
Expand Down

0 comments on commit 5c10bf7

Please sign in to comment.