permissions.request()
Asks the user for the permissions listed in thepermissions.Permissions object.
ThePermissions argument can contain anorigins property, an array ofhost permissions, apermissions property, an array ofAPI permissions, or both.
Requested permissions must be defined in theoptional_permissions manifest.json key. Theorigins property can include permissions matching a subset of the hosts matched by an optional permission. For example, ifoptional_permissions include"*://mozilla.org/", thenpermissions.origins can include"https://developer.mozilla.org/".
Requests foroptional-only permissions can't include any other optional permissions.
The request can only be made inside the handler for auser action. Unless all the permissions requested are ones granted silently, the browser asks the user whether to grant the requested permissions. One request is made for all requested permissions: either all permissions are granted or none are.
The extension retains any permissions granted, even over upgrade and disable and enable cycling.
This is an asynchronous function that returns aPromise.
In this article
Syntax
let requesting = browser.permissions.request( permissions // Permissions object)Parameters
permissionsA
permissions.Permissionsobject.
Return value
APromise that is fulfilled withtrue if the extension is granted the permissions listed in thepermissions argument, orfalse otherwise.
Examples
This code adds a click handler that asks for various permissions, then logs the result of the request and the extension's permissions after the request completes.
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
Note:This API is based on Chromium'schrome.permissions API.