extension.getBackgroundPage()

Returns the Window of the background page if the background script is running. If the script is not running, null is returned.

This a synchronous function.

Note: This method cannot be used in Private Browsing mode — it always returns null. Consider using runtime.sendMessage() or runtime.connect(). See Firefox bug 1329304 for more information.

Syntax

js
let page = browser.extension.getBackgroundPage()

Parameters

None.

Return value

object. Window of the background page or null.

Examples

Suppose a background script defines a function foo():

js
// background.js

function foo() {
  console.log("I'm defined in background.js");
}

A script running in a popup can call this function directly like this:

js
// popup.js

let page = browser.extension.getBackgroundPage();
page.foo(); // -> "I'm defined in background.js"

Example extensions

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
getBackgroundPage
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 48 (Release date: 2016-08-02)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Note: This API is based on Chromium's chrome.extension API. This documentation is derived from extension.json in the Chromium code.