Created
August 14, 2019 18:09
-
-
Save iiic/7c2c750587d6afea35d52043f35fc09a to your computer and use it in GitHub Desktop.
it's part of Chrome Lighthouse test, but this is separated
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
'use strict'; | |
function lighthouseDomTest ( /** @type {Element} */ rootElement ) | |
{ | |
let maxDepth = 0; | |
let maxDepthElement = null; | |
let mostChildren = 0; | |
let mostChildrenElement = null; | |
let allElements = rootElement.querySelectorAll( '*' ); | |
allElements.forEach( ( element ) => | |
{ | |
let currentElement = element; | |
if ( !currentElement.children.length ) { | |
let steps = 0; | |
while ( currentElement !== rootElement ) { | |
steps++; | |
currentElement = currentElement.parentElement; | |
} | |
if ( maxDepth < steps ) { | |
maxDepth = steps; | |
maxDepthElement = element; | |
} | |
} | |
if ( element.children.length > mostChildren ) { | |
mostChildren = element.children.length; | |
mostChildrenElement = element; | |
} | |
} ); | |
return { | |
'totalElementNodes': allElements.length, | |
'maxDepth': maxDepth, | |
'maxDepthElement': maxDepthElement, | |
'mostChildren': mostChildren, | |
'mostChildrenInElement': mostChildrenElement, | |
}; | |
} | |
lighthouseDomTest( document.body ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://developers.google.com/web/tools/lighthouse/audits/dom-size