Skip to content

PoC clone node #1897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions injected/src/features/element-hiding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
});
Expand Down
Loading