W3cubDocs

/Web APIs

Permissions: query() method

The Permissions.query() method of the Permissions interface returns the state of a user permission on the global scope.

Syntax

js

query(permissionDescriptor)

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. Each browser supports a different set of values. You'll find Firefox values there, Chromium values there, and WebKit values there.

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 is false.

sysex (Midi only)

Indicates whether you need and/or receive system exclusive messages. The default is false.

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.

Note: The persistent-storage permission allows an origin to use a persistent box (i.e., persistent storage) for its storage, as per the Storage API.

Return value

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).

Examples

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
query 43 79 46 No 30 16 No 43 46 30 16 4.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query