Document: hasStorageAccess() method

The hasStorageAccess() method of the Document interface returns a Promise that resolves with a boolean value indicating whether the document has access to its first-party storage.

This method is part of the Storage Access API.

Syntax

hasStorageAccess()

Parameters

None.

Return value

A Promise that resolves with a boolean value indicating whether the document has access to its first-party storage.

If the promise gets resolved and a user gesture event was being processed when the function was originally called, the resolve handler will run as if a user gesture was being processed, so it will be able to call APIs that require user activation.

Examples

document.hasStorageAccess().then((hasAccess) => {
  if (hasAccess) {
    // storage access has been granted already.
  } else {
    // storage access hasn't been granted already;
    // you may want to call requestStorageAccess().
  }
});

Specifications

Specification
The Storage Access API
# dom-document-hasstorageaccess

Browser compatibility

BCD tables only load in the browser

See also