Last active
July 11, 2017 11:23
-
-
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
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
/* | |
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