From 855d54f2755380a39d238f6e6d392032ac375304 Mon Sep 17 00:00:00 2001
From: Jungkee Song The user agent must create a {{CacheStorage}} object when a {{Window}} object or a {{WorkerGlobalScope}} object is created and associate it with that object. A A For example, consider a document created by a navigation to The value of has more or less the same effect as a document being loaded in a secure context with the following which is more or less equivalent to the page containing javascript code like:
CacheStorage
object represents a name to cache map of its associated global object's environment settings object's origin. Multiple separate objects implementing the {{CacheStorage}} interface across documents and workers can all be associated with the same name to cache map simultaneously.CacheStorage
object represents a name to cache map of its associated global object's environment settings object's origin. Multiple separate objects implementing the {{CacheStorage}} interface across documents and workers can all be associated with the same name to cache map simultaneously.{{CacheStorage/match(request, options)}}
@@ -2929,7 +2929,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
// e.g. define an API namespace
readonly attribute APISpaceType APISpace;
// e.g. define a method
- Promise<T> methodName(list of arguments);
+ Promise<T> methodName(/* list of arguments */);
};
foreignfetch
, which does not bubble."opaque"
, set response to an opaque filtered response of internalResponse.Service Workers Nightly
- Editor’s Draft,
+ Editor’s Draft,
3. Client Context
// scope defaults to the path the script sits in
+
// scope defaults to the path the script sits in
// "/" in this example
navigator.serviceWorker.register("/serviceworker.js").then(
function(registration) {
@@ -1830,8 +1830,7 @@
+ });},
function(why) {
console.error("Installing the worker failed!:", why);
- });
-
3.1.
@@ -1862,9 +1861,8 @@ ServiceWorker
https://example.com/app.html
which matches via the following registration call which has been previously executed:// Script on the page https://example.com/app.html
-navigator.serviceWorker.register("/service_worker.js", { scope: "/" });
-
+// Script on the page https://example.com/app.html
+navigator.serviceWorker.register("/service_worker.js", { scope: "/" });
navigator.serviceWorker.controller.scriptURL
will be "https://example.com/service_worker.js
".<
ExtendableMessageEvent
interface, with the event type message, which does not bubble and is not cancelable.
data
attribute of e be initialized to clonedMessage.
- origin
attribute of e be initialized to the Unicode serialisation of incumbentSettings’s origin.
+ origin
attribute of e be initialized to the Unicode serialization of incumbentSettings’s origin.
ServiceWorkerGlobalScope
object, let the source
attribute of e be initialized to a new ServiceWorker
object that represents incumbentGlobal’s service worker.
Window
object, let the source
attribute of e be initialized to a new WindowClient
object that represents incumbentGlobal’s browsing context.
Client
object that represents the worker associated with incumbentGlobal.
@@ -2252,7 +2250,7 @@ 4. Execution Context
// caching.js
+
// caching.js
this.addEventListener("install", function(e) {
e.waitUntil(
// Open a cache of resources.
@@ -2283,8 +2281,7 @@
+});return caches.match("/fallback.html");
})
);
-});
-
4.1.
@@ -2435,7 +2432,7 @@ ServiceWorkerGlobalScope
ServiceWorkerMessageEvent
interface, with the event type message, which does not bubble and is not cancelable.
data
attribute of e be initialized to clonedMessage.
- origin
attribute of e be initialized to the Unicode serialisation of sourceSettings’s origin.
+ origin
attribute of e be initialized to the Unicode serialization of sourceSettings’s origin.
source
attribute of e be initialized to a ServiceWorker
object, which represents the service worker associated with sourceSettings’s global object.
ports
attribute of e be initialized to newPorts.
Link: </js/sw.js>; rel="serviceworker"; scope="/"
link
element:<link rel="serviceworker" href="/js/sw.js" scope="/">
-
+<link rel="serviceworker" href="/js/sw.js" scope="/">
navigator.serviceworker.register("/js/sw.js", { scope: "/" });
-
+navigator.serviceworker.register("/js/sw.js", { scope: "/" });
CacheStorage
interface is designed to largely conform to ECMAScript 6 Map objects but entirely async, and with additional convenience methods. The methods, clear
, forEach
, entries
and values
, are intentionally excluded from the scope of the first version resorting to the ongoing discussion about the async iteration by TC39.
The user agent must create a CacheStorage
object when a Window
object or a WorkerGlobalScope
object is created and associate it with that object.
A CacheStorage
object represents a name to cache map of its associated global object’s environment settings object’s origin. Multiple separate objects implementing the CacheStorage
interface across documents and workers can all be associated with the same name to cache map simultaneously.
A CacheStorage
object represents a name to cache map of its associated global object’s environment settings object’s origin. Multiple separate objects implementing the CacheStorage
interface across documents and workers can all be associated with the same name to cache map simultaneously.
match(request, options)
match(request, options)
method must run these steps:
Specifications may define an API tied to a service worker registration by using partial interface definition to the ServiceWorkerRegistration
interface where it may define the specification specific attributes and methods:
partial interface ServiceWorkerRegistration { +partial interface ServiceWorkerRegistration { // e.g. define an API namespace - readonly attribute APISpaceType APISpace; + readonly attribute APISpaceType APISpace; // e.g. define a method - Promise<T> methodName(list of arguments); + Promise<T> methodName(/* list of arguments */); };
Specifications may define a functional event by extending ExtendableEvent
interface:
// e.g. define FunctionalEvent interface -interface FunctionalEvent : ExtendableEvent { +// e.g. define FunctionalEvent interface +interface FunctionalEvent : ExtendableEvent { // add a functional event’s own attributes and methods };@@ -3930,8 +3925,8 @@
@@ -4440,7 +4435,7 @@ 9.3. Define Event Handler
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; +partial interface ServiceWorkerGlobalScope { + attribute EventHandler onfunctionalevent; };JavaScript execution context.
Let workerEventLoop be a newly created event loop. - Let workerGlobalScope be realmExecutionContext’s global object. + Let workerGlobalScope be realmExecutionContext’s global object. Let settingsObject be a new environment settings object whose algorithms are defined as follows: @@ -5249,39 +5244,35 @@
Default scope: -
// Maximum allowed scope defaults to the path the script sits in +// Maximum allowed scope defaults to the path the script sits in // "/js" in this example navigator.serviceWorker.register("/js/sw.js").then(function() { console.log("Install succeeded with the default scope '/js'."); -}); -+});Upper path without Service-Worker-Allowed header: -// Set the scope to an upper path of the script location +// 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(function() { console.error("Install failed due to the path restriction violation."); -}); -+});Upper path with Service-Worker-Allowed header: -// Set the scope to an upper path of the script location +// Set the scope to an upper path of the script location // Response included "Service-Worker-Allowed : /" navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).then(function() { console.log("Install succeeded as the max allowed scope was overriden to '/'."); -}); -+});A path restriction voliation even with Service-Worker-Allowed header: -// Set the scope to an upper path of the script location +// 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(function() { console.error("Install failed as the scope is still out of the overriden maximum allowed scope."); -}); -+});
A service worker is a type of web worker. A service worker executes in the registering service worker client's origin.
@@ -368,11 +368,11 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/A service worker client has an associated frame type, which is one of auxiliary, top-level, nested, and none. Unless stated otherwise it is none. -
A window client is a service worker client whose global object is a {{Window}} object.
+A window client is a service worker client whose global object is a {{Window}} object.
-A dedicated worker client is a service worker client whose global object is a {{DedicatedWorkerGlobalScope}} object.
+A dedicated worker client is a service worker client whose global object is a {{DedicatedWorkerGlobalScope}} object.
-A shared worker client is a service worker client whose global object is a {{SharedWorkerGlobalScope}} object.
+A shared worker client is a service worker client whose global object is a {{SharedWorkerGlobalScope}} object.
A worker client is either a dedicated worker client or a shared worker client.
A ServiceWorkerContainer
provides capabilities to register, unregister, and update the service worker registrations, and provides access to the state of the service worker registrations and their associated service workers.
A {{ServiceWorkerContainer}} has an associated service worker client, which is a service worker client whose global object is associated with the {{Navigator}} object or the {{WorkerNavigator}} object that the {{ServiceWorkerContainer}} is retrieved from.
+A {{ServiceWorkerContainer}} has an associated service worker client, which is a service worker client whose global object is associated with the {{Navigator}} object or the {{WorkerNavigator}} object that the {{ServiceWorkerContainer}} is retrieved from.
A {{ServiceWorkerContainer}} object has an associated ready promise (a promise). It is initially set to a new promise.
@@ -1181,15 +1181,15 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/auxiliary
"
- The window client's global object's browsing context is an auxiliary browsing context.
The window client's global object's browsing context is an auxiliary browsing context.
top-level
"
- The window client's global object's browsing context is a top-level browsing context.
The window client's global object's browsing context is a top-level browsing context.
nested
"
- The window client's global object's browsing context is a nested browsing context.
The window client's global object's browsing context is a nested browsing context.
none
"TypeError
and abort these steps.window
", and client is a window client, then:
The user agent should not terminate the service worker associated with e's relevant settings object's global object until e's extensions allowed flag is unset. However, the user agent may impose a time limit to this lifetime extension.
+The user agent should not terminate the service worker associated with e's relevant settings object's global object until e's extensions allowed flag is unset. However, the user agent may impose a time limit to this lifetime extension.
The user agent must create a {{CacheStorage}} object when a {{Window}} object or a {{WorkerGlobalScope}} object is created and associate it with that object.
-A CacheStorage
object represents a name to cache map of its associated global object's environment settings object's origin. Multiple separate objects implementing the {{CacheStorage}} interface across documents and workers can all be associated with the same name to cache map simultaneously.
A CacheStorage
object represents a name to cache map of its associated global object's environment settings object's origin. Multiple separate objects implementing the {{CacheStorage}} interface across documents and workers can all be associated with the same name to cache map simultaneously.
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:
install
, which does not bubble and is not cancelable.Resources will now use the service worker registration instead of the existing application cache.
activate
, which does not bubble and is not cancelable.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 is set to 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.
This effectively means that the fetch events and the other functional events such as push events are backed up by the registration's task queues while the other tasks including message events are discarded.
@@ -3297,7 +3297,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/true
if request's client is a window client and the event was dispatched with the user's intention for the page reload, and false
otherwise.The task must use activeWorker's event loop and the handle functional event task source.
A service worker is a type of web worker. A service worker executes in the registering service worker client’s origin.
-A service worker has an associated state, which is one of parsed, installing, installed, activating, activated, and redundant. It is initially parsed.
-A service worker has an associated script url (a URL).
-A service worker has an associated type which is either "classic
" or "module
". Unless stated otherwise, it is "classic
".
A service worker has an associated containing service worker registration (a service worker registration), which contains itself.
-A service worker has an associated id (an opaque string), which uniquely identifies itself during the lifetime of its containing service worker registration.
-A service worker is dispatched a set of lifecycle events, install and activate, and functional events including fetch.
-A service worker has an associated script resource (a script), which represents its own script resource. It is initially set to null. A script resource has an associated has ever been evaluated flag. It is initially unset. A script resource has an associated HTTPS state which is "none
", "deprecated
", or "modern
". Unless stated otherwise, it is "none
".
A service worker has an associated script resource map which is a List of the Record {[[key]], [[value]]} where [[key]] is a URL and [[value]] is a response.
-A service worker has an associated skip waiting flag. Unless stated otherwise it is unset.
-A service worker has an associated imported scripts updated flag. It is initially unset.
-A service worker has an associated set of event types to handle whose element type is an event listener’s event type. It is initially set to null.
+A service worker is a type of web worker. A service worker executes in the registering service worker client’s origin.
+A service worker has an associated state, which is one of parsed, installing, installed, activating, activated, and redundant. It is initially parsed.
+A service worker has an associated script url (a URL).
+A service worker has an associated type which is either "classic
" or "module
". Unless stated otherwise, it is "classic
".
A service worker has an associated containing service worker registration (a service worker registration), which contains itself.
+A service worker has an associated id (an opaque string), which uniquely identifies itself during the lifetime of its containing service worker registration.
+A service worker is dispatched a set of lifecycle events, install and activate, and functional events including fetch.
+A service worker has an associated script resource (a script), which represents its own script resource. It is initially set to null. A script resource has an associated has ever been evaluated flag. It is initially unset. A script resource has an associated HTTPS state which is "none
", "deprecated
", or "modern
". Unless stated otherwise, it is "none
".
A service worker has an associated script resource map which is a List of the Record {[[key]], [[value]]} where [[key]] is a URL and [[value]] is a response.
+A service worker has an associated skip waiting flag. Unless stated otherwise it is unset.
+A service worker has an associated imported scripts updated flag. It is initially unset.
+A service worker has an associated set of event types to handle whose element type is an event listener’s event type. It is initially set to null.
The lifetime of a service worker is tied to the execution lifetime of events and not references held by service worker clients to the ServiceWorker
object.
ServiceWorker
For example, consider a document created by a navigation to https://example.com/app.html
which matches via the following registration call which has been previously executed:
// Script on the page https://example.com/app.html -navigator.serviceWorker.register("/service_worker.js", { scope: "/" }); -+navigator.serviceWorker.register("/service_worker.js", { scope: "/" });
The value of navigator.serviceWorker.controller.scriptURL
will be "https://example.com/service_worker.js
".
ServiceWorkerGlobalScope
object associated with serviceWorker.
MessagePort
objects in cloneRecord.[[TransferList]], if any, maintaining their relative order.
@@ -1866,7 +1864,7 @@ ExtendableMessageEvent
interface, with the event type message, which does not bubble and is not cancelable.
data
attribute of e be initialized to clonedMessage.
- origin
attribute of e be initialized to the Unicode serialisation of incumbentSettings’s origin.
+ origin
attribute of e be initialized to the Unicode serialization of incumbentSettings’s origin.
ServiceWorkerGlobalScope
object, let the source
attribute of e be initialized to a new ServiceWorker
object that represents incumbentGlobal’s service worker.
Window
object, let the source
attribute of e be initialized to a new WindowClient
object that represents incumbentGlobal’s browsing context.
Client
object that represents the worker associated with incumbentGlobal.
@@ -2269,8 +2267,7 @@ ServiceWorkerGlobalScope
ServiceWorkerMessageEvent
interface, with the event type message, which does not bubble and is not cancelable.
data
attribute of e be initialized to clonedMessage.
- origin
attribute of e be initialized to the Unicode serialisation of sourceSettings’s origin.
- source
attribute of e be initialized to a ServiceWorker
object, which represents the service worker associated with sourceSettings’s global object.
+ origin
attribute of e be initialized to the Unicode serialization of sourceSettings’s origin.
+ source
attribute of e be initialized to a ServiceWorker
object, which represents the service worker associated with sourceSettings’s global object.
ports
attribute of e be initialized to newPorts.
CacheStorage
interface is designed to largely conform to ECMAScript 6 Map objects but entirely async, and with additional convenience methods. The methods, clear
, forEach
, entries
and values
, are intentionally excluded from the scope of the first version resorting to the ongoing discussion about the async iteration by TC39.
The user agent must create a CacheStorage
object when a Window
object or a WorkerGlobalScope
object is created and associate it with that object.
A CacheStorage
object represents a name to cache map of its associated global object’s environment settings object’s origin. Multiple separate objects implementing the CacheStorage
interface across documents and workers can all be associated with the same name to cache map simultaneously.
A CacheStorage
object represents a name to cache map of its associated global object’s environment settings object’s origin. Multiple separate objects implementing the CacheStorage
interface across documents and workers can all be associated with the same name to cache map simultaneously.
match(request, options)
match(request, options)
method must run these steps:
Specifications may define an API tied to a service worker registration by using partial interface definition to the ServiceWorkerRegistration
interface where it may define the specification specific attributes and methods:
partial interface ServiceWorkerRegistration { +partial interface ServiceWorkerRegistration { // e.g. define an API namespace - readonly attribute APISpaceType APISpace; + readonly attribute APISpaceType APISpace; // e.g. define a method - Promise<T> methodName(list of arguments); + Promise<T> methodName(/* list of arguments */); };
Specifications may define a functional event by extending ExtendableEvent
interface:
// e.g. define FunctionalEvent interface -interface FunctionalEvent : ExtendableEvent { ++});// e.g. define FunctionalEvent interface +interface FunctionalEvent : ExtendableEvent { // add a functional event’s own attributes and methods };@@ -3662,8 +3659,8 @@
@@ -4139,7 +4136,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:partial interface ServiceWorkerGlobalScope { - attribute EventHandler onfunctionalevent; +partial interface ServiceWorkerGlobalScope { + attribute EventHandler onfunctionalevent; };JavaScript execution context.
Let workerEventLoop be a newly created event loop. - Let workerGlobalScope be realmExecutionContext’s global object. + Let workerGlobalScope be realmExecutionContext’s global object. Let settingsObject be a new environment settings object whose algorithms are defined as follows: @@ -4832,8 +4829,7 @@
// "/js" in this example navigator.serviceWorker.register("/js/sw.js").then(function() { console.log("Install succeeded with the default scope '/js'."); -}); -