serviceworker
"serviceworker
keyword may be used with <{link}> elements. This keyword creates an external resource link (serviceworker link) that is used to declare a [=/service worker registration=] and its [=service worker registration/scope url=].
+ A [=/service worker registration=] and its [=service worker registration/scope url=] are created by a serviceworker link, which is declared using a "serviceworker" `Link` header or a <{link}> element whose <{link/rel}> attribute contains the keyword "[=html/serviceworker=]
".
Link
headerLink
header+ Link: <sw.js>; rel="serviceworker"; scope="/"; workertype="module"; updateviacache="all" ++
Link
headerLink
header that contains a serviceworker link, the user agent *should* run these steps:
@@ -1768,7 +1795,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
classic
" if the <{link/workertype}> attribute is omitted.
- 1. If |workerType| is not a valid {{WorkerType}} value, queue a task to fire an event named error
at the <{link}> element, and abort these steps.
+ 1. Let |workerType| be the state of the <{link/workertype}> attribute.
1. Let |useCache| be true if the <{link}> element has a <{link/usecache}> attribute, otherwise false.
1. Let |promise| be a new promise.
1. Invoke [=Start Register=] with |scopeURL|, |scriptURL|, |promise|, |client|, |client|'s creation URL, |workerType|, and |useCache|.
@@ -1811,24 +1837,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
- partial interface HTMLLinkElement { - [CEReactions] attribute USVString scope; - [CEReactions] attribute WorkerType workerType; - [CEReactions] attribute boolean useCache; - }; -- - The scope IDL attribute must reflect the element's scope content attribute. - - The workerType IDL attribute must reflect the element's workertype content attribute. - - The useCache IDL attribute must reflect the element's usecache content attribute. -
serviceworker
"
// 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 @@
// 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 @@
serviceworker
"The serviceworker
keyword may be used with link
elements. This keyword creates an external resource link (serviceworker link) that is used to declare a service worker registration and its scope url.
A service worker registration and its scope url are created by a serviceworker link, which is declared using a "serviceworker" Link
header or a link
element whose rel
attribute contains the keyword "serviceworker
".
Link
headerWhen a user agent that supports [RFC5988] processes a Link
header that contains a serviceworker link, the user agent should run these steps:
Link
headerA serviceworker link can be declared using a Link
header [RFC5988] with "serviceworker
" as the value of the "rel
" parameter and a script url as the target IRI, and the following optional target attributes:
scope
+ Value: A scope url.
+workertype
+ Value: A worker type.
+updateviacache
+ Value: An update via cache mode.
+The "anchor
" parameter must not be specified.
Link
headerWhen a user agent that supports [RFC5988] processes a Link
header that contains a serviceworker link, the user agent should run these steps:
If the Link
header has an "anchor
" parameter, abort these steps.
link
elementWhen a serviceworker link’s link
element is inserted into a document, or a serviceworker link is created on a link
element that is already in a document tree, or the href
or scope
attributes of the link
element of a serviceworker link is changed, the user agent should run these steps:
link
elementWhen a serviceworker link’s link
element is inserted into a document, or a serviceworker link is created on a link
element that is already in a document tree, or the href
or scope
attributes of the link
element of a serviceworker link is changed, the user agent should run these steps:
If the href
attribute is the empty string, abort these steps.
Let scopeURL be null.
If the scope
attribute is present, set scopeURL to the result of parsing the scope
attribute with the link
element’s node document’s document base URL.
If the scope
attribute is present, set scopeURL to the result of parsing the scope
attribute with the link
element’s node document’s document base URL.
Let workerType be the workertype
attribute, or "classic
" if the workertype
attribute is omitted.
Let workerType be the state of the workertype
attribute.
If workerType is not a valid WorkerType
value, queue a task to fire an event named error
at the link
element, and abort these steps.
Let useCache be true if the link
element has a usecache
attribute, otherwise false.
Let useCache be true if the link
element has a usecache
attribute, otherwise false.
Let promise be a new promise.
load
at the link
element.
The serviceworker link element must not delay the load event of the element’s node document.
+The serviceworker link element must not delay the load event of the element’s node document.
Link: </js/sw.js>; rel="serviceworker"; scope="/"
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: "/" });
partial interface HTMLLinkElement { - [CEReactions] attribute USVString scope; - [CEReactions] attribute WorkerType workerType; - [CEReactions] attribute boolean useCache; -}; --
The scope IDL attribute must reflect the element’s scope content attribute.
-The workerType IDL attribute must reflect the element’s workertype content attribute.
-The useCache IDL attribute must reflect the element’s usecache content attribute.
-The following definitions are the user agent’s internal data structures used throughout the specification.
-A scope to registration map is an ordered map where the keys are scope urls and the values are service worker registrations.
+A scope to registration map is an ordered map where the keys are scope urls and the values are service worker registrations.
A job is an abstraction of one of register, update, and unregister request for a service worker registration.
For unregister jobs, their scope url is the same.
-A job queue is a thread safe queue used to synchronize the set of concurrent jobs. The job queue contains jobs as its elements. The job queue should satisfy the general properties of FIFO queue. A user agent must maintain a separate job queue for each service worker registration keyed by its scope url. A job queue is initially empty. Unless stated otherwise, the job queue referenced from the algorithm steps is a job queue for the job’s scope url.
+A job queue is a thread safe queue used to synchronize the set of concurrent jobs. The job queue contains jobs as its elements. The job queue should satisfy the general properties of FIFO queue. A user agent must maintain a separate job queue for each service worker registration keyed by its scope url. A job queue is initially empty. Unless stated otherwise, the job queue referenced from the algorithm steps is a job queue for the job’s scope url.
referrer, a URL
workerType, a worker type
+workerType, a worker type
useCache, a boolean
Let job be the result of running Create Job with register, scopeURL, scriptURL, promise, and client.
Set job’s worker type to workerType.
+Set job’s worker type to workerType.
Set job’s use cache to useCache.
Let newestWorker be the result of running the Get Newest Worker algorithm passing registration as the argument.
If newestWorker is not null, job’s script url equals newestWorker’s script url with the exclude fragments flag set, and job’s use cache's value equals registration’s use cache's value, then:
+If newestWorker is not null, job’s script url equals newestWorker’s script url with the exclude fragments flag set, and job’s use cache's value equals registration’s use cache's value, then:
Invoke Resolve Job Promise with job and the ServiceWorkerRegistration
object which represents registration.
Let newestWorker be the result of running Get Newest Worker algorithm passing registration as the argument.
If job’s job type is update, and newestWorker’s script url does not equal job’s script url with the exclude fragments flag set, then:
+If job’s job type is update, and newestWorker’s script url does not equal job’s script url with the exclude fragments flag set, then:
Invoke Reject Job Promise with job and a TypeError
.
Let referrerPolicy be the empty string.
Switching on job’s worker type, run these substeps with the following options:
+Switching on job’s worker type, run these substeps with the following options:
classic
"
Let scopeURL be registration’s scope url.
+Let scopeURL be registration’s scope url.
Let maxScopeString be null.
Else, continue the rest of these steps after the algorithm’s asynchronous completion, with script being the asynchronous completion value.
If newestWorker is not null, newestWorker’s script url equals job’s script url with the exclude fragments flag set, and script’s source text is a byte-for-byte match with newestWorker’s script resource's source text, if script is a classic script, and script’s module record's [[ECMAScriptCode]] is a byte-for-byte match with newestWorker’s script resource's module record's [[ECMAScriptCode]] otherwise, then:
+If newestWorker is not null, newestWorker’s script url equals job’s script url with the exclude fragments flag set, and script’s source text is a byte-for-byte match with newestWorker’s script resource's source text, if script is a classic script, and script’s module record's [[ECMAScriptCode]] is a byte-for-byte match with newestWorker’s script resource's module record's [[ECMAScriptCode]] otherwise, then:
Invoke Resolve Job Promise with job and the ServiceWorkerRegistration
object which represents registration.
Generate a unique opaque string and set worker’s id to the value.
Set worker’s script url to job’s script url, worker’s script resource to script, and worker’s type to job’s worker type.
+Set worker’s script url to job’s script url, worker’s script resource to script, and worker’s type to job’s worker type.
Set worker’s script resource’s HTTPS state to httpsState.
If newestWorker is null, abort these steps.
Let job be the result of running Create Job with update, registration’s scope url, newestWorker’s script url, null, and null.
+Let job be the result of running Create Job with update, registration’s scope url, newestWorker’s script url, null, and null.
Set job’s worker type to newestWorker’s type.
+Set job’s worker type to newestWorker’s type.
Set job’s force bypass cache flag if its force bypass cache flag is set.
Invoke Resolve Job Promise with job and the ServiceWorkerRegistration
object which represents registration.
Queue a task to fire an event named updatefound
at all the ServiceWorkerRegistration
objects for all the service worker clients whose creation URL matches registration’s scope url and all the service workers whose containing service worker registration is registration.
Queue a task to fire an event named updatefound
at all the ServiceWorkerRegistration
objects for all the service worker clients whose creation URL matches registration’s scope url and all the service workers whose containing service worker registration is registration.
Let installingWorker be registration’s installing worker.
Note: Once an active worker is activating, neither a runtime script error nor a force termination of the active worker prevents the active worker from getting activated.
For each service worker client client whose creation URL matches registration’s scope url:
+For each service worker client client whose creation URL matches registration’s scope url:
If client is a window client, unassociate client’s responsible document from its application cache, if it has one.
@@ -5305,7 +5312,7 @@Return serviceWorker’s script url.
+Return serviceWorker’s script url.
Return its registering service worker client's origin.
@@ -5317,7 +5324,7 @@Set workerGlobalScope’s url to serviceWorker’s script url.
+Set workerGlobalScope’s url to serviceWorker’s script url.
Set workerGlobalScope’s HTTPS state to serviceWorker’s script resource’s HTTPS state.
Let scopeString be serialized scope with the exclude fragment flag set.
Let registration be a new service worker registration whose scope url is set to scope and use cache is set to useCache.
+Let registration be a new service worker registration whose scope url is set to scope and use cache is set to useCache.
Set scope to registration map[scopeString] to registration.
active
" and null as the arguments.
Let scopeString be serialized registration’s scope url with the exclude fragment flag set.
+Let scopeString be serialized registration’s scope url with the exclude fragment flag set.
Remove scope to registration map[scopeString].
@@ -6555,14 +6562,14 @@Service-Worker-Allowed
`
Indicates the user agent will override the path restriction, which limits the maximum allowed scope url that the script can control, to the given value.
+Indicates the user agent will override the path restriction, which limits the maximum allowed scope url that the script can control, to the given value.
Note: The value is a URL. If a relative URL is given, it is parsed against the script’s URL.
// Maximum allowed scope defaults to the path the script sits in // "/js" in this example -navigator.serviceWorker.register("/js/sw.js").then(() => { +navigator.serviceWorker.register("/js/sw.js").then(() => { console.log("Install succeeded with the default scope '/js'."); });@@ -6571,7 +6578,7 @@
// Set the scope to an upper path of the script location // Response has no Service-Worker-Allowed header -navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).catch(() => { +navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).catch(() => { console.error("Install failed due to the path restriction violation."); }); @@ -6580,7 +6587,7 @@
// Set the scope to an upper path of the script location // Response included "Service-Worker-Allowed : /" -navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).then(() => { +navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).then(() => { console.log("Install succeeded as the max allowed scope was overriden to '/'."); }); @@ -6589,7 +6596,7 @@
// Set the scope to an upper path of the script location // Response included "Service-Worker-Allowed : /foo" -navigator.serviceWorker.register("/foo/bar/sw.js", { scope: "/" }).catch(() => { +navigator.serviceWorker.register("/foo/bar/sw.js", { scope: "/" }).catch(() => { console.error("Install failed as the scope is still out of the overriden maximum allowed scope."); }); @@ -6976,8 +6983,6 @@