-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckForShadowDom.js
More file actions
32 lines (27 loc) · 1 KB
/
checkForShadowDom.js
File metadata and controls
32 lines (27 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function hasShadowRoot(element) {
return element.shadowRoot !== null && element.shadowRoot !== undefined;
}
// Function to recursively traverse the DOM and check for shadow roots
function findShadowDOMElements(node, shadowDOMElements) {
if (node.nodeType === Node.ELEMENT_NODE) {
if (hasShadowRoot(node)) {
shadowDOMElements.push(node);
}
// Recursively check children
for (let i = 0; i < node.childNodes.length; i++) {
findShadowDOMElements(node.childNodes[i], shadowDOMElements);
}
}
}
// Entry point
function checkForShadowDOM() {
const shadowDOMElements = [];
findShadowDOMElements(document.body, shadowDOMElements);
if (shadowDOMElements.length > 0) {
return("The page contains instances of Shadow DOM. Elements with Shadow DOM:", shadowDOMElements);
} else {
return("The page does not contain any instances of Shadow DOM.");
}
}
// Call the function to check for shadow DOM elements
checkForShadowDOM();