MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

Les APIs WebExtensions en JavaScript peuvent être utilisées au sein des scripts d'arrière plan de l'extension et dans tout autre document livré avec celle-ci. Ceci inclut les pop-ups relatives à une action navigateur ou action de page, barres latérales, pages d'options, ou pages de nouvel onglet. Certaines de ces APIs peuvent également être interrogées par des scripts de contenu de l'extension (voir la liste dans le guide des scripts de contenu).

Pour utiliser les APIs plus puissantes, vous devez en demander la permission dans le manifest.json de votre extension.

Vous pouvez accéder aux APIs en utilisant l'espace de noms browser :

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

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

De nombreuses APIs sont asynchrones et retournent une Promesse :

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

Notez que ceci est différent du système d'extension de Google Chrome, qui utilise l'espace de noms chrome à la place de browser, et qui utilise des fonctions de rappel (callbacks) plutôt que des promesses pour les fonctions asynchrones. Afin de favoriser la portabilité, l'implémentation Firefox des WebExtensions prend en charge chrome et les fonctions de rappel ainsi que browser et les promesses. Mozilla a également écrit une prothèse d'émulation (polyfill) permettant au code qui utilise browser et les promesses de fonctionner sans modification dans Chrome: https://github.com/mozilla/webextension-polyfill.

Microsoft Edge utilise l'espace de noms browser, mais ne supporte pas encore les APIs asynchrones basées sur les promesses. Avec Edge, à l'heure actuelle, les API asynchrones doivent utiliser des fonctions de rappel.

Tous les navigateurs ne sont pas compatibles avec toutes les APIs : pour de plus amples informations, consultez la compatibilité navigateur pour les APIs JavaScript.

alarms

Schedule code to run at a specific time in the future. This is like setTimeout() and setInterval(), except that those functions don't work with background pages that are loaded on demand.

API reference documentation

bookmarks

The WebExtensions bookmarks API lets an add-on interact with and manipulate the browser's bookmarking system. You can use it to bookmark pages, retrieve existing bookmarks, and edit, remove, and organize bookmarks.

API reference documentation

browserAction

Adds a button to the browser's toolbar.

API reference documentation

browsingData

Enables WebExtensions to clear data that is accumulated while the user is browsing.

API reference documentation

commands

Listen for the user executing commands that you have registered using the commands manifest.json key.

API reference documentation

contextMenus

Add items to the browser's context menu, to be displayed in the contexts you specify. For example, you can show the item only when the user clicks on an image, or on an editable element, or when part of a page is selected.

API reference documentation

contextualIdentities

Work with contextual identities: list, create, remove, and update contextual identities.

API reference documentation

cookies

Enables WebExtensions to get and set cookies, and be notified when they change.

API reference documentation

devtools.inspectedWindow

The devtools.inspectedWindow API lets a devtools add-on interact with the window that the developer tools are attached to.

API reference documentation

devtools.network

The devtools.network API lets a devtools add-on get information about network requests associated with the window that the devtools are attached to (the inspected window).

API reference documentation

devtools.panels

The devtools.panels API lets a devtools add-on define its user interface inside the devtools window.

API reference documentation

downloads

Enables WebExtensions to interact with the browser's download manager. You can use this API module to download files, cancel, pause, resume downloads, and show downloaded files in the file manager.

API reference documentation

events

Common types used by APIs that dispatch events.

API reference documentation

extension

Utilities related to your add-on. Get URLs to resources packages with your add-on, get the Window object for your add-on's pages, get the values for various settings. Note that the messaging APIs in this module are deprecated in favor of the equivalent APIs in the runtime module.

API reference documentation

extensionTypes

Some common types used in other WebExtension APIs.

API reference documentation

history

Use the history API to interact with the browser history.

API reference documentation

i18n

Functions to internationalize your add-on. You can use these APIs to get localized strings from locale files packaged with your add-on, find out the browser's current language, and find out the value of its Accept-Language header.

API reference documentation

identity

Use the identity API to get an OAuth2 authorization code or access token, which an add-on can then use to access user data from a service which supports OAuth2 access (such as a Google or a Facebook account).

API reference documentation

idle

Find out when the user's system is idle, locked, or active.

API reference documentation

management

Get information about installed add-ons.

API reference documentation

notifications

Display notifications to the user, using the underlying operating system's notification mechanism. Because this API uses the operating system's notification mechanism, the details of how notifications appear and behave may differ according to the operating system and the user's settings.

API reference documentation

omnibox

Enables WebExtensions to implement customised behavior when the user types into the browser's address bar.

API reference documentation

pageAction

A page action is a clickable icon inside the browser's address bar.

API reference documentation

permissions

Add-ons need permissions to access many of the more powerful WebExtension APIs. They can ask for permissions at install time by including the permissions they need in the permissions manifest.json key. The main advantages of asking for permissions at install time are:

API reference documentation

privacy

Access and modify various privacy-related browser settings.

API reference documentation

proxy

Use the proxy API to register an extended Proxy Auto-Configuration (PAC) file, which implements a policy for proxying web requests.

API reference documentation

runtime

This module provides information about your add-on and the environment it's running in.

API reference documentation

sessions

Use the sessions API to list, and restore, tabs and windows that have been closed while the browser has been running.

API reference documentation

sidebarAction

Gets and sets properties of an add-on's sidebar.

API reference documentation

storage

Enables WebExtensions to store and retrieve data, and listen for changes to stored items.

API reference documentation

tabs

Interact with the browser's tab system.

API reference documentation

topSites

Use the topSites API to get an array containing all the sites listed in the browser's "New Tab" page.

API reference documentation

types

Defines the BrowserSetting type, which is used to represent a browser setting.

API reference documentation

webNavigation

Add event listeners for the various stages of a navigation. A navigation consists of a frame in the browser transitioning from one URL to another, usually (but not always) in response to a user action like clicking a link or entering a URL in the location bar.

API reference documentation

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.

API reference documentation

windows

Interact with browser windows. You can use this API to get information about open windows and to open, modify, and close windows. You can also listen for window open, close, and activate events.

API reference documentation

Étiquettes et contributeurs liés au document

Étiquettes : 
 Contributeurs à cette page : hellosct1, Badacadabra, wbamberg
 Dernière mise à jour par : hellosct1,