diff --git a/packages/rrweb/src/record/mutation.ts b/packages/rrweb/src/record/mutation.ts index 337394acf1..f352424b5f 100644 --- a/packages/rrweb/src/record/mutation.ts +++ b/packages/rrweb/src/record/mutation.ts @@ -472,6 +472,14 @@ export default class MutationBuffer { if (isIgnored(m.target, this.mirror)) { return; } + 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 + unattachedDoc = this.doc; + } switch (m.type) { case 'characterData': { const value = m.target.textContent; @@ -554,7 +562,7 @@ export default class MutationBuffer { } if (attributeName === 'style') { - const old = this.doc.createElement('span'); + const old = unattachedDoc.createElement('span'); if (m.oldValue) { old.setAttribute('style', m.oldValue); }