Permissions API

Questo contenuto viene visualizzato in inglese perché non è ancora disponibile una versione tradotta nella lingua selezionata. Aiutaci a tradurre questo articolo!

The Permissions API provides a consistent programmatic way to query the status of API permissions attributed to the current context. For example, the Permissions API can be used to determine if permission to access a particular API has been granted or denied.

Concepts and usage

Historically different APIs handle their own permissions inconsistently — for example the Notifications API allows for explicit checking of permission status and requesting permission, whereas the Geolocation API doesn't (which causes problems if the user denied the initial permission request). The Permissions API provides the tools to allow developers to implement a better user experience as far as permissions are concerned.

The permissions property has been made available on the Navigator object, both in the standard browsing context and the worker context (WorkerNavigator — so permission checks are available inside workers), and returns a Permissions object that provides access to the Permissions API functionality.

Once you have this object you can then perform permission-related tasks, for example querying a permission using the Permissions.query() method to return a promise that resolves with the PermissionStatus for a specific API.

Not all APIs' permission statuses can be queried using the Permissions API. Notable APIs that are Permissions-aware include:

More APIs will gain Permissions API support over time.

Examples

We have made a simple example available called Location Finder. You can run the example live, or view the source code on Github.

Read more about how it works in our article Using the Permissions API.

Interfaces

Navigator.permissions and WorkerNavigator.permissions Read only
Provides access to the Permissions object from the main context and worker context respectively.
Permissions
Provides the core Permission API functionality, such as methods for querying and revoking permissions.
PermissionStatus
Provides access to the current status of a permission, and an event handler to respond to changes in permission status.

Specification

Specification Status Comment
Permissions Working Draft Initial definition.

Browser compatibility

Permissions interface

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
PermissionsChrome Full support 43Edge No support NoFirefox Full support 46IE No support NoOpera Full support YesSafari No support NoWebView Android Full support 43Chrome Android Full support 43Firefox Android Full support 46Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes
accelerometer permissonChrome Full support 62Edge No support NoFirefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 62Chrome Android Full support 62Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android ?
accessibility events permissonChrome Full support 62Edge No support NoFirefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 62Chrome Android Full support 62Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android ?
ambient-light-sensor permissonChrome Full support 62Edge No support NoFirefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 62Chrome Android Full support 62Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android ?
accelerometer permissonChrome Full support 62Edge No support NoFirefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 62Chrome Android Full support 62Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android ?
camera permissionChrome Full support 64Edge No support NoFirefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 64Chrome Android Full support 64Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android ?
clipboard-read permissonChrome Full support 64Edge No support NoFirefox No support NoIE No support NoOpera ? Safari No support NoWebView Android Full support 64Chrome Android Full support 64Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android ?
clipboard-write permissionChrome Full support 64Edge No support NoFirefox No support NoIE No support NoOpera ? Safari No support NoWebView Android Full support 64Chrome Android Full support 64Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android ?
geolocation permissionChrome Full support 43Edge No support NoFirefox ? IE No support NoOpera Full support 30Safari No support NoWebView Android No support NoChrome Android Full support 43Firefox Android ? Opera Android Full support 30Safari iOS No support NoSamsung Internet Android ?
background-sync permissionChrome Full support 51Edge No support NoFirefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 51Chrome Android Full support 51Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android ?
magnetometer permissionChrome Full support 62Edge No support NoFirefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 62Chrome Android Full support 62Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android ?
microphone permissionChrome Full support 64Edge No support NoFirefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 64Chrome Android Full support 64Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android ?
midi permissionChrome Full support 43Edge No support NoFirefox ? IE No support NoOpera Full support 30Safari No support NoWebView Android No support NoChrome Android Full support 43Firefox Android ? Opera Android Full support 30Safari iOS No support NoSamsung Internet Android ?
notifications permissionChrome Full support 43Edge No support NoFirefox ? IE No support NoOpera Full support 30Safari No support NoWebView Android No support NoChrome Android Full support 43Firefox Android ? Opera Android Full support 30Safari iOS No support NoSamsung Internet Android ?
payment-handler permissionChrome Full support 66Edge No support NoFirefox ? IE No support NoOpera ? Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android ?
persistent-storage permissionChrome Full support 71Edge No support NoFirefox Full support 53IE No support NoOpera Full support 58Safari No support NoWebView Android Full support 71Chrome Android Full support 71Firefox Android Full support 53Opera Android Full support 50Safari iOS No support NoSamsung Internet Android No support No
push permissionChrome Full support 43Edge No support NoFirefox ? IE No support NoOpera Full support 30Safari No support NoWebView Android No support NoChrome Android Full support 43Firefox Android ? Opera Android Full support 30Safari iOS No support NoSamsung Internet Android ?
queryChrome Full support 43Edge No support NoFirefox Full support 46IE No support NoOpera Full support YesSafari No support NoWebView Android Full support 43Chrome Android Full support 43Firefox Android Full support 46Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes
request
ExperimentalNon-standard
Chrome Full support 46Edge No support NoFirefox No support NoIE No support NoOpera ? Safari No support NoWebView Android Full support 46Chrome Android Full support 46Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android ?
requestAll
ExperimentalNon-standard
Chrome Full support 48Edge No support NoFirefox No support NoIE No support NoOpera ? Safari No support NoWebView Android Full support 48Chrome Android Full support 48Firefox Android No support NoOpera Android ? Safari iOS No support NoSamsung Internet Android ?
revoke
ExperimentalNon-standard
Chrome Full support 46Edge No support NoFirefox Full support 51
Disabled
Full support 51
Disabled
Disabled From version 51: this feature is behind the dom.permissions.revoke.enable preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support 47 — 51
IE No support NoOpera ? Safari No support NoWebView Android Full support 46Chrome Android Full support 46Firefox Android Full support 51
Disabled
Full support 51
Disabled
Disabled From version 51: this feature is behind the dom.permissions.revoke.enable preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support 47 — 51
Opera Android ? Safari iOS No support NoSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also