Permissions

Baseline 2022

Newly available

Since September 2022, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Note: This feature is available in Web Workers.

The Permissions interface of the Permissions API provides the core Permission API functionality, such as methods for querying and revoking permissions

Instance methods

Permissions.query()

Returns the user permission status for a given API.

Permissions.revoke() Deprecated

Revokes the permission currently set on a given API.

Example

js
navigator.permissions.query({ name: "geolocation" }).then((result) => {
  if (result.state === "granted") {
    showLocalNewsWithGeolocation();
  } else if (result.state === "prompt") {
    showButtonToEnableLocalNews();
  }
  // Don't do anything if the permission was denied.
});

Specifications

Specification
Permissions
# permissions-interface

Browser compatibility

BCD tables only load in the browser