What is the way to list all global variables that have been used by the site? Can any browser javascript debugger do that? By used I mean READ, not changed/added. Detect ifr
This one-liner will get you pretty close, and does not require installing anything additional, or running code before the page loads:
Object.keys(window).filter(x => typeof(window[x]) !== 'function' &&
Object.entries(
Object.getOwnPropertyDescriptor(window, x)).filter(e =>
['value', 'writable', 'enumerable', 'configurable'].includes(e[0]) && e[1]
).length === 4)
It filters Object.keys(window) based on three principles:
window.foo = 'bar'
) have a specific-looking property descriptor, and we can leverage that. Note, if the script defines properties using Object.defineProperty with a different descriptor, we'll miss them, but this is very rare in practice.