diff --git a/script/analyseFrame.js b/script/analyseFrame.js index 84640e6..dabec09 100644 --- a/script/analyseFrame.js +++ b/script/analyseFrame.js @@ -16,6 +16,24 @@ * along with this program. If not, see . */ +function countShadom() { + const countElements = (element) => { + let count = 1; + Array.from(element.children).forEach(child => { + count += countElements(child); + }); + + if (element.shadowRoot) { + Array.from(element.shadowRoot.children).forEach(sChild => { + count += countElements(sChild); + }); + } + return count; + }; + + return countElements(document.body) +} + function start_analyse() { const analyseStartingTime = Date.now(); const dom_size = getDomSizeWithoutSvg(); @@ -28,7 +46,7 @@ function start_analyse() { } function getDomSizeWithoutSvg(){ - let dom_size = document.getElementsByTagName("*").length; + let dom_size = countShadom(); const svgElements = document.getElementsByTagName("svg"); for (let i = 0 ; i< svgElements.length ; i++) { dom_size -= getNbChildsExcludingNestedSvg(svgElements[i])-1; diff --git a/script/analyseFrameWithBestPractices.js b/script/analyseFrameWithBestPractices.js index 20ca136..cf8aa92 100644 --- a/script/analyseFrameWithBestPractices.js +++ b/script/analyseFrameWithBestPractices.js @@ -16,6 +16,24 @@ * along with this program. If not, see . */ +function countShadom() { + const countElements = (element) => { + let count = 1; + Array.from(element.children).forEach(child => { + count += countElements(child); + }); + + if (element.shadowRoot) { + Array.from(element.shadowRoot.children).forEach(sChild => { + count += countElements(sChild); + }); + } + return count; + }; + + return countElements(document.body) +} + function start_analyse() { const analyseStartingTime = Date.now(); const dom_size = getDomSizeWithoutSvg(); @@ -42,7 +60,7 @@ function start_analyse() { } function getDomSizeWithoutSvg() { - let dom_size = document.getElementsByTagName("*").length; + let dom_size = countShadom(); const svgElements = document.getElementsByTagName("svg"); for (let i = 0; i < svgElements.length; i++) { dom_size -= getNbChildsExcludingNestedSvg(svgElements[i]) - 1;