JavaScript APIs for WebExtensions can be used inside the extension's background scripts and in any other documents bundled with the extension, including browser action or page action popups, sidebars, options pages, or new tab pages. A few of these APIs can also be accessed by an extension's content scripts (see the list in the content script guide).

To use the more powerful APIs you need to request permission in your extension's manifest.json.

You can access the APIs using the browser namespace:

function logTabs(tabs) {
  console.log(tabs);
}

browser.tabs.query({currentWindow: true}, logTabs);

Many of the APIs are asynchronous, returning a Promise:

function logCookie(c) {
  console.log(c);
}

function logError(e) {
  console.error(e);
}

var setCookie = browser.cookies.set(
  {url: "https://developer.mozilla.org/"}
);
setCookie.then(logCookie, logError);

Note that this is different from Google Chrome's extension system, which uses the chrome namespace instead of browser, and which uses callbacks instead of promises for asynchronous functions. As a porting aid, the Firefox implementation of WebExtensions APIs supports chrome and callbacks as well as browser and promises. Mozilla has also written a polyfill which enables code that uses browser and promises to work unchanged in Chrome: https://github.com/mozilla/webextension-polyfill.

Firefox also implements these APIs under the chrome namespace using callbacks. This allows code written for Chrome to run largely unchanged in Firefox for the APIs documented here.

Microsoft Edge uses the browser namespace, but doesn't yet support promise-based asynchronous APIs. In Edge, for the time being, asynchronous APIs must use callbacks.

Not all browsers support all the APIs: for the details, see Browser support for JavaScript APIs.

alarms

API reference documentation

bookmarks

API reference documentation

browserAction

API reference documentation

browserSettings

API reference documentation

browsingData

API reference documentation

clipboard

API reference documentation

commands

API reference documentation

contentScripts

API reference documentation

contextualIdentities

API reference documentation

cookies

API reference documentation

devtools.inspectedWindow

API reference documentation

devtools.network

API reference documentation

devtools.panels

API reference documentation

dns

API reference documentation

downloads

API reference documentation

events

API reference documentation

extension

API reference documentation

extensionTypes

API reference documentation

find

API reference documentation

history

API reference documentation

i18n

API reference documentation

identity

API reference documentation

idle

API reference documentation

management

API reference documentation

API reference documentation

notifications

API reference documentation

omnibox

API reference documentation

pageAction

API reference documentation

permissions

API reference documentation

pkcs11

API reference documentation

privacy

API reference documentation

proxy

API reference documentation

runtime

API reference documentation

API reference documentation

sessions

API reference documentation

sidebarAction

API reference documentation

storage

API reference documentation

tabs

API reference documentation

theme

API reference documentation

topSites

API reference documentation

types

API reference documentation

webNavigation

API reference documentation

webRequest

API reference documentation

windows

API reference documentation

Document Tags and Contributors

Tags: 
Contributors to this page: wbamberg, ExE-Boss, stephaniehobson, Makyen, andrewtruongmoz, Sheppy
Last updated by: wbamberg,