Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add a try/catch to provide some robustness in case `document.implemen…
…tation.createHTMLDocument` isn't available
  • Loading branch information
eoghanmurray committed Apr 13, 2023
commit f36073da7a8ba93b1f956c0d1db286ea72cc36c5
9 changes: 8 additions & 1 deletion packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,14 @@ export default class MutationBuffer {
if (isIgnored(m.target, this.mirror)) {
return;
}
const unattachedDoc = document.implementation.createHTMLDocument(); // avoid upsetting original document from a Content Security point of view
let unattachedDoc;
try {
// avoid upsetting original document from a Content Security point of view
unattachedDoc = document.implementation.createHTMLDocument();
} catch (e) {
// fallback to more direct method
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know when we will fallback? I'm curious what would trigger errors and the fallback case? Unsupported browsers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just not 100% about that document.implementation.createHTMLDocument(); so took the prudent option of falling back to the previous method (which is working fine but wouldn't work for you from a CSP POV)

I just looked it up now and it seems fine:
https://caniuse.com/?search=implementation.createhtmldocument
E.g. it could fail on IE11 as there is a 'title' attribute missing
I don't think anyone is supporting IE11

You could add some reporting in there if it happens, or to add a custom commit on top (for your deployment) to revert this last commit.
I'm putting this out to a 'canary' environment today, but I don't have any reporting on whether the fallback kicks in; I'm happy enough that it worked in the rrweb test environment (Puppeteer/Chrome).

unattachedDoc = this.doc;
}
switch (m.type) {
case 'characterData': {
const value = m.target.textContent;
Expand Down