Skip to content

Instantly share code, notes, and snippets.

@rcherny
Created August 31, 2018 17:12
Show Gist options
  • Save rcherny/f3c480571dd4476b43d5431f3afaba7a to your computer and use it in GitHub Desktop.
Save rcherny/f3c480571dd4476b43d5431f3afaba7a to your computer and use it in GitHub Desktop.
Get Non-Window Scope Globals
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