From bb44001eaebb5f8a6f7edf7d649d24934df5ab5c Mon Sep 17 00:00:00 2001 From: Michael Dellanoce Date: Wed, 30 Aug 2023 13:51:17 -0400 Subject: [PATCH] only call createHTMLDocument where it is needed --- packages/rrweb/src/record/mutation.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/rrweb/src/record/mutation.ts b/packages/rrweb/src/record/mutation.ts index 097d1a8fd5..53eb072c86 100644 --- a/packages/rrweb/src/record/mutation.ts +++ b/packages/rrweb/src/record/mutation.ts @@ -497,14 +497,6 @@ 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; @@ -597,6 +589,14 @@ export default class MutationBuffer { value, ); if (attributeName === 'style') { + 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; + } const old = unattachedDoc.createElement('span'); if (m.oldValue) { old.setAttribute('style', m.oldValue);