You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Return [=a new promise=] |promise| and run the following substeps [=in parallel=]:
2160
2168
1. [=map/For each=] |cacheName| → |cache| of the [=relevant name to cache map=]:
2161
2169
1. If |options|["{{MultiCacheQueryOptions/cacheName}}"] matches |cacheName|, then:
2162
-
1. Resolve |promise| with the result of running the algorithm specified in {{Cache/match(request, options)}} method of {{Cache}} interface with |request| and |options| (providing |cache| as thisArgument to the `[[Call]]` internal method of {{Cache/match(request, options)}}.)
2170
+
1. Resolve |promise| with the result of running the algorithm specified in {{Cache/match(request, options)}} method of {{Cache}} interface with |request| and |options| (providing |cache| as thisArgument to the `\[[Call]]` internal method of {{Cache/match(request, options)}}.)
2163
2171
1. Abort these steps.
2164
2172
1. Resolve |promise| with undefined.
2165
2173
1. Else:
2166
2174
1. Let |promise| be [=a promise resolved with=] undefined.
2167
2175
1. [=map/For each=]<var ignore>cacheName</var> → |cache| of the [=relevant name to cache map=]:
2168
2176
1. Set |promise| to the result of [=promise/reacting=] to itself with a fulfillment handler that, when called with argument |response|, performs the following substeps:
2169
2177
1. If |response| is not undefined, return |response|.
2170
-
1. Return the result of running the algorithm specified in {{Cache/match(request, options)}} method of {{Cache}} interface with |request| and |options| as the arguments (providing |cache| as thisArgument to the `[[Call]]` internal method of {{Cache/match(request, options)}}.)
2178
+
1. Return the result of running the algorithm specified in {{Cache/match(request, options)}} method of {{Cache}} interface with |request| and |options| as the arguments (providing |cache| as thisArgument to the `\[[Call]]` internal method of {{Cache/match(request, options)}}.)
1. For each |eventType| of |settingsObject|'s [=environment settings object/global object=]'s associated list of <a>event listeners</a>' event types:
2974
2982
1. [=set/Append=] |eventType| to |workerGlobalScope|'s associated [=ServiceWorkerGlobalScope/service worker=]'s <a>set of event types to handle</a>.
2975
2983
2976
-
Note: If the global object's associated list of event listeners does not have any event listener added at this moment, the service worker's set of event types to handle remains an empty set. The user agents are encouraged to show a warning that the event listeners must be added on the very first evaluation of the worker script.
2984
+
Note: If the global object's associated list of event listeners does not have any event listener added at this moment, the service worker's [=set of event types to handle=] remains an empty set.
2977
2985
2978
2986
1. Set |script|'s <a>has ever been evaluated flag</a>.
2987
+
1. Unset the |serviceWorker|'s [=all fetch listeners are empty flag=].
2988
+
1. The user agent may, if the [=All Fetch Listeners Are Empty=] algorithm with |workerGlobalScope| returns true, set |serviceWorker|'s [=all fetch listeners are empty flag=].
2989
+
2979
2990
1. Run the <a>responsible event loop</a> specified by |settingsObject| until it is destroyed.
2980
2991
1. [=map/Clear=] |workerGlobalScope|'s [=map of active timers=].
2981
2992
1. Wait for |serviceWorker| to be [=running=], or for |startFailed| to be true.
2982
2993
1. If |startFailed| is true, then return *failure*.
2983
2994
1. Return |serviceWorker|'s [=start status=].
2984
2995
</section>
2985
2996
2997
+
<section algorithm>
2998
+
<h3 id="all-fetch-listeners-are-empty-algorithm"><dfn>All Fetch Listeners Are Empty</dfn></h3>
2999
+
3000
+
: Input
3001
+
:: |workerGlobalScope|, a [=service worker/global object=].
3002
+
: Output
3003
+
:: a boolean
3004
+
3005
+
1. If |workerGlobalScope|'s [=set of event types to handle=] does not [=set/contain=]<code>fetch</code>, then return true.
3006
+
1. Let |eventHandler| be |workerGlobalScope|'s [=EventTarget/event handler map=]["onfetch"]'s value.
3007
+
1. Let |eventListenerCallbacks| be the result of calling [=legacy-obtain service worker fetch event listener callbacks=] given |workerGlobalScope|.
3008
+
1. [=list/For each=] |eventListenerCallback| of |eventListenerCallbacks|:
3009
+
1. Let |callback| be null.
3010
+
1. If |eventHandler| is not null and |eventListenerCallback| equals |eventHandler|'s [=event handler/listener=]'s [=event listener/callback=], then set |callback| to the result of [=convert to an ECMAScript value|converting to an ECMAScript value=] |eventHandler|'s [=event handler/value=].
3011
+
1. Otherwise, set |callback| to the result of [=convert to an ECMAScript value|converting to an ECMAScript value=] |eventListenerCallback|.
3012
+
1. If [$IsCallable$](|callback|) is false:
3013
+
1. Let |getResult| be [=Completion=]([$Get$](|callback|), <code>handleEvent</code>).
3014
+
1. If |getResult| is [=abrupt completion=], then return false.
3015
+
1. Set |callback| to |getResult|.
3016
+
1. If [$IsCallable$](|callback|) is false, or |callback|'s [=function body=] is not empty (i.e. either a [=statement=] or [=declaration=] exist), then return false.
3017
+
3018
+
Note: This detects "<code>fetch</code>" listeners like `() => {}`. Some sites have a fetch event listener with empty body to make them recognized by Chromium as a progressive web application (PWA).
3019
+
3020
+
1. Return true.
3021
+
3022
+
Note: User agents are encouraged to show a warning indicating that empty "<code>fetch</code>" listeners are unnecessary, and may have a negative performance impact.
3023
+
3024
+
</section>
3025
+
2986
3026
<section algorithm>
2987
3027
<h3 id="terminate-service-worker-algorithm"><dfn>Terminate Service Worker</dfn></h3>
1. Set |registration| to the result of running <a>Match Service Worker Registration</a> given |storage key| and |request|'s [=request/url=].
3041
3081
1. If |registration| is null or |registration|'s <a>active worker</a> is null, return null.
3042
3082
1. If |request|'s [=request/destination=] is not {{RequestDestination/"report"}}, set |reservedClient|'s <a>active service worker</a> to |registration|'s <a>active worker</a>.
3043
-
1. If |request| is a [=navigation request=], |registration|'s [=navigation preload enabled flag=] is set, |request|'s [=request/method=] is \`<code>GET</code>\`, and |registration|'s [=active worker=]'s <a>set of event types to handle</a>[=set/contains=]<code>fetch</code>, then:
3083
+
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:
3044
3084
3045
3085
Note: If the above is true except |registration|'s [=active worker=]'s <a>set of event types to handle</a> **does not** contain <code>fetch</code>, then the user agent may wish to show a console warning, as the developer's intent isn't clear.
1. If the result of running the [=Should Skip Event=] algorithm with "fetch" and |activeWorker| is true, then:
3076
3116
1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
3077
3117
1. Return null.
3118
+
1. If |activeWorker|'s [=all fetch listeners are empty flag=] is set:
3119
+
1. [=In parallel=]:
3120
+
1. If |activeWorker|'s [=service worker/state=] is "activating", then wait for |activeWorker|'s [=service worker/state=] to become "activated".
3121
+
1. Run the [=Run Service Worker=] algorithm with |activeWorker|.
3122
+
1. If |shouldSoftUpdate| is true, then run the [=Soft Update=] algorithm with |registration|.
3123
+
1. Return null.
3078
3124
1. If |useHighResPerformanceTimers| is true, then set |useHighResPerformanceTimers| to |activeWorker|'s [=service worker/global object=]'s [=WorkerGlobalScope/cross-origin isolated capability=].
3079
3125
1. Let |timingInfo|'s [=service worker timing info/start time=] be the [=coarsened shared current time=] given |useHighResPerformanceTimers|.
3080
3126
1. If |activeWorker|'s [=service worker/state=] is "`activating`", wait for |activeWorker|'s [=service worker/state=] to become "`activated`".
0 commit comments