close() is supported in the DedicatedWorkerGlobalScope (source), but not the ServiceWorkerGlobalScope.
In Manifest V3, the latest version of the Web Extensions platform, extensions can use service workers as a background context. In the Web Extensions Community Group, we have been discussing a feature request to support the immediate termination of a service worker.
We would prefer a spec level solution over an extension specific API so filing this issue.
There are a few key use cases we have identified:
- A developer is handling sensitive data in the service worker (e.g a password manager). When the user asks the password manager to lock, immediately terminating the service worker would provide some additional certainty that any data in memory can be freed (source).
- A developer is writing tests and wants to immediately terminate the service worker (source).
- In general, a service worker no longer has any work to perform and wishes to free up resources.
I found #865 which has some of the history: it appears this initially threw an error, and was then moved to avoid exposing it entirely. But I couldn't find any specific motivations for not supporting it.
close()is supported in the DedicatedWorkerGlobalScope (source), but not the ServiceWorkerGlobalScope.In Manifest V3, the latest version of the Web Extensions platform, extensions can use service workers as a background context. In the Web Extensions Community Group, we have been discussing a feature request to support the immediate termination of a service worker.
We would prefer a spec level solution over an extension specific API so filing this issue.
There are a few key use cases we have identified:
I found #865 which has some of the history: it appears this initially threw an error, and was then moved to avoid exposing it entirely. But I couldn't find any specific motivations for not supporting it.