From 4a46f36a0d9937bd499e1e5dd8df98ee86311db3 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 15 Aug 2025 16:58:08 +0100 Subject: [PATCH 1/6] PoC clone node --- injected/src/features/element-hiding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/injected/src/features/element-hiding.js b/injected/src/features/element-hiding.js index 5c4aaf0cb4..7d6c7ed519 100644 --- a/injected/src/features/element-hiding.js +++ b/injected/src/features/element-hiding.js @@ -147,7 +147,7 @@ function isDomNodeEmpty(node) { } // use a DOMParser to remove all metadata elements before checking if // the node is empty. - const parsedNode = parser.parseFromString(node.outerHTML, 'text/html').documentElement; + const parsedNode = node.cloneNode(); parsedNode.querySelectorAll('base,link,meta,script,style,template,title,desc').forEach((el) => { el.remove(); }); From 2b1f6873f8e6e8122842683a02e716b662af738c Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 15 Aug 2025 17:51:24 +0100 Subject: [PATCH 2/6] Update element-hiding.js --- injected/src/features/element-hiding.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/injected/src/features/element-hiding.js b/injected/src/features/element-hiding.js index 7d6c7ed519..9e8d95b037 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(); @@ -147,7 +146,7 @@ function isDomNodeEmpty(node) { } // use a DOMParser to remove all metadata elements before checking if // the node is empty. - const parsedNode = node.cloneNode(); + const parsedNode = /** @type {Element} */(node.cloneNode()); parsedNode.querySelectorAll('base,link,meta,script,style,template,title,desc').forEach((el) => { el.remove(); }); From be59a7ee1caea6889fd97d64c00d8cce287fba40 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 15 Aug 2025 17:53:19 +0100 Subject: [PATCH 3/6] Update element-hiding.js --- injected/src/features/element-hiding.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/injected/src/features/element-hiding.js b/injected/src/features/element-hiding.js index 9e8d95b037..d32760d38a 100644 --- a/injected/src/features/element-hiding.js +++ b/injected/src/features/element-hiding.js @@ -144,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 = /** @type {Element} */(node.cloneNode()); + if (!parsedNode) { + return false; + } parsedNode.querySelectorAll('base,link,meta,script,style,template,title,desc').forEach((el) => { el.remove(); }); From 6db4d56d7cf3349db2b29905940fe2557db3c43b Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 15 Aug 2025 19:30:45 +0100 Subject: [PATCH 4/6] Update element-hiding.js --- injected/src/features/element-hiding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/injected/src/features/element-hiding.js b/injected/src/features/element-hiding.js index d32760d38a..ed6f381901 100644 --- a/injected/src/features/element-hiding.js +++ b/injected/src/features/element-hiding.js @@ -146,7 +146,7 @@ function isDomNodeEmpty(node) { } // use a clonedNode to remove all metadata elements before checking if // the node is empty. - const parsedNode = /** @type {Element} */(node.cloneNode()); + const parsedNode = /** @type {HTMLElement} */(node.cloneNode()); if (!parsedNode) { return false; } From fae35c784aad798a2a74fc5e33fd1f98bae30edf Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 15 Aug 2025 20:33:56 +0100 Subject: [PATCH 5/6] Lint fix --- injected/src/features/element-hiding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/injected/src/features/element-hiding.js b/injected/src/features/element-hiding.js index ed6f381901..f46a9ae669 100644 --- a/injected/src/features/element-hiding.js +++ b/injected/src/features/element-hiding.js @@ -146,7 +146,7 @@ function isDomNodeEmpty(node) { } // use a clonedNode to remove all metadata elements before checking if // the node is empty. - const parsedNode = /** @type {HTMLElement} */(node.cloneNode()); + const parsedNode = /** @type {HTMLElement} */ (node.cloneNode()); if (!parsedNode) { return false; } From b2f82ed27f16f5b2255a4d68fca2c8cb16748474 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 15 Aug 2025 20:49:26 +0100 Subject: [PATCH 6/6] Update element-hiding.js --- injected/src/features/element-hiding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/injected/src/features/element-hiding.js b/injected/src/features/element-hiding.js index f46a9ae669..9cd3db312a 100644 --- a/injected/src/features/element-hiding.js +++ b/injected/src/features/element-hiding.js @@ -146,7 +146,7 @@ function isDomNodeEmpty(node) { } // use a clonedNode to remove all metadata elements before checking if // the node is empty. - const parsedNode = /** @type {HTMLElement} */ (node.cloneNode()); + const parsedNode = /** @type {HTMLElement} */ (node.cloneNode(true)); if (!parsedNode) { return false; }