Skip to content

API in Capabilities

Permissions API (navigator.permissions.query)

Published Updated

The navigator.permissions.query() method reads the permission state for a named feature. Its promise fulfills with a PermissionStatus. The status is "granted" or "denied"; otherwise, it is "prompt".

BCD records Permissions.query() from Chrome 43 and Firefox 46. Its Safari entry begins at version 16. The permission names accepted by the method differ by browser, so support for the interface does not establish support for a particular name.

const status = await navigator.permissions.query({ name: 'geolocation' });

The method accepts one PermissionDescriptor and returns a Promise<PermissionStatus>.

Member Type Meaning
name string The permission name to query. Each implementation registers the names it supports.

Some registered permissions use descriptor types with more members. The Permissions specification defines name as a DOMString, not an enum, because implementations support different powerful features.

The query algorithm rejects the promise with InvalidStateError when the associated document is not fully active. It rejects with TypeError when the permission name is unsupported. Conversion of the supplied descriptor can also reject the promise with the conversion’s exception.

These examples distinguish an unavailable query from a permission state returned by the API.

This function checks for the API, handles an unsupported name, and returns a fallback value without treating it as a user denial.

async function readGeolocationPermission() {
if (!('permissions' in navigator)) {
return 'unknown';
}
try {
const status = await navigator.permissions.query({ name: 'geolocation' });
return status.state;
} catch (error) {
return error instanceof TypeError ? 'unsupported-name' : 'unknown';
}
}
console.log(await readGeolocationPermission());

The fallback preserves the distinction between a missing query surface and the specified "denied" state.

PermissionStatus is an EventTarget. Its change event lets the page read the new state after it changes.

if ('permissions' in navigator) {
navigator.permissions.query({ name: 'notifications' }).then((status) => {
console.log(status.state);
status.addEventListener('change', () => console.log(status.state));
}).catch(() => console.log('notifications permission query unavailable'));
} else {
console.log('Permissions API unavailable');
}

The rejection branch also covers a browser that exposes Permissions without registering notifications.

Specifications

SpecificationStatus
Permissions: query() methodW3C