W3cubDocs

/DOM

document.requestStorageAccess

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The requestStorageAccess() method of the Document interface returns a Promise that resolves if the access to first-party storage was granted, and rejects if access was denied.

Storage access is granted based on a series of checks described here:

  1. If the document already has been granted access, resolve.
  2. If the document has a null origin, reject.
  3. If the document's frame is the main frame, resolve.
  4. If the sub frame's origin is equal to the main frame's, resolve.
  5. If the sub frame is not sandboxed, skip to step 7.
  6. If the sub frame doesn't have the token allow-storage-access-by-user-activation, reject.
  7. If the sub frame's parent frame is not the top frame, reject.
  8. If the browser is not processing a user gesture, reject.
  9. Check any additional rules that the browser has. Examples: Whitelists, blacklists, on-device classification, user settings, anti-clickjacking heuristics, or prompting the user for explicit permission. Reject if some rule is not fulfilled.
  10. Grant the document access to cookies and other site storage and store that fact for the purposes of future calls to Document.hasStorageAccess() and requestStorageAccess().

See Storage Access API for more information.

Syntax

Promise<boolean> requestStorageAccess()

Parameters

None.

Return value

a Promise that resolves if the access to first-party storage was granted, and rejects if access was denied.

If the promise gets resolved, 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.requestStorageAccess().then(
  () => { console.log('access granted') },
  () => { console.log('access denied') }
);

Specifications

The API is currently only at the proposal stage — the standardization process has yet to begin. You can currently find specification details of the API at Apple's Introducing Storage Access API blog post, and WHATWG HTML issue 338 — Proposal: Storage Access API.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support No No 65
Disabled
65
Disabled
Disabled From version 65: this feature is behind the dom.storage_access.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No No 11.1
11.1
Currently only available on macOS High Sierra 10.13.4 beta, and in Safari Technology Preview 47+.
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support No No No 65
Disabled
65
Disabled
Disabled From version 65: this feature is behind the dom.storage_access.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No 11.1
11.1
Currently only available on iOS 11.3 beta.
?

See also

Storage Access API

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/document/requestStorageAccess