diff --git a/docs/index.bs b/docs/index.bs index ede56461..483b7ae5 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -1975,6 +1975,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 1. If |r|'s [=request/url=]'s [=url/scheme=] is not one of "http" and "https", then: 1. [=fetch/Terminate=] all the ongoing fetches initiated by |requests| with reason *fatal*. 1. Break the loop. + 1. If |r|'s [=request/client=]'s [=environment settings object/global object=] is a {{ServiceWorkerGlobalScope}} object, set |request|'s [=service-workers mode=] to "`foreign`". 1. Set |r|'s [=request/initiator=] to "fetch" and [=request/destination=] to "subresource". 1. Add a {{Request}} object associated with |r| to |requestArray|. 1. Let |responsePromise| be a new promise. @@ -2265,6 +2266,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 1. Let |serviceWorker| be |request|'s [=request/client=]'s [=environment settings object/global object=]'s [=ServiceWorkerGlobalScope/service worker=]. 1. If |serviceWorker|'s imported scripts updated flag is unset, then: 1. Let |registration| be |serviceWorker|'s [=containing service worker registration=]. + 1. Set |request|'s [=service-workers mode=] to "`foreign`". 1. Set |request|'s [=request/cache mode=] to "no-cache" if any of the following are true: * |registration|'s [=service worker registration/use cache=] is false. * The [=current global object=]'s [=force bypass cache for importscripts flag=] is set. @@ -2588,6 +2590,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe To [=fetching scripts/perform the fetch=] given |request|, run the following steps: + 1. Append \`Service-Worker\`/\`script\` to |request|'s [=request/header list=]. + + Note: See the definition of the Service-Worker header in Appendix B: Extended HTTP headers. + 1. Set |request|'s [=request/cache mode=] to "no-cache" if any of the following are true: * |registration|'s [=service worker registration/use cache=] is false. * |job|'s [=force bypass cache flag=] is set. @@ -2595,7 +2601,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe Note: Even if the cache mode is not set to "no-cache", the user agent obeys Cache-Control header's max-age value in the network layer to determine if it should bypass the browser cache. - 1. Set |request|'s [=skip-service-worker flag=]. + 1. Set |request|'s [=service-workers mode=] to "`none`". 1. If the [=fetching scripts/is top-level=] flag is unset, then return the result of [=/fetching=] |request|. 1. Append \`Service-Worker\`/\`script\` to |request|'s [=request/header list=]. @@ -2909,7 +2915,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=]. 1. Let |preloadResponseObject| be a new {{Response}} object associated with a new {{Headers}} object whose [=guard=] is "`immutable`". 1. [=header list/Append=] to |preloadRequestHeaders| a new [=header=] whose [=header/name=] is \`Service-Worker-Navigation-Preload\` and [=header/value=] is |registration|'s [=navigation preload header value=]. - 1. Set |preloadRequest|'s [=skip-service-worker flag=]. + 1. Set |preloadRequest|'s [=service-workers mode=] to "`none`". 1. Run the following substeps [=in parallel=]: 1. [=Fetch=] |preloadRequest|. diff --git a/docs/index.html b/docs/index.html index 4dc2d68e..6cef070a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1856,12 +1856,12 @@

Bootstrapping with a service worker:
// scope defaults to the path the script sits in
 // "/" in this example
-navigator.serviceWorker.register("/serviceworker.js").then(registration => {
+navigator.serviceWorker.register("/serviceworker.js").then(registration => {
   console.log("success!");
   if (registration.installing) {
     registration.installing.postMessage("Howdy from your installing page.");
   }
-}, err => {
+}, err => {
   console.error("Installing the worker failed!", err);
 });
 
@@ -2390,10 +2390,10 @@

Serving Cached Resources:
// caching.js
-self.addEventListener("install", event => {
+self.addEventListener("install", event => {
   event.waitUntil(
     // Open a cache of resources.
-    caches.open("shell-v1").then(cache => {
+    caches.open("shell-v1").then(cache => {
       // Begins the process of fetching them.
       // The coast is only clear when all the resources are ready.
       return cache.addAll([
@@ -2407,16 +2407,16 @@ 

); }); -self.addEventListener("fetch", event => { +self.addEventListener("fetch", event => { // No "fetch" events are dispatched to the service worker until it // successfully installs and activates. // All operations on caches are async, including matching URLs, so we use // promises heavily. e.respondWith() even takes promises to enable this: event.respondWith( - caches.match(e.request).then(response => { + caches.match(e.request).then(response => { return response || fetch(e.request); - }).catch(() => { + }).catch(() => { return caches.match("/fallback.html"); }) ); @@ -3683,7 +3683,7 @@

has more or less the same effect as a document being loaded in a secure context with the following link element:

-
<link rel="serviceworker" href="/js/sw.js" scope="/">
+
<link rel="serviceworker" href="/js/sw.js" scope="/">
 

which is more or less equivalent to the page containing javascript code like:

navigator.serviceworker.register("/js/sw.js", { scope: "/" });
@@ -3909,6 +3909,8 @@ 

Break the loop.

+
  • +

    If r’s client's global object is a ServiceWorkerGlobalScope object, set request’s service-workers mode to "foreign".

  • Set r’s initiator to "fetch" and destination to "subresource".

  • @@ -4430,7 +4432,7 @@

    7.3.2. importScripts(urls)

    -

    When the importScripts(urls) method is called on a ServiceWorkerGlobalScope object, the user agent must import scripts into worker global scope, given this ServiceWorkerGlobalScope object and urls, and with the following steps to perform the fetch given the request request:

    +

    When the importScripts(urls) method is called on a ServiceWorkerGlobalScope object, the user agent must import scripts into worker global scope, given this ServiceWorkerGlobalScope object and urls, and with the following steps to perform the fetch given the request request:

    1. Let serviceWorker be request’s client's global object's service worker.

      @@ -4439,6 +4441,8 @@

      Let registration be serviceWorker’s containing service worker registration.

      +
    2. +

      Set request’s service-workers mode to "foreign".

    3. Set request’s cache mode to "no-cache" if any of the following are true:

        @@ -4521,7 +4525,7 @@

    8.3. Define Event Handler

    -

    Specifications may define an event handler attribute for the corresponding functional event using partial interface definition to the ServiceWorkerGlobalScope interface:

    +

    Specifications may define an event handler attribute for the corresponding functional event using partial interface definition to the ServiceWorkerGlobalScope interface:

    partial interface ServiceWorkerGlobalScope {
       attribute EventHandler onfunctionalevent;
     };
    @@ -4530,7 +4534,7 @@ 

    8.4. Request Functional Event Dispatch

    To request a functional event dispatch to a service worker, specifications may invoke Handle Functional Event algorithm with its service worker registration registration and the algorithm callbackSteps as the arguments.

    -

    Specifications may define an algorithm callbackSteps where the corresponding functional event can be created and fired with specification specific objects. The algorithm is passed globalObject (a ServiceWorkerGlobalScope object) at which it may fire its functional events. This algorithm is called on a task queued by Handle Functional Event algorithm.

    +

    Specifications may define an algorithm callbackSteps where the corresponding functional event can be created and fired with specification specific objects. The algorithm is passed globalObject (a ServiceWorkerGlobalScope object) at which it may fire its functional events. This algorithm is called on a task queued by Handle Functional Event algorithm.

    Note: See an example hook defined in Notifications API.

    @@ -4898,6 +4902,9 @@

    To perform the fetch given request, run the following steps:

      +
    1. +

      Append `Service-Worker`/`script` to request’s header list.

      +

      Note: See the definition of the Service-Worker header in Appendix B: Extended HTTP headers.

    2. Set request’s cache mode to "no-cache" if any of the following are true:

    +
  • +

    If r’s client's global object is a ServiceWorkerGlobalScope object, set request’s service-workers mode to "foreign".

  • Set r’s initiator to "fetch" and destination to "subresource".

  • @@ -3970,7 +3972,7 @@

    6.3.2. importScripts(urls)

    -

    When the importScripts(urls) method is called on a ServiceWorkerGlobalScope object, the user agent must import scripts into worker global scope, given this ServiceWorkerGlobalScope object and urls, and with the following steps to perform the fetch given the request request:

    +

    When the importScripts(urls) method is called on a ServiceWorkerGlobalScope object, the user agent must import scripts into worker global scope, given this ServiceWorkerGlobalScope object and urls, and with the following steps to perform the fetch given the request request:

    1. Let serviceWorker be request’s client's global object's service worker.

      @@ -3979,6 +3981,8 @@

      Let registration be serviceWorker’s containing service worker registration.

      +
    2. +

      Set request’s service-workers mode to "foreign".

    3. Set request’s cache mode to "no-cache" if any of the following are true:

        @@ -4061,7 +4065,7 @@

    7.3. Define Event Handler

    -

    Specifications may define an event handler attribute for the corresponding functional event using partial interface definition to the ServiceWorkerGlobalScope interface:

    +

    Specifications may define an event handler attribute for the corresponding functional event using partial interface definition to the ServiceWorkerGlobalScope interface:

    partial interface ServiceWorkerGlobalScope {
       attribute EventHandler onfunctionalevent;
     };
    @@ -4070,7 +4074,7 @@ 

    7.4. Request Functional Event Dispatch

    To request a functional event dispatch to a service worker, specifications may invoke Handle Functional Event algorithm with its service worker registration registration and the algorithm callbackSteps as the arguments.

    -

    Specifications may define an algorithm callbackSteps where the corresponding functional event can be created and fired with specification specific objects. The algorithm is passed globalObject (a ServiceWorkerGlobalScope object) at which it may fire its functional events. This algorithm is called on a task queued by Handle Functional Event algorithm.

    +

    Specifications may define an algorithm callbackSteps where the corresponding functional event can be created and fired with specification specific objects. The algorithm is passed globalObject (a ServiceWorkerGlobalScope object) at which it may fire its functional events. This algorithm is called on a task queued by Handle Functional Event algorithm.

    Note: See an example hook defined in Notifications API.

    @@ -4383,6 +4387,9 @@

    To perform the fetch given request, run the following steps:

      +
    1. +

      Append `Service-Worker`/`script` to request’s header list.

      +

      Note: See the definition of the Service-Worker header in Appendix B: Extended HTTP headers.

    2. Set request’s cache mode to "no-cache" if any of the following are true:

      @@ -8719,7 +8728,7 @@

      4.1.3. skipWaiting()
    3. 4.4.1. event.waitUntil(f) -
    4. 4.5.6. event.respondWith(r) +
    5. 4.5.5. event.respondWith(r)
    6. Install (2)
    7. Handle Service Worker Client Unload