-
-
Save zazaulola/c1c2e80bdeeff8ad14399cf1724f9854 to your computer and use it in GitHub Desktop.
Recursively find all shadow roots in a page.
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
/** | |
* Find all elements with openned ShadowRoots | |
* | |
* @param {Node} e - An element that we should search for ShadowRoots within. | |
* @returns {Array<Element>} Array of Elements that holds ShadowRoot | |
*/ | |
const findRoots = (e = document.documentElement) => | |
[e,...e.querySelectorAll('*')] | |
.filter(e => e.shadowRoot) | |
.flatMap(e => [e, ...findRoots(e.shadowRoot)]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment