Skip to content

Commit ca38db9

Browse files
authored
Add new fields and getter steps for static routing resource timing (#1769)
This commit adds necessary fields and steps to realize timing info for the ServiceWorker static routing API discussed in w3c/resource-timing#389.
1 parent b7bbcea commit ca38db9

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

docs/index.bs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
241241
<section>
242242
<h3 id="service-worker-timing">Service Worker Timing</h3>
243243

244-
Service workers mark certain points in time that are later exposed by the <a interface lt="PerformanceNavigationTiming">navigation timing</a> API.
244+
Service workers mark certain points in time that are later exposed by the <a interface lt="PerformanceNavigationTiming">navigation timing</a> API and <a interface lt="PerformanceResourceTiming">resource timing</a> API.
245245

246246
A <dfn export>service worker timing info</dfn> is a [=/struct=]. It has the following [=struct/items=]:
247247

@@ -250,6 +250,14 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
250250
:: A {{DOMHighResTimeStamp}}, initially 0.
251251
: <dfn export>fetch event dispatch time</dfn>
252252
:: A {{DOMHighResTimeStamp}}, initially 0.
253+
: <dfn export>worker router evaluation start</dfn>
254+
:: A {{DOMHighResTimeStamp}}, initially 0.
255+
: <dfn export>worker cache lookup start</dfn>
256+
:: A {{DOMHighResTimeStamp}}, initially 0.
257+
: <dfn export>worker matched router source</dfn>
258+
:: A {{DOMString}}, initially an empty string.
259+
: <dfn export>worker final router source</dfn>
260+
:: A {{DOMString}}, initially an empty string.
253261
</section>
254262
</section>
255263

@@ -1092,7 +1100,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
10921100

10931101
A {{ServiceWorkerGlobalScope}} object has an associated <dfn for="ServiceWorkerGlobalScope">force bypass cache for import scripts flag</dfn>. It is initially unset.
10941102

1095-
A {{ServiceWorkerGlobalScope}} object has an associated <dfn for="ServiceWorkerGlobalScope">race response map</dfn> which is an [=ordered map=] where the [=map/keys=] are [=/requests=] and the [=map/values=] are [=race response=].
1103+
A {{ServiceWorkerGlobalScope}} object has an associated <dfn for="ServiceWorkerGlobalScope">race response map</dfn> which is an [=ordered map=] where the [=map/keys=] are [=/requests=] and the [=map/values=] are [=/race response=].
10961104

10971105
A <dfn id="dfn-race-response">race response</dfn> is a [=struct=] used to contain the network response when {{RouterSourceEnum/"race-network-and-fetch-handler"}} performs. It has a <dfn for="race response">value</dfn>, which is a [=/response=], "<code>pending</code>", or null.
10981106

@@ -2557,6 +2565,12 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
25572565

25582566
Note: Keep this definition in sync with [=fetch a classic worker-imported script=].
25592567

2568+
A <dfn id="dfn-race-result">race result</dfn> is a [=tuple=] of a [=race result/routed response=] and [=race result/used route=].
2569+
2570+
A [=/race result=] has an associated <dfn export for="race result">routed response</dfn> (a [=/response=]).
2571+
2572+
A [=/race result=] has an associated <dfn export for="race result">used route</dfn> (a {{RouterSourceEnum}}).
2573+
25602574
<section algorithm>
25612575
<h3 id="create-job-algorithm"><dfn>Create Job</dfn></h3>
25622576

@@ -3215,13 +3229,16 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32153229
* |request| is a [=non-subresource request=].
32163230
* |request| is a [=subresource request=] and |registration| is [=stale=].
32173231
1. If |activeWorker|'s [=service worker/list of router rules=] [=list/is not empty=]:
3232+
1. Set |timingInfo|’s [=service worker timing info/worker router evaluation start=] to the [=coarsened shared current time=] given |useHighResPerformanceTimers|.
32183233
1. Let |source| be the result of running the [=Get Router Source=] algorithm with |registration|'s <a>active worker</a> and |request|.
32193234
1. If |source| is non-null, then:
3235+
1. Set |timingInfo|'s [=service worker timing info/worker matched router source=] be set to |source|, and [=service worker timing info/worker final router source=] be set to {{RouterSourceEnum/"network"}}.
32203236
1. If |source| is {{RouterSourceEnum/"network"}}:
32213237
1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
32223238
1. Return null.
32233239
1. Else if |source| is {{RouterSourceEnum/"cache"}}, or |source|["{{RouterSourceDict/cacheName}}"] [=map/exists=], then:
32243240
1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
3241+
1. Set |timingInfo|’s [=service worker timing info/worker cache lookup start=] to the [=coarsened shared current time=] given |useHighResPerformanceTimers|.
32253242
1. [=map/For each=] |cacheName| &#x2192; |cache| of the |registration|'s [=service worker registration/storage key=]'s [=name to cache map=].
32263243
1. If |source|["{{RouterSourceDict/cacheName}}"] [=map/exists=] and |source|["{{RouterSourceDict/cacheName}}"] [=string/is=] not |cacheName|, [=continue=].
32273244
1. Let |requestResponses| be the result of running [=Query Cache=] with |request|, a new {{CacheQueryOptions}}, and |cache|.
@@ -3237,18 +3254,20 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32373254
Note: This only creates a ServiceWorkerGlobalScope because CORS checks require that. It is not expected that implementations will actually create a ServiceWorkerGlobalScope here.
32383255

32393256
1. If |response|'s [=response/type=] is "`opaque`", and [=cross-origin resource policy check=] with |globalObject|'s [=environment settings object/origin=], |globalObject|, "", and |response|'s [=filtered response/internal response=] returns <b>blocked</b>, then return null.
3257+
1. Set |timingInfo|'s [=service worker timing info/worker final router source=] be set to {{RouterSourceEnum/"cache"}}.
32403258
1. Return |response|.
32413259
1. Return null.
32423260
1. Else if |source| is {{RouterSourceEnum/"race-network-and-fetch-handler"}}, and |request|'s [=request/method=] is \`<code>GET</code>\` then:
32433261
1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
3244-
1. Let |queue| be an empty [=queue=] of [=/response=].
3262+
1. Let |queue| be an empty [=queue=] of [=race result=].
32453263
1. Let |raceFetchController| be null.
32463264
1. Let |raceResponse| be a [=race response=] whose [=race response/value=] is "<code>pending</code>".
32473265
1. Run the following substeps [=in parallel=], but [=abort when=] |fetchController|'s [=fetch controller/state=] is "<code>terminated</code>" or "<code>aborted</code>":
32483266
1. Set |raceFetchController| to the result of calling [=fetch=] given |request|, with [=fetch/processResponse=] set to the following steps given a [=/response=] |raceNetworkRequestResponse|:
32493267
1. If |raceNetworkRequestResponse|'s [=response/status=] is [=ok status=], then:
32503268
1. Set |raceResponse|'s [=race response/value=] to |raceNetworkRequestResponse|.
3251-
1. [=queue/Enqueue=] |raceNetworkRequestResponse| to |queue|.
3269+
1. Let |raceNetworkResult| be a [=race result=] whose [=race result/routed response=] is |raceNetworkRequestResponse| and [=race result/used route=] is {{RouterSourceEnum/"network"}}.
3270+
1. [=queue/Enqueue=] |raceNetworkResult| to |queue|.
32523271
1. Otherwise, set |raceResponse|'s [=race response/value=] to a [=network error=].
32533272
1. [=If aborted=] and |raceFetchController| is not null, then:
32543273
1. [=fetch controller/Abort=] |raceFetchController|.
@@ -3257,9 +3276,12 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32573276
1. Run the following substeps [=in parallel=]:
32583277
1. Let |fetchHandlerResponse| be the result of [=Create Fetch Event and Dispatch=] with |request|, |registration|, |useHighResPerformanceTimers|, |timingInfo|, |workerRealm|, |reservedClient|, |preloadResponse|, and |raceResponse|.
32593278
1. If |fetchHandlerResponse| is not null and not a [=network error=], and |raceFetchController| is not null, [=fetch controller/abort=] |raceFetchController|.
3260-
1. [=queue/Enqueue=] |fetchHandlerResponse| to |queue|.
3279+
1. Let |raceFetchHandlerResult| be a [=race result=] whose [=race result/routed response=] is |fetchHandlerResponse| and [=race result/used route=] is {{RouterSourceEnum/"fetch-event"}}.
3280+
1. [=queue/Enqueue=] |raceFetchHandlerResult| to |queue|.
32613281
1. Wait until |queue| is not empty.
3262-
1. Return the result of [=dequeue=] |queue|.
3282+
1. Let |result| be the result of [=dequeue=] |queue|.
3283+
1. Set |timingInfo|'s [=service worker timing info/worker final router source=] be set to |result|'s [=race result/used route=].
3284+
1. Return |result|'s [=/race response=].
32633285
1. Assert: |source| is "{{RouterSourceEnum/fetch-event}}"
32643286
1. If |request| is a [=navigation request=], |registration|'s [=navigation preload enabled flag=] is set, |request|'s [=request/method=] is \`<code>GET</code>\`, |registration|'s [=active worker=]'s [=set of event types to handle=] [=set/contains=] <code>fetch</code>, and |registration|'s [=active worker=]'s [=all fetch listeners are empty flag=] is not set then:
32653287

@@ -3283,7 +3305,10 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32833305
1. Let |deserializedError| be the result of [=deserialize a serialized abort reason=] given null and |workerRealm|.
32843306
1. [=fetch controller/Abort=] |preloadFetchController| with |deserializedError|.
32853307
1. Else, resolve |preloadResponse| with undefined.
3286-
1. Return the result of [=Create Fetch Event and Dispatch=] with |request|, |registration|, |useHighResPerformanceTimers|, |timingInfo|, |workerRealm|, |reservedClient|, |preloadResponse|, and null.
3308+
1. Let |fetchResult| be the result of [=Create Fetch Event and Dispatch=] with |request|, |registration|, |useHighResPerformanceTimers|, |timingInfo|, |workerRealm|, |reservedClient|, |preloadResponse|, and null.
3309+
1. If |fetchResult| is not null and |timingInfo|'s [=service worker timing info/worker final router source=] is set to {{RouterSourceEnum/"network"}}:
3310+
1. Set |timingInfo|'s [=service worker timing info/worker final router source=] to {{RouterSourceEnum/"fetch-event"}}.
3311+
1. Return |fetchResult|.
32873312
</section>
32883313

32893314
<section algorithm>

0 commit comments

Comments
 (0)