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 or page action popups, sidebars, options pages, 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.

browsingData
WebExtensions ์„ ํ†ตํ•ด ์‚ฌ์šฉ์ž๊ฐ€ ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ ์ถ•์ ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ญ์ œํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
contentScripts
์ด API๋Š” ์ฝ˜ํ…์ธ  ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋“ฑ๋กํ•œ๋‹ค. ๋“ฑ๋ก๋œ ์ฝ˜ํ…์ธ  ์Šคํฌ๋ฆฝํŠธ๋Š” ๋ธŒ๋ผ์šฐ์ €๊ฐ€ URL ํŒจํ„ด์ด ์ผ์น˜ํ•˜๋Š” ํŽ˜์ด์ง€์— ๋„ฃ๋Š”๋‹ค.
contextMenus
๋ธŒ๋ผ์šฐ์ €์˜ ๋ฉ”๋‰ด ์‹œ์Šคํ…œ์— ํ•ญ๋ชฉ์„ ์ถ”๊ฐ€ํ•œ๋‹ค.
pageAction
ํŽ˜์ด์ง€ ์•ก์…˜์€ ๋ธŒ๋ผ์šฐ์ €์˜ ์ฃผ์†Œ์ฐฝ์— ์žˆ๋Š” ์•„์ด์ฝ˜์ด๋‹ค.
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.