Skip to content

Instantly share code, notes, and snippets.

@grabcode
Last active February 2, 2016 10:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grabcode/8f350d5231e266c3934e to your computer and use it in GitHub Desktop.
Save grabcode/8f350d5231e266c3934e to your computer and use it in GitHub Desktop.
Explore or Spy the global variables available, or any given scope. By default, it run in the global browser scope `window`, and exclude its default properties.
/*
* Explore/Spy App Global variables, excluding defaults (defaults comes down a scope)
* > Run me in your dev tool console via copy/pasting
* > In return, I provide a list of keys, and copy in your clipboard (how sweet is that!)
*
* Follow my creator https://twitter.com/grabthecode
*/
;(function(scope, defaults){
var excluded = [];
switch(Object.prototype.toString.call(defaults)){
case '[object Function]':
excluded = defaults(); //expecting an array, don't be a bitch
break;
case '[object Array]':
excluded = defaults;
break;
case '[object String]':
excluded = [defaults]
break;
}
var cache = [];
var circularStructHandler = function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
return value;
}
var keys = [];
var props = Object.keys(scope).reduce(function(memo, key){
if(scope.hasOwnProperty(key) && excluded.indexOf(key)==-1){
keys.push(key);
var entity = scope[key]
var type = Object.prototype.toString.call(entity);
var value;
switch(type) {
case '[object Function]':
value = Function.prototype.toString.call(entity)
break;
default:
value = JSON.stringify(entity, circularStructHandler)
}
memo.push({
key: key,
type: type,
value: value
});
}
return memo;
}, []);
console.table(props);
copy(JSON.stringify(keys));
console.log("Copied in clipboard");
})(this, function windowsStdGlobals(){
// window "standard" globals in chrome as of today - Version 47.0.2526.111
return ["external","chrome","document","props","b","speechSynthesis","caches","localStorage","sessionStorage","webkitStorageInfo","indexedDB","webkitIndexedDB","ondeviceorientation","ondevicemotion","crypto","postMessage","blur","focus","close","onautocompleteerror","onautocomplete","applicationCache","performance","onunload","onstorage","onpopstate","onpageshow","onpagehide","ononline","onoffline","onmessage","onlanguagechange","onhashchange","onbeforeunload","onwaiting","onvolumechange","ontoggle","ontimeupdate","onsuspend","onsubmit","onstalled","onshow","onselect","onseeking","onseeked","onscroll","onresize","onreset","onratechange","onprogress","onplaying","onplay","onpause","onmousewheel","onmouseup","onmouseover","onmouseout","onmousemove","onmouseleave","onmouseenter","onmousedown","onloadstart","onloadedmetadata","onloadeddata","onload","onkeyup","onkeypress","onkeydown","oninvalid","oninput","onfocus","onerror","onended","onemptied","ondurationchange","ondrop","ondragstart","ondragover","ondragleave","ondragenter","ondragend","ondrag","ondblclick","oncuechange","oncontextmenu","onclose","onclick","onchange","oncanplaythrough","oncanplay","oncancel","onblur","onabort","isSecureContext","onwheel","onwebkittransitionend","onwebkitanimationstart","onwebkitanimationiteration","onwebkitanimationend","ontransitionend","onsearch","onanimationstart","onanimationiteration","onanimationend","styleMedia","defaultstatus","defaultStatus","screenTop","screenLeft","clientInformation","console","devicePixelRatio","outerHeight","outerWidth","screenY","screenX","pageYOffset","scrollY","pageXOffset","scrollX","innerHeight","innerWidth","screen","navigator","frameElement","parent","opener","top","length","frames","closed","status","toolbar","statusbar","scrollbars","personalbar","menubar","locationbar","history","location","name","self","window","stop","open","alert","confirm","prompt","print","requestAnimationFrame","cancelAnimationFrame","captureEvents","releaseEvents","getComputedStyle","matchMedia","moveTo","moveBy","resizeTo","resizeBy","getSelection","find","getMatchedCSSRules","webkitRequestAnimationFrame","webkitCancelAnimationFrame","webkitCancelRequestAnimationFrame","btoa","atob","setTimeout","clearTimeout","setInterval","clearInterval","requestIdleCallback","cancelIdleCallback","scroll","scrollTo","scrollBy","fetch","webkitRequestFileSystem","webkitResolveLocalFileSystemURL","openDatabase"];
});
@grabcode
Copy link
Author

When run on this page:
screen shot 2016-01-27 at 1 07 07 pm

Copied into the clipboard (ctrl+c)

["script1453856046274","define","require","setImmediate","clearImmediate","JsMutationObserver","CustomElements","unwrap","wrap","$","jQuery","_perfRefForUserTimingPolyfill","regeneratorRuntime","SelectorSet","ZeroClipboard","IncludeFragmentElement","PollIncludeFragmentElement","RelativeTimeElement","TimeAgoElement","LocalTimeElement","GitHub","_octo","d3Ready","ga","gaplugins","GoogleAnalyticsObject","gaGlobal","ReconnectingWebSocket","jstz","DateInput","u2f"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment