permissions.request()

Asks the user for the permissions listed in a permissions.Permissions object.

The permissions requested must be listed in the extension's:

  • optional_permissions key of its manifest.json file for origins and permissions. The origins property can include permissions matching a subset of the hosts matched by an optional permission. For example, if optional_permissions include "*://mozilla.org/", then permissions.origins can include "https://developer.mozilla.org/".
  • gecko.data_collection_permissions.optional property of the browser_specific_settings key of its manifest.json file for data_collection.

Requests for optional-only permissions can't include any other optional permissions.

The extension can only make the request inside the handler for a user action. Unless the browser can grant all the requested permissions silently, it prompts the user to grant them. The browser makes one request for all requested permissions: either all are granted, or none are.

The extension retains any permissions granted, even over upgrade and disable and enable cycling.

Syntax

js
let requesting = browser.permissions.request(
  permissions                // Permissions object
)

Parameters

permissions

A permissions.Permissions object.

Return value

A Promise fulfilled with true if the browser grants the extension the permissions listed in the permissions argument, or false otherwise.

Examples

This code adds a click handler that prompts the user for various permissions, then logs the request's outcome and the extension's permissions after the request completes.

js
const permissionsToRequest = {
  permissions: ["bookmarks", "history"],
  origins: ["https://developer.mozilla.org/"],
};

async function requestPermissions() {
  function onResponse(response) {
    if (response) {
      console.log("Permission was granted");
    } else {
      console.log("Permission was refused");
    }
    return browser.permissions.getAll();
  }

  const response = await browser.permissions.request(permissionsToRequest);
  const currentPermissions = await onResponse(response);

  console.log(`Current permissions:`, currentPermissions);
}

document
  .querySelector("#request")
  .addEventListener("click", requestPermissions);

Example extensions

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
request
Chrome – Full support
Chrome 16 (Release date: 2011-12-13)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 55 (Release date: 2017-08-08)
footnote
footnote It's not possible to request permissions from within DevTools (bug 1796933).
footnote Before version 101, permissions cannot be requested from a sidebar document (bug 1493396).
footnote Before version 75, permissions cannot be requested from popup panels (see bug 1432083).
footnote Before version 61, permissions cannot be requested from options pages embedded in about:addons (see bug 1382953).
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote
footnote Requesting <all_urls> or *://*/* origins will grant permission to request specific origin patterns and automatically prompt the user for access to any visited website via the extension's access popover in the toolbar.
footnote The user will be prompted again for permissions that have been previously granted and then removed.
footnote Supported permissions will be granted without prompting the user. Only specific origin patterns will prompt the user.
Firefox for Android – Full support
Firefox for Android 120 (Release date: 2023-11-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote
footnote Requesting <all_urls> or *://*/* origins will grant permission to request specific origin patterns and automatically prompt the user for access to any visited website via the extension's banner.
footnote The user will be prompted again for permissions that have been previously granted and then removed.
footnote Supported permissions will be granted without prompting the user. Only specific origin patterns will prompt the user.

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

Note: This API is based on Chromium's chrome.permissions API.