Created
December 28, 2020 16:38
-
-
Save bcruddy/fc99873729883223035c69ed68c7432c 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 forEachFrame (fn, targetWindow = window, filter = () => null) { | |
const frames = targetWindow.document.querySelectorAll('iframe, frame'); | |
for (const frame of frames) { | |
if (filter(frame)) { | |
continue; | |
} | |
try { | |
fn(frame.contentWindow, frame); | |
} catch (err) { | |
console.warn('failed to access child frame', err.toString()); | |
} | |
try { | |
forEachFrame(fn, frame.contentWindow); | |
} catch (err) { | |
console.warn('failed to access nested child frame', err.toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment