Skip to content

Introduce runtime.waitUntil API to keep background service worker / event page active during a specific task #416

Description

@Rob--W

Extension Service workers and (limited) event pages are terminated when they are idle for a period of time. The mechanisms for determining the termination triggers vary by browser version *, and extensions do currently not have an explicit mechanism to extend the lifetime until the completion of a specific task. This is a proposal for the runtime.waitUntil method to do so.

* Chrome used to terminate service workers after 5 minutes, until recently when that restriction was lifted : extensions can extend their service worker's lifetime when they are actively calling extension APIs or handling events, and even some web platform APIs (see history of changes by Chrome version). The advantage of integrating the lifetime in specific web platform APIs is greater control by the browser. The downside is that the set of lifetime-extending APIs is seemingly arbitrary and the expected behavior cannot easily be determined (e.g. by developers or code reviewers).

On to the proposal:

  • Add a runtime.waitUntil method, modeled after the ExtendableEvent's waitUntil method.
  • It extends the lifetime of the background context until the completion of the task, observed through settling the promise.
  • We can consider additional restrictions to avoid accidental or intentional long-lived contexts. For example:
    • a (default) deadline after which waitUntil stops blocking termination.
    • restricting the API to specific control flows, e.g. from an extension event.
    • requiring justification in the API call for keeping the background alive. This could be embedded in a profiler annotation or the developer console to help with diagnosing unnecessarily long-running tasks.

Related discussions / bugs:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions