Skip to content

Instantly share code, notes, and snippets.

@pengx17
Created February 28, 2022 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pengx17/1674dfdff2aafbacf99017bc9dd376c1 to your computer and use it in GitHub Desktop.
Save pengx17/1674dfdff2aafbacf99017bc9dd376c1 to your computer and use it in GitHub Desktop.
Get all non standard variables defined in the global context
// make sure it doesn't count my own properties
(function () {
var results, currentWindow,
// create an iframe and append to body to load a clean window object
iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
// get the current list of properties on window
currentWindow = Object.getOwnPropertyNames(window);
// filter the list against the properties that exist in the clean window
results = currentWindow.filter(function(prop) {
return !iframe.contentWindow.hasOwnProperty(prop);
});
let result = {};
results.forEach(r => {
result[r] = window[r];
})
console.log(result)
document.body.removeChild(iframe);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment