-
Notifications
You must be signed in to change notification settings - Fork 30
Description
For the v4 launch of the web-vitals JS libary we wanted to add additional attribution timings to the TTFB metric (see: GoogleChrome/web-vitals#458).
We were hoping to be able to expose some timing attribution for service worker latency, but in my testing I found that the workerStart, fetchStart, and requestStart values were very inconsistent across browsers for pages that were controlled by service worker—and even inconsistent within the same browser when comparing pages whose navigation request was handled via service worker (i.e. the fetch event called event.respondWith()) vs. pages controlled by service worker but that didn't respond to navigation requests.
I'm not super familiar with this spec, so it wasn't clear whether the issue is with ambiguity in the spec itself or just in engine implementations of the spec, but regardless I wanted to flag my findings here in the hopes that someone would be able to investigate. Also, I didn't see any Web Platform tests covering service worker behavior for this API (at least based on test names).
Summary of inconsistencies
Note: all of these issues can be reproduced using this demo page: https://nt-sw.glitch.me/
If the fetch event DOES NOT call event.respondWith() for the navigation request:
workerStart- Chrome & Safari: corresponds to when the SW process started (or zero if it was already started)
- Firefox: is always 0
fetchStart- Chrome: corresponds to when the
fetchevent was dispatched - Safari: corresponds to when the
fetchlisteners have finished running. - Firefox: is always 0
- Chrome: corresponds to when the
requestStart- Chrome, Safari, & Firefox: corresponds to when fetch event listeners have finished running.
Implications:
- Safari: SW startup duration cannot be measured accurately because
fetchStart - workerStartincludes time running the fetch events.fetchevent duration also cannot be measured. - Firefox: Neither SW startup nor
fetchevent duration can be measured at all.
If the fetch event DOES call event.respondWith() for the navigation request:
workerStart- Chrome & Safari: corresponds to when the SW process started (or zero if it was already started)
- Firefox: is always 0
fetchStart- Chrome: corresponds to when the
fetchevent was dispatched - Safari: is always 0
- Firefox: corresponds to when
event.respondWith()was called
- Chrome: corresponds to when the
requestStart- Chrome: also corresponds to when the
fetchevent was dispatched (even if there was significant blocking duration within thefetchevent beforeevent.respondWith()was called) - Safari: is always 0
- Firefox: corresponds to when
event.respondWith()was called
- Chrome: also corresponds to when the
Implications:
- Chrome:
fetchevent duration cannot be measured becausefetchStartandrequestStartreport the same time. - Safari: Neither SW startup nor
fetchevent duration can be measured at all. - Firefox: SW startup duration cannot be measured accurately because
fetchStart - workerStartincludes time running the fetch events.fetchevent duration also cannot be measured.