Skip to content

Instantly share code, notes, and snippets.

@felquis
Last active July 11, 2017 11:23
Show Gist options
  • Save felquis/c8f610697024aeb9370e to your computer and use it in GitHub Desktop.
Save felquis/c8f610697024aeb9370e to your computer and use it in GitHub Desktop.
Find global variables in the browser, discover global variables a web side is exposing in JavaScript
/*
Usage
global.get() // return Array of globals found
*/
;(function (global) {
function Globals () {}
var getWindow = function () {
var iframe = document.createElement('iframe')
iframe.style.display = 'none'
document.body.appendChild(iframe)
var result = iframe.contentWindow || iframe.contentDocument
iframe.parentElement.removeChild(iframe)
return result
}
Globals.prototype.get = function() {
var iframeWindow = getWindow()
var result = []
var property;
for (property in global) {
if (!(property in iframeWindow)) {
result.push(property)
}
}
return result
};
global.globals = new Globals();
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment