Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Nos bénévoles n'ont pas encore traduit cet article en Français. Aidez-nous à réaliser cette tâche !

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The Permissions API provides a consistent programmatic way to query the status of API permissions attributed to the current context — for example whether permission to use the API is granted or denied, and whether the user will be asked whether permission should be granted for an API.

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.

At the time of writing, only the Geolocation, Notifications, Push , and WebMIDI APIs are recognised by the Permissions API, with Chrome only including the first two. This list will grow as the API is implemented further.

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 API Editor's Draft Initial definition.

Browser Support

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 43.0 46 (46) ? ? ?
revoke() ? 47 (47) ? ? ?
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support No support 43.0 46.0 (46) ?[1] ? ? ? 43.0
revoke() ? ? ? ?[1] ? ? ? ?

[1] Firefox OS currently uses its own proprietary Permissions API, which works in a different way: see Permissions API (Firefox OS).

See also

Using the Permissions API

Étiquettes et contributeurs liés au document

 Dernière mise à jour par : mnoorenberghe,