From 5e391d0bf89726182e1b9b7571c7a1c47316018e Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Sat, 26 Feb 2022 17:42:25 +0000 Subject: [PATCH] Fix for #816 - avoid triggering a CSP (content security policy) error with `.setAttribute('style')` --- packages/rrweb/src/record/mutation.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/rrweb/src/record/mutation.ts b/packages/rrweb/src/record/mutation.ts index 205a9220d5..481f93c2e2 100644 --- a/packages/rrweb/src/record/mutation.ts +++ b/packages/rrweb/src/record/mutation.ts @@ -426,6 +426,7 @@ export default class MutationBuffer { if (isIgnored(m.target)) { return; } + const unattachedDoc = new Document(); // needed to avoid upsetting original document from a Content Security point of view switch (m.type) { case 'characterData': { const value = m.target.textContent; @@ -472,7 +473,7 @@ export default class MutationBuffer { this.attributes.push(item); } if (m.attributeName === 'style') { - const old = this.doc.createElement('span'); + const old = unattachedDoc.createElement('span'); if (m.oldValue) { old.setAttribute('style', m.oldValue); }