- From: Jake Archibald <notifications@github.com>
- Date: Fri, 19 Feb 2021 06:00:01 -0800
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/ServiceWorker/issues/1566@github.com>
Certain events allow the service worker time to execute, after which it should be shut down, even if there's work pending (to preserve ram, battery, and privacy). The service worker shouldn't be able to give itself extra time to run, as it would be able to keep itself open indefinitely. To solve this, we should spec something like: --- A `ServiceWorkerGlobalScope` has a set of **keepalive handles**, each has: - An **expiry time**. - A **no-clients expiry time**. These handles are added as an optional part of dispatching an `ExtendableEvent`. They'd only be added by event dispatches that should give the service worker time, such as a fetch/`postMessage` from a page or a client that depends on a page to be alive (worker, shared worker, worklet etc etc), or a background activity event. The service worker checks the **keepalive handles** periodically, and compares the current time to the **expiry time** (if there are open clients) or the **no-clients expiry time** (if there are no clients). If the current time has passed that time, the handle is removed. All items in **keepalive handles** can be removed if all lifetime promises in every `ExtendableEvent` in the global have become settled. If the **keepalive handles** set becomes empty, the service worker is terminated regardless of ongoing work. The **keepalive handle** state can be mutated, for situations where the expiry times need to be changed during the life of the handle. Eg, we might reduce the expiry time of a handle associated with a fetch once the fetch is complete. In this model, if the service worker `postMessage`s itself, it won't create a new keepalive handle. This event can add lifetime promises, but it doesn't extend the expiry time of any handles. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3c/ServiceWorker/issues/1566
Received on Friday, 19 February 2021 14:00:13 UTC