background
Type | Object |
---|---|
Mandatory | No |
Example | "background": { "scripts": ["background.js"] } |
Use the background
key to include one or more background scripts, and optionally a background page in your extension.
Background scripts are the place to put code that needs to maintain long-term state, or perform long-term operations, independently of the lifetime of any particular web pages or browser windows.
Background scripts are loaded as soon as the extension is loaded and stay loaded until the extension is disabled or uninstalled, unless persistent
is specified as false
. You can use any of the WebExtension APIs in the script, as long as you have requested the necessary permissions.
See the "Background pages" section in Anatomy of an extension for some more details.
The background
key is an object that may have one of the following two properties, both optional:
scripts | An The scripts share the same The scripts are loaded in the order they appear in the array. If you specify a value for Note: If you want to fetch a script from a remote location with the Note: In Firefox prior to version 50, when the debugger is open, scripts are not always loaded in the order given in the array. To work around this bug, you can use the |
page | If you need some particular content in the page, you can define your own page using the If you use this property, you can not specify background scripts using |
The background
key can also contain the following optional property:
persistent | A
|
Example
"background": { "scripts": ["jquery.js", "my-background.js"] }
Load two background scripts.
"background": { "page": "my-background.html" }
Load a custom background page.
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
background |
Yes |
14 |
48 |
? |
Yes |
14 |
? |
? |
48 |
? |
? |
? |
page |
Yes |
14 |
48 |
? |
Yes |
14 |
? |
? |
48 |
? |
? |
? |
persistent |
Yes |
14
The 'persistent' property is mandatory.
|
48
["Only persistent pages are supported.", "Before version 66, Firefox would log a warning even if the value was set to
true ."] |
? |
Yes |
14
Before 14.1, only persistent pages are supported.
|
? |
? |
48
["Only persistent pages are supported.", "Before version 66, Firefox would log a warning even if the value was set to
true ."] |
? |
? |
? |
scripts |
Yes |
14 |
48
Before Firefox 50, when the debugger is open, scripts are not always loaded in the order given in the array.
|
? |
Yes |
14 |
? |
? |
48
Before Firefox 50, when the debugger is open, scripts are not always loaded in the order given in the array.
|
? |
? |
? |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/background