Skip to content

A resource timing entry is not created if the end of a non-null response body is not reached and there is no consume body steps #1813

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

Open
Lubrsi opened this issue Mar 5, 2025 · 3 comments
Labels
topic: timing Issues and PR that touch on the infrastructure that is used by ResourceTiming, NavigationTiming, etc

Comments

@Lubrsi
Copy link

Lubrsi commented Mar 5, 2025

What is the issue with the Fetch Standard?

For example, the given code will not produce a resource timing entry:

fetch("/alwayserror").then(resp => {
    if (!resp.ok) {
        return "status_" + resp.status;
    }
    return resp.text();
}).then(() => {
    console.log(JSON.stringify(performance.getEntriesByType("resource")));
});

Where /alwayserror is an endpoint which returns an error status code and a response body containing one byte.

In Blink, WebKit and Gecko, they produce a resource timing entry, but they all have a race condition of when it becomes available. In my testing on macOS 15.3.1:

  • For WebKit, it's a coin flip if the resource timing entry is available in the promise job reaction for the second then
  • For Gecko, I had to wait until at least the next task (e.g. a setTimeout(() => {}, 0) for the entry to be available.
  • In Blink, I had to wait for at least a 51ms timeout for the resource entry to start appearing, but it's hit and miss if it's available at that timeout.
  • Reading the body to the end (e.g. removing the if (!resp.ok) path in the above example) produces a resource timing entry straight away in all three, available in the second then callback.

On the live web, this is encountered by Cloudflare Turnstile.

This is caused by processResponseEndOfBody being called as the flush algorithm when reading the body through a TransformStream in fetch response handover. If the end of the stream is not reached, flushAlgorithm is not called, and thus a resource timing entry is not created.

@annevk annevk added the topic: timing Issues and PR that touch on the infrastructure that is used by ResourceTiming, NavigationTiming, etc label Apr 9, 2025
@annevk
Copy link
Member

annevk commented Apr 9, 2025

I'm not really sure what we could do to improve this situation. If I remember correctly we need the full body in order to create a timing entry.

cc @noamr

@noamr
Copy link
Contributor

noamr commented Apr 9, 2025

One thing we can do here is create the resource timing entry at handover, and add it to the buffer (accessible via e.g. getEntriesByType), but set its final info (encoded/decoded size, end time) and queue it to observers only when its body is complete. This is what we do for navigation timing entries. Not sure if this helps with your use case @Lubrsi?

/cc @yoavweiss

@annevk
Copy link
Member

annevk commented Apr 9, 2025

I like the idea of it being more deterministic when it's allocated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: timing Issues and PR that touch on the infrastructure that is used by ResourceTiming, NavigationTiming, etc
Development

No branches or pull requests

3 participants