List a Page's Custom JavaScript Globals with a Bookmarklet
A bookmarklet that lists the global variables a web page or its scripts added to window, filtering out the browser's built-ins.
On this page
When you're debugging or reverse-engineering a site, it helps to know which global variables the page's own scripts created: configuration objects, framework instances, or library handles like jQuery or wp. This bookmarklet lists them in the browser console and saves them to window.$appGlobals for further inspection.
How It Works
The script creates a blank, hidden <iframe>. Its window object contains only the browser's built-in properties, so any property on the page's window that the iframe lacks was added by the page, its scripts, or an extension.
Comparing against a fresh iframe adapts to whichever browser and version you're using. Older versions of this bookmarklet hard-coded a list of built-in names, which went stale with every browser release.
The Script
Readable version:
(() => {
const frame = document.createElement('iframe');
frame.style.display = 'none';
document.body.appendChild(frame);
const builtins = new Set(Object.getOwnPropertyNames(frame.contentWindow));
frame.remove();
const globals = {};
for (const key of Object.getOwnPropertyNames(window)) {
if (!builtins.has(key)) {
try { globals[key] = window[key]; } catch (e) { globals[key] = '(unreadable)'; }
}
}
window.$appGlobals = globals;
console.table(Object.keys(globals).sort().map((name) => ({ name, type: typeof globals[name] })));
console.log(globals);
})();Install It
Show the bookmarks bar (
Ctrl+Shift+B, orCmd+Shift+Bon macOS).Right-click the bar and choose Add page (Chrome, Edge) or Add Bookmark (Firefox).
Name it
List Globalsand paste this single line as the URL:
javascript:(() => { const frame = document.createElement('iframe'); frame.style.display = 'none'; document.body.appendChild(frame); const builtins = new Set(Object.getOwnPropertyNames(frame.contentWindow)); frame.remove(); const globals = {}; for (const key of Object.getOwnPropertyNames(window)) { if (!builtins.has(key)) { try { globals[key] = window[key]; } catch (e) { globals[key] = '(unreadable)'; } } } window.$appGlobals = globals; console.table(Object.keys(globals).sort().map((name) => ({ name, type: typeof globals[name] }))); console.log(globals); })();Use It
Open the page, open the developer console (F12), and click the bookmark. The console shows a table of global names and their types. Then explore any of them:
$appGlobals.someConfigObjectLimitations
Variables declared at the top level with
let,const, orclassdon't becomewindowproperties, so they don't appear. Onlyvar, function declarations, and explicitwindow.x = ...assignments do.Browser extensions that inject scripts into the page show up in the list too.
Strict Content Security Policies can stop bookmarklets from running on some sites. If nothing happens, paste the readable version into the console instead.
Sources
This article is in the public domain (CC0 1.0), code samples included. Use it however helps you.