[w3c/ServiceWorker] @MMMMCCCCBOT (Issue #1682)

nt task source
This task source is used for features that dispatch other functional events, e.g. push events, to service workers.

Note: A user agent may use a separate task source for each functional event type in order to avoid a head-of-line blocking phenomenon for certain functional events.

2.7. User Agent Shutdown
A user agent must maintain the state of its stored service worker registrations across restarts with the following rules:

An installing worker does not persist but is discarded. If the installing worker was the only service worker for the service worker registration, the service worker registration is discarded.

A waiting worker promotes to an active worker.

To attain this, the user agent must invoke Handle User Agent Shutdown when it terminates.

3. Client Context
Bootstrapping with a service worker:
// scope defaults to the path the script sits in
// "/" in this example
navigator.serviceWorker.register("/serviceworker.js").then(registration => {
  console.log("success!");
  if (registration.installing) {
    registration.installing.postMessage("Howdy from your installing page.");
  }
}, err => {
  console.error("Installing the worker failed!", err);
});
3.1. ServiceWorker
✔MDN
[SecureContext, Exposed=(Window,Worker)]
interface ServiceWorker : EventTarget {
  readonly attribute USVString scriptURL;
  readonly attribute ServiceWorkerState state;
  undefined postMessage(any message, sequence<object> transfer);
  undefined postMessage(any message, optional StructuredSerializeOptions options = {});

  // event
  attribute EventHandler onstatechange;
};
ServiceWorker includes AbstractWorker;

enum ServiceWorkerState {
  "parsed",
  "installing",
  "installed",
  "activating",
  "activated",
  "redundant"
};
A ServiceWorker object represents a service worker. Each ServiceWorker object is associated with a service worker. Multiple separate objects implementing the ServiceWorker interface across documents and workers can all be associated with the same service worker simultaneously.

A ServiceWorker object has an associated ServiceWorkerState object which is itself associated with service worker's state.

3.1.1. Getting ServiceWorker instances
An environment settings object has a service worker object map, a map where the keys are service workers and the values are ServiceWorker objects.

To get the service worker object representing serviceWorker (a service worker) in environment (an environment settings object), run these steps:
Let objectMap be environment’s service worker object map.

If objectMap[serviceWorker] does not exist, then:

Let serviceWorkerObj be a new ServiceWorker in environment’s Realm, and associate it with serviceWorker.

Set serviceWorkerObj’s state to serviceWorker’s state.

Set objectMap[serviceWorker] to serviceWorkerObj.

Return objectMap[serviceWorker].

3.1.2. scriptURL
✔MDN
The scriptURL getter steps are to return the service worker's serialized script url.

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");
The value of navigator.serviceWorker.controller.scriptURL will be "https://example.com/service_worker.js".

3.1.3. state
✔MDN
The state attribute must return the value (in ServiceWorkerState enumeration) to which it was last set.

3.1.4. postMessage(message, transfer)
The postMessage(message, transfer) method steps are:

Let options be «[ "transfer" → transfer ]».

Invoke postMessage(message, options) with message and options as the arguments.

3.1.5. postMessage(message, options)
The postMessage(message, options) method steps are:

Let serviceWorker be the service worker represented by this.

Let incumbentSettings be the incumbent settings object.

Let incumbentGlobal be incumbentSettings’s global object.

Let serializeWithTransferResult be StructuredSerializeWithTransfer(message, options["transfer"]). Rethrow any exceptions.

If the result of runni

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1682
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/issues/1682@github.com>

Received on Friday, 26 May 2023 19:28:55 UTC