diff --git a/injected/src/features/element-hiding.js b/injected/src/features/element-hiding.js index 5c4aaf0cb4..9cd3db312a 100644 --- a/injected/src/features/element-hiding.js +++ b/injected/src/features/element-hiding.js @@ -2,7 +2,6 @@ import ContentFeature from '../content-feature'; import { isBeingFramed, injectGlobalStyles } from '../utils'; let adLabelStrings = []; -const parser = new DOMParser(); let hiddenElements = new WeakMap(); let modifiedElements = new WeakMap(); let appliedRules = new Set(); @@ -145,9 +144,12 @@ function isDomNodeEmpty(node) { if (node.tagName === 'BODY') { return false; } - // use a DOMParser to remove all metadata elements before checking if + // use a clonedNode to remove all metadata elements before checking if // the node is empty. - const parsedNode = parser.parseFromString(node.outerHTML, 'text/html').documentElement; + const parsedNode = /** @type {HTMLElement} */ (node.cloneNode(true)); + if (!parsedNode) { + return false; + } parsedNode.querySelectorAll('base,link,meta,script,style,template,title,desc').forEach((el) => { el.remove(); });