Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

META: background scripting #101

Closed
10 tasks
carlosjeurissen opened this issue Oct 4, 2021 · 0 comments
Closed
10 tasks

META: background scripting #101

carlosjeurissen opened this issue Oct 4, 2021 · 0 comments

Comments

@carlosjeurissen
Copy link
Contributor

carlosjeurissen commented Oct 4, 2021

To allow extensions to run tasks in the background when no UI is visible to the user or bound to be too insecure (like content_scripts), browsers provide the ability to run scripts in the background. The way this can be achieved has changed over time as shown below.

MV1 syntax (background_page)

MV1 only supported a persistent background page which you could define with the background_page property. This has been replaced with the background property in MV2.

MV2 syntax (background.scripts)

Manifest v2 introduced the background property which allows to define the background page using an object notation like this:

"background": {
  "page": "/background.html"
}

In addition to defining the page, it introduced the background.scripts property which allows the webExt author to define a set of scripts instead of a page. In which case the browser will generate the background page automatically and add the script tags to the body of the background page.

Then it introduced the background.persistent property. Which is true by default (needs confirmation by all browsers). This allows to either go for the classic background page, or opt in (by setting to false) to so called Event pages. These pages will only run when needed by the extension. See Chrome MV2 Docs.
Inconsistencies: the event pages are currently not supported by Firefox yet mandatory on iOS Safari. In macOS Safari < v14.1, only persistent pages were supported. In addition, Microsoft edge < v45 requires the persistent property to be set.

MV3 syntax (background.service_worker)

A new syntax has been proposed with MV3 to replace the background pages and scripts with background.service_worker. The other properties page, scripts and persistent are not accepted anymore. A new background.type property is introduced which can be set to "module" which allows you to import further code. See Chrome MV3 SW Docs. This new syntax is also supported in MV2 in Google Chrome starting in version xxx without flags. The service_worker can be killed at any time unlike the persistent background pages and lacks web APIs not available in serviceWorkers. Some webExt APIs are also unavailable like i18n.getMessage, see #93.

Group issues related to background.service_worker

As some may be aware there are quite some issues and incompatibilities when switching from background pages to serviceWorkers. A dedicated issue is made collecting all use cases not covered by serviceWorkers:

Not included in this overview are:

Proposals to improve the background.service_worker situation

Action items

@carlosjeurissen carlosjeurissen changed the title background property Overview: background property Oct 4, 2021
@carlosjeurissen carlosjeurissen changed the title Overview: background property Overview: background scripting Oct 5, 2021
@carlosjeurissen carlosjeurissen changed the title Overview: background scripting META: background scripting Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant