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.query()
method of the Permissions
interface returns the status of a user permission on the global scope.
Syntax
navigator.permissions.query(PermissionDescriptor).then(function(permissionStatus) { ... })
Parameters
PermissionDescriptor
- An object that sets options for the
query
operation consisting of a comma-separated list of name-value pairs. The available options are:name
: The name of the API whose permissions you want to query. Valid values are'geolocation'
,'midi'
,'notifications'
, and'push'
.userVisibleOnly
: (Push only, not supported in Firefox — see the Browser Support section below) Indicates whether you want to show a notification for every message or be able to send silent push notifications. The default isfalse
.sysex
: (Midi only) Indicates whether you need and/or receive system exclusive messages. The default isfalse
.
Note: As of Firefox 44, the permissions for Notifications and Push have been merged. If permission is granted (e.g. by the user, in the relevant permissions dialog), navigator.permissions.query()
will return true
for both notifications
and push
.
Returns
A Promise
that resolves to a PermissionStatus
object.
Exceptions
Exception | Explanation |
---|---|
TypeError |
Retrieving the PermissionDescriptor information failed in some way, or the permission doesn't exist or is currently unsupported (e.g. midi , or push with userVisibleOnly ). |
Example
navigator.permissions.query({name:'geolocation'}).then(function(result) { if (result.status == 'granted') { showLocalNewsWithGeolocation(); } else if (result.status == 'prompt') { showButtonToEnableLocalNews(); } // Don't do anything if the permission was denied. });
Specification
Specification | Status | Comment |
---|---|---|
Permissions API The definition of 'query()' in that specification. |
Editor's Draft | Initial definition. |
Browser Support
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 43.0 | 46 (46) 49 (49)[1] |
? | ? | ? |
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) 49.0 (49)[1] |
? | ? | ? | ? | 43.0 |
[1] As of version 49, Firefox no longer supports the 'push' PermissionDescriptor
dictionary type (referred to in the spec as PushPermissionDescriptor
); this is because Firefox relies on a quota system for controlling the userVisibleOnly
status instead, and was throwing an error when it encountered a PushPermissionDescriptor
instance. With this dictionary removed, Firefox now simply ignores it.