I used this recur method to accomplish this from this Stackoverflow answer.
If you want to do this yourself, do it in an about:blank page because it will load the current page and may crash your browser.
function recur(obj, visited = new WeakSet()) {
if (visited.has(obj)) return {}; // skip already visited object to prevent cycles
visited.add(obj); // add the current object to the visited set
var result = {},
_tmp;
for (var i in obj) {
if (i === "nextElementSibling" || i === "style") continue;
try {
// enabledPlugin is too nested, also skip functions
if (i === 'enabledPlugin' || typeof obj[i] === 'function') {
continue;
} else if (typeof obj[i] === 'object') {
// get props recursively
_tmp = recur(obj[i], visited);
// if object is not {}
if (Object.keys(_tmp).length) result[i] = _tmp;
} else {
result[i] = obj[i]; // string, number or boolean
}
} catch (error) {
// handle error, you can log it here if needed
// console.error('Error:', error);
}
}
return result;
}
JSON.stringify(recur(window));