runtime.getBackgroundPage()

Retrieves the Window for the add-on's background page.

This provides a convenient way for other privileged extension scripts, such as scripts running in options pages, or scripts running in browser action or page action popups (but not content scripts), to get direct access to the background script's scope. This enables them to access variables or call functions defined in that scope.

If the background page is an event page, the system will ensure it is loaded before calling the callback. If the add-on does not include a background page, this function sets runtime.lastError.

Syntax

browser.runtime.getBackgroundPage(
  function(backgroundPage) {...} // function
)

Parameters

callback
function. The function is passed the following arguments:
backgroundPageOptional
object. Window for the background page, if there is one.

Browser compatibility

EdgeFirefoxChromeOpera
Basic support?45.0Yes33
Firefox
Basic support48.0

Examples

Acknowledgements

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

Document Tags and Contributors

 Contributors to this page: wbamberg
 Last updated by: wbamberg,