Created
March 5, 2023 00:57
-
-
Save mkropat/4700713333561de748e27cdb9c915864 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
objs = new Set | |
nameToObj = new Map | |
function t(obj) { | |
if (!obj || objs.has(obj) || typeof obj !== 'object') { return } | |
if (obj.nodeName === 'IFRAME') { return } // iframe descendants can cause security errors | |
objs.add(obj) | |
let proto = Object.getPrototypeOf(obj) | |
let name = (obj.constructor && obj.constructor.name) || (proto && proto.constructor && proto.constructor.name) | |
if (!nameToObj.has(name)) { nameToObj.set(name, []) } | |
nameToObj.get(name).push(obj) | |
for (let key of Reflect.ownKeys(obj)) { | |
try { | |
t(obj[key]) | |
} catch (err) { } | |
} | |
t(proto) | |
if (obj[Symbol.iterator]) { | |
for (let item of obj) { t(item) } | |
} | |
} | |
t(window) | |
objs = [...objs] | |
nameToObj = Object.fromEntries(nameToObj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment