Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are fetchStart, connectStart, redirectStart relative to navigationStart? #237

Closed
Nithanaroy opened this issue Nov 10, 2020 · 10 comments
Closed

Comments

@Nithanaroy
Copy link

Times like fetchStart, connectStart, redirectStart are not timestamps to compare with page level metrics like loadEventEnd. Are they relative to navigationStart?

@npm1
Copy link
Contributor

npm1 commented Nov 10, 2020

What's loadEventEnd? But yes, the values returned in the API are relative to the timeOrigin (so yea, navigationStart).

@Nithanaroy
Copy link
Author

Nithanaroy commented Nov 10, 2020

Okay. Thank you.
I'm referring to https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming/loadEventEnd

The numbers I'm seeing in our RUM datasets are weird based on the definition you confirmed. I am seeing

loadEventEnd - navigationStart > postOnLoadResourceTimingEntry.startTime

for a lot of RUM samples. And as per the definition startTime should equal fetchStart
Here postOnLoadResourceTimingEntry is a resource that is initiated on the page's onLoad event.

Both loadEventEnd and fetchStart not being relative to navigationStart is the only explanation I can think of for this which doesn't agree with the spec.

Any thoughts on why this could be happening?

@npm1
Copy link
Contributor

npm1 commented Nov 11, 2020

How much bigger is it? I would suggest looking at performance.timeOrigin, how different is it from navigationStart? The former is the one used for startTime, and also we jitter the values so that could affect this kind of comparison. Also worth double checking that the fetch begins directly on onLoad and not in a promise inside it, or something like that which introduces some delay.

@nicjansma
Copy link
Contributor

Do you have a page that reproduces this problem? Have you seen this across browsers, or only in specific ones?

Here postOnLoadResourceTimingEntry is a resource that is initiated on the page's onLoad event.

In that case, the loadEventEnd hasn't happened yet (since the handler is still running), so it's likely the postOnLoadResourceTimingEntry.startTime should happen prior to loadEventEnd-navigationStart. If you compare to loadEventStart, postOnLoadResourceTimingEntry.startTime should be after that.

If that's not the issue, there are a few known browser bugs with navigationStart (via NavigationTiming) and timeOrigin (which ResourceTiming use) differing slightly https://bugs.chromium.org/p/chromium/issues/detail?id=955532#c26

@Nithanaroy
Copy link
Author

Hi @npm1,
On my dev machine it happens around 100ms earlier, but on users' devices I have seen bigger numbers. Both timeOrigin and navigationStart match for the page I'm interested in.
Screen Shot 2020-11-11 at 1 29 10 PM

And I verified the code to make the resource we are fetching happens on the onLoad event of the window, something like,

window.addEventListener('load', () => { getMyApiDataUsingFetch(); });

@npm1
Copy link
Contributor

npm1 commented Nov 11, 2020

One additional idea: locally you could log performance.now() at the beginning and at the end of the load event to know the time frame where we were expecting the fetch to begin. That said, fetching is inherently asynchronous in modern browsers, so I'm not surprised that this happens in some cases. That is, the process that runs the JavaScript is not the same as the process which performs the network requests, so this could explain why you may see this kind of result, unless you use an async function and await the fetch.

@Nithanaroy
Copy link
Author

Hi @nicjansma,
I think with loadEventStart the numbers look reasonable, i.e.

loadEventStart - navigationStart < postOnLoadResourceTimingEntry.startTime

Is loadEventEnd - loadEventStart the time taken to execute the onLoad event handler? Are these separated to easily see how much work is being immediately after page load?

Thanks for all the ideas @npm1 :)

@nicjansma
Copy link
Contributor

nicjansma commented Nov 16, 2020

Correct loadEventStart is the timestamp before the onload handlers run and loadEventEnd is the timestamp after all onload handlers have finished, so the difference between the two is the duration.

If you're executing code at onload, any network requests that start then will probably have a startTime after loadEventStart and before loadEventEnd

@nicjansma
Copy link
Contributor

@Nithanaroy I believe we've addressed your issue, but please leave a comment if there is still a question here!

@Krinkle
Copy link
Member

Krinkle commented Jan 19, 2021

loadEventEnd is the timestamp before the onload handlers run and loadEventStart is the timestamp after all onload handlers have finished, […]

I think you meant the other way around, right? 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants