Is the code to get _domContentLoadedTime correct?
yagikota opened this issue · comments
Your question
I am trying to get performance metrics for a site I accessed using the browsertime command.
browsertime https://www.youtube.com/ -n 1 --headless true --b chrome
For example, part of the HAR file obtained by executing the above command looks like this:
"pageTimings": {
"onContentLoad": 3344.498,
"onLoad": 4376.424,
"_firstPaint": 2887,
"_largestContentfulPaint": 3992,
"_firstContentfulPaint": 2887,
"_domInteractiveTime": 3345,
"_domContentLoadedTime": 3345
},
I have a question about how to get the _domContentLoadedTime
shown here. Looking at this code, I see that you are using domContentLoadedEventStart
to get _domContentLoadedTime
, is this correct?
According to MDN
The DOMContentLoaded event fires when the HTML document has been completely parsed, and all deferred scripts (<script defer src="…"> and <script type="module">) have downloaded and executed. It doesn't wait for other things like images, subframes, and async scripts to finish loading.
So, I think _domContentLoadedTime
should be obtained as follows:
// domContentLoadedTime: Number(t.domContentLoadedEventStart.toFixed(d)),
domContentLoadedTime: Number(t.domContentLoadedEventEnd.toFixed(d)),
Thank you for your feedback.
Hi @yagikota thanks for creating the issue! Yes I thinks it's unclear. I think the metrics in https://github.com/sitespeedio/browsertime/blob/main/browserscripts/timings/pageTimings.js comes from a old Google Analytics guidance, so domContentLoadedTime isn't the exact same thing as the DOMContentLoaded event. The start fires right before the event https://w3c.github.io/navigation-timing/#dom-performancetiming-domcontentloadedeventstart and the end fires right after. I personally uses https://github.com/sitespeedio/browsertime/blob/main/browserscripts/timings/navigationTiming.js when monitoring a site. Maybe the best would be just to remove the pageTimings to avoid confusion.
thanks!