Created
August 31, 2018 17:12
-
-
Save rcherny/f3c480571dd4476b43d5431f3afaba7a to your computer and use it in GitHub Desktop.
Get Non-Window Scope Globals
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
delete keysfromscript; | |
delete wholeset; | |
try { | |
var keysfromscript = []; | |
} catch(e) { | |
keysfromscript = []; | |
} | |
try { | |
var wholeset = []; | |
} catch(e) { | |
wholeset = []; | |
} | |
function collectThese(){ | |
var iframe = document.createElement('iframe'); | |
iframe.src = "about:blank"; | |
document.body.appendChild(iframe); | |
var windowVars = Object.keys(iframe.contentWindow); | |
var globalVars = Object.keys(window).filter(key => !windowVars.includes(key)); | |
console.log("global Vars:", globalVars); | |
keysfromscript = globalVars; | |
keysfromscript.forEach(function(currentVal, idx, arr){ | |
wholeset.push({ | |
key: keysfromscript[idx], | |
value: window[currentVal] | |
}) | |
}); | |
console.table(wholeset); | |
document.body.removeChild(iframe); | |
}; | |
collectThese(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment