Yes, you can! You will need to repeat some logic to create this tree, but for your example, you can do something like:
var tracker = {}; Array.from(document.querySelectorAll("*")).forEach(node => { if (!tracker[node.tagName]) tracker[node.tagName] = 1; else tracker[node.tagName]++; }); console.log(tracker);
You can change this to work on a recrusive subset of childNodes. It just repeats the whole document.
Check this script and open the console to see the result of the tracker , which counts and lists the tag names. To add depth, just take parentNode.length to the end.
Here the script is updated, which, it seems to me, corresponds to the number of depths;
var tracker = {}; var depth = 0; var prevNode; Array.from(document.querySelectorAll("*")).forEach(node => { if (!tracker[node.tagName]) tracker[node.tagName] = 1; else tracker[node.tagName]++; console.log("Node depth:", node.tagName, depth); if (node.parentNode != prevNode) depth++; prevNode = node; }); console.log(tracker);
source share