Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created May 21, 2024 13:58
Show Gist options
  • Save YonatanKra/5092049caec303b06f913ee5a2a62735 to your computer and use it in GitHub Desktop.
Save YonatanKra/5092049caec303b06f913ee5a2a62735 to your computer and use it in GitHub Desktop.
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