JavaScript APIs

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

To use the more powerful APIs you need to request permission in your add-on'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 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.

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 (en-US).

browsingData

WebExtensions 을 통해 사용자가 브라우저를 사용하는 동안 축적된 데이터를 삭제할 수 있는 기능을 제공합니다.

contentScripts

이 API는 콘텐츠 스크립트를 등록한다. 등록된 콘텐츠 스크립트는 브라우저가 URL 패턴이 일치하는 페이지에 넣는다.

contextMenus

브라우저의 메뉴 시스템에 항목을 추가한다.

pageAction

페이지 액션 (en-US)은 브라우저의 주소창에 있는 아이콘이다.

storage

웹확장이 데이터를 저장하고, 확인하고, 저장된 항목의 변화를 감시할 수 있도록 해 준다.

tabs

Interact with the browser's tab system.

webRequest

Add event listeners for the various stages of making an HTTP request. The event listener receives detailed information about the request and can modify or cancel the request.