Skip to content
Skip to the article
In Git & Dev Tools: 3 articles
Git & Dev Tools

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.

Updated
Applies to
  • Chrome
  • Firefox
  • Edge
Tags
  • javascript
  • debugging
  • browser
  • bookmarklet
Reading time
3 min

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

  1. Show the bookmarks bar (Ctrl+Shift+B, or Cmd+Shift+B on macOS).

  2. Right-click the bar and choose Add page (Chrome, Edge) or Add Bookmark (Firefox).

  3. Name it List Globals and 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.someConfigObject

Limitations

  • Variables declared at the top level with let, const, or class don't become window properties, so they don't appear. Only var, function declarations, and explicit window.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.