Skip to content

Add unique identifier to "PerformanceResourceTiming" API #1007

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
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

monica-ch
Copy link

Explainer doc for the feedback.

@noamr
Copy link

noamr commented Apr 8, 2025

Thanks for working on this! I'm a bit confused about how the solution (specifically option 1) maps to the use case.
Seems like the use case is about mapping resource timing entries to fetch events, but the solution in option 1 only deals with navigations and maps the clientId, which would be the same across resources?

This OP alludes to that but this explainer doesn't...

Another issue with this is that mapping a response to a clientId only works if you don't use caches, which often beats the purpose of using a service-worker in the first place. A Cache allows you to reuse responses across clients, and this kind of mapping would break on the first response reuse.

Copy link
Member

@fabiorocha fabiorocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like both files are almost identical. I assume we only need one of them?

@monica-ch monica-ch marked this pull request as ready for review April 25, 2025 20:44
@monica-ch monica-ch changed the title Add explainer to expose client info on "PerformanceResourceTiming" API Add unique identifier to "PerformanceResourceTiming" API Apr 25, 2025

## Use Cases
Tracking resource timing across multiple requests, whether from different browsing contexts (e.g. multiple tabs) or service workers, can be challenging. Some examples include:
1. **Measuring Resource Timing Across Client and Service Worker** <br>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This <br> and the next <br> look weirdly out of place as the only embedded HTML in the document. Can you replace with an additional newline?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

event.respondWith((async () => {
const response = await fetch(event.request);
const entries = self.performance.getEntriesByType("resource");
const timing = entries.find(e => e.responseId === response.responseId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the sample code in this document contains code something like this

      const entries = self.performance.getEntriesByType("resource"); 
      const timing = entries.find(e => e.responseId === response.responseId); 

Should we also be proposing a new Performance function to help find these entries?

partial interface Performance {
  PerformanceEntry getEntryById (DOMString id);
}
      const timing = self.performance.getEntryById(response.responseId); 

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think getEntryById might be confusing, at least for the current explainer - as there are quite a few different kinds of Ids mentioned. Will keep the current sample code for now.

|Distinguish between identical requests from different clients. | ✅ |✅ | ✅ |
|Enables end-to-end correlation between requests, responses, and resource timings.| ❌ |✅| ❌ |
|Leverages existing identifiers (FetchEvent).| ❌ | ❌ | ✅ |
|Developers do not need to generate and manage RequestIds | ✅ |❌| ✅ |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For option 2 I thought the request ID is optional and will be generated by the user agent if not provided? If so then 'Developers do not need to generate manage RequestIds' for option 2 is true - they don't need to. Maybe this row is supposed to be about removing flexibility for end devs to use their own IDs?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

Copy link
Member

@fabiorocha fabiorocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after pending comments are addressed.

victorhuangwq and others added 4 commits June 9, 2025 11:57
Co-authored-by: David Risney <dave@deletethis.net>
Co-authored-by: David Risney <dave@deletethis.net>
Co-authored-by: David Risney <dave@deletethis.net>
@victorhuangwq
Copy link

@david-risney I have mostly addressed the comments. Do take a look

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

Successfully merging this pull request may close these issues.

5 participants