Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://stackoverflow.com/a/52693392/10559302
- /*
- It filters Object.keys(window) based on three principles:
- 1. Things that are null or undefined are usually not interesting to look at.
- 2. Most scripts will define a bunch of event handlers (i.e. functions) but they are also usually not interesting to dump out.
- 3. Properties on window that are set by the browser itself, are usually defined in a special way, and their property descriptors reflect that. Globals defined with the assignment operator (i.e. 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.
- */
- 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)
- /*
- An interactive way to 'search' would be opening the devtools (e.g. in chrome) typing window + Enter and then click the triangle to expand the object tree.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement