Skip to content

Commit 4e9d705

Browse files
authored
Update Handle Fetch to return timing info (#1772)
This change ensures that timing information is propagated to the caller even when a network fallback occurs. Consequently, Service Worker timing information can now be configured as outlined in the explainer, once related specifications are updated to support this behavior. https://github.com/WICG/service-worker-static-routing-api/blob/main/resource-timing-api.md#correspondence-of-the-matched-source-type-and-the-actual-source-type
1 parent ca38db9 commit 4e9d705

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

docs/index.bs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,7 +3196,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
31963196
:: |fetchController|, a [=fetch controller=]
31973197
:: |useHighResPerformanceTimers|, a boolean
31983198
: Output
3199-
:: a [=/response=]
3199+
:: a [=/response=] or [=service worker timing info=]
32003200

32013201
1. Let |registration| be null.
32023202
1. Let |client| be |request|'s [=request/client=].
@@ -3235,28 +3235,29 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32353235
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"}}.
32363236
1. If |source| is {{RouterSourceEnum/"network"}}:
32373237
1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
3238-
1. Return null.
3238+
1. Return |timingInfo|.
32393239
1. Else if |source| is {{RouterSourceEnum/"cache"}}, or |source|["{{RouterSourceDict/cacheName}}"] [=map/exists=], then:
32403240
1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
32413241
1. Set |timingInfo|’s [=service worker timing info/worker cache lookup start=] to the [=coarsened shared current time=] given |useHighResPerformanceTimers|.
32423242
1. [=map/For each=] |cacheName| → |cache| of the |registration|'s [=service worker registration/storage key=]'s [=name to cache map=].
32433243
1. If |source|["{{RouterSourceDict/cacheName}}"] [=map/exists=] and |source|["{{RouterSourceDict/cacheName}}"] [=string/is=] not |cacheName|, [=continue=].
32443244
1. Let |requestResponses| be the result of running [=Query Cache=] with |request|, a new {{CacheQueryOptions}}, and |cache|.
3245-
1. If |requestResponses| is an empty [=list=], return null.
3245+
1. If |requestResponses| is an empty [=list=], return |timingInfo|.
32463246
1. Else:
32473247
1. Let |requestResponse| be the first element of |requestResponses|.
32483248
1. Let |response| be |requestResponse|'s response.
32493249
1. Let |globalObject| be |activeWorker|'s [=service worker/global object=].
32503250
1. If |globalObject| is null:
32513251
1. Set |globalObject| to the result of running [=Setup ServiceWorkerGlobalScope=] with |activeWorker|.
3252-
1. If |globalObject| is null, return null.
3252+
1. If |globalObject| is null, return |timingInfo|.
32533253

32543254
Note: This only creates a ServiceWorkerGlobalScope because CORS checks require that. It is not expected that implementations will actually create a ServiceWorkerGlobalScope here.
32553255

3256-
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.
3256+
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 |timingInfo|.
32573257
1. Set |timingInfo|'s [=service worker timing info/worker final router source=] be set to {{RouterSourceEnum/"cache"}}.
3258+
1. Set |result|'s [=service worker timing info=] be set to |timingInfo|.
32583259
1. Return |response|.
3259-
1. Return null.
3260+
1. Return |timingInfo|.
32603261
1. Else if |source| is {{RouterSourceEnum/"race-network-and-fetch-handler"}}, and |request|'s [=request/method=] is \`<code>GET</code>\` then:
32613262
1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
32623263
1. Let |queue| be an empty [=queue=] of [=race result=].
@@ -3281,6 +3282,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32813282
1. Wait until |queue| is not empty.
32823283
1. Let |result| be the result of [=dequeue=] |queue|.
32833284
1. Set |timingInfo|'s [=service worker timing info/worker final router source=] be set to |result|'s [=race result/used route=].
3285+
1. Set |result|'s [=service worker timing info=] be set to |timingInfo|.
32843286
1. Return |result|'s [=/race response=].
32853287
1. Assert: |source| is "{{RouterSourceEnum/fetch-event}}"
32863288
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:
@@ -3306,8 +3308,8 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
33063308
1. [=fetch controller/Abort=] |preloadFetchController| with |deserializedError|.
33073309
1. Else, resolve |preloadResponse| with undefined.
33083310
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. If |fetchResult| is not null and |fetchResult|'s [=response/service worker timing info=]'s [=service worker timing info/worker final router source=] is set to {{RouterSourceEnum/"network"}}:
3312+
1. Set |fetchResult|'s [=response/service worker timing info=]'s [=service worker timing info/worker final router source=] to {{RouterSourceEnum/"fetch-event"}}.
33113313
1. Return |fetchResult|.
33123314
</section>
33133315

0 commit comments

Comments
 (0)