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) {

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

Many of the APIs are asynchronous, returning a Promise:

function logCookie(c) {

function logError(e) {

var setCookie = browser.cookies.set(
  {url: ""}
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:

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.

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