Created
May 21, 2024 13:58
-
-
Save YonatanKra/5092049caec303b06f913ee5a2a62735 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getAllNestedShadowRootsParents(element) { | |
const nestedShadowRoots = []; | |
function traverseShadowRoot(node) { | |
if (node.shadowRoot) { | |
nestedShadowRoots.push(node); | |
node.shadowRoot.querySelectorAll('*').forEach(child => { | |
traverseShadowRoot(child); | |
}); | |
} else { | |
Array.from(node.querySelectorAll('*')).forEach(child => traverseShadowRoot(child)); | |
} | |
} | |
traverseShadowRoot(element); | |
return Array.from(new Set(nestedShadowRoots)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment