Created
October 3, 2022 16:33
-
-
Save ThomazPom/1e57e416c4b111b27e3d44d640cfb920 to your computer and use it in GitHub Desktop.
This file contains 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 discoverAllShadowRoots(){ | |
let shadowroots = [] | |
function discover(elem){ | |
let elemshadowroots = [...elem.querySelectorAll("*")] | |
elemshadowroots.push(elem) | |
elemshadowroots=elemshadowroots.map(z=>z.shadowRoot).filter(z=>z) | |
elemshadowroots.forEach(discover) | |
shadowroots.push(...elemshadowroots) | |
} | |
discover(document.body) | |
return shadowroots; | |
} | |
document.querySelectorAllShadowRoot = function(selector){ | |
let shadowRoots = discoverAllShadowRoots() | |
for (let index = 0; index < shadowRoots.length; index++) { | |
const sr = shadowRoots[index]; | |
srsl = sr.querySelector(selector) | |
if(srsl) | |
{ | |
return srsl | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment