diff --git a/lib/core/utils/dq-element.js b/lib/core/utils/dq-element.js index 373675e3..74b5965d 100644 --- a/lib/core/utils/dq-element.js +++ b/lib/core/utils/dq-element.js @@ -174,10 +174,10 @@ function getSource(element) { if (!source && typeof window.XMLSerializer === 'function') { source = new window.XMLSerializer().serializeToString(element); } - let htmlString = truncate(source || ''); // Remove unwanted attributes - const regex = /\s*data-percy-[^=]+="[^"]*"/g; - htmlString = htmlString.replace(regex, ''); + const regex = /\s*data-percy-[^=]+="[^"]*"/g; // Remove unwanted attributes + source = (source || '').replace(regex, ''); + const htmlString = truncate(source); return htmlString; }