Nos bénévoles n'ont pas encore traduit cet article en Français. Inscrivez-vous et aidez-nous à réaliser cette tâche !
Vous pouvez également lire cet article en English (US).

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.

Conditions for granting storage access

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

Assuming all of the requirements above are satisfied, Firefox will automatically grant storage access to the requesting origin on up to a threshold number of first-party origins in the current session for the duration of user’s session, up to a maximum of 24 hours. After the requesting origin has exceeded the maximum allowable number of storage access grants, any future call to requestStorageAccess() during the same browsing session will prompt the user.

The maximum number of concurrent storage access grants an origin can obtain is a positive integer currently defined as one percent of the number of top-level origins visited in the current session or 5, whichever is higher. The threshold is enforced on the level of eTLD+1, so for example two storage access grants for foo.example.com and bar.example.com will only count as a single exception against the limit.

At the time of a requestStorageAccess() call, if the requesting origin has storage access to...

...fewer origins than the maximum:

  • The user is not prompted.
  • The origin is given an ephemeral storage access grant for the current top-level origin.
  • The number of origins the requesting origin has storage access to is incremented by one.
  • The ephemeral storage access grant is:
    • Invalidated at the end of the browser session.
    • Not persisted to disk (e.g. will not persist if the browser crashes).
    • Reset after 24 hours in the case of a long-running browser session.

...equal or more origins than the maximum:

  • The user is prompted
  • If the user clicks “Allow” or “Allow on any site” the request is resolved.
  • If the user clicks “Don’t Allow”, the storage access request is rejected and the requesting origin can re-request once it receives another user interaction.
  • If the user allows storage the requesting origin is given a persistent storage access grant on the current top-level origin.
  • The number of origins the requesting origin has storage access to is incremented by one.
  • The persistent storage access permission is:
    • Persisted to disk and will remain valid in future browser sessions.
    • Reset after 30 days.

When an ephemeral or persistent storage access grant expires, the number of origins the requesting origin has storage access to is decremented by one.

Note: If the requesting origin is not classified as a tracking origin, the access request is automatically given an ephemeral storage access grant, which will go away when the page is reloaded. The user is never shown a prompt in this case, and calling requestStorageAccess() won’t have any side effects besides changing the value returned by Document.hasStorageAccess().

Debugging

The storage access grant threshold may make it more difficult to test your website under the condition where Firefox prompts the user for access. To make testing easier, we have added two preferences in about:config that control prompting upon requestStorageAccess() calls:

  • dom.storage_access.auto_grants can be set to false to disable the automatic granting of ephemeral storage access grants. All calls to requestStorageAccess() by origins classified as trackers will trigger a prompt.
  • dom.storage_access.max_concurrent_auto_grants controls the threshold number of storage access grants at which users will begin to receive prompts. For example, if you want to configure Firefox to automatically grant access on the first site where requestStorageAccess() is called and then prompt afterwards, you should adjust the value of the dom.storage_access.max_concurrent_auto_grants preference to 1.

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 compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
requestStorageAccess
ExperimentalNon-standard
Chrome No support NoEdge No support NoFirefox Full support 65IE No support NoOpera No support NoSafari Full support 11.1
Notes
Full support 11.1
Notes
Notes Currently only available on macOS High Sierra 10.13.4 beta, and in Safari Technology Preview 47+.
WebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 65
Disabled
Full support 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.
Opera Android No support NoSafari iOS Full support 11.1
Notes
Full support 11.1
Notes
Notes Currently only available on iOS 11.3 beta.
Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also

Storage Access API

Étiquettes et contributeurs liés au document

Contributeurs à cette page : mfuji09, mdnwebdocs-bot, chrisdavidmills, Ehsan
Dernière mise à jour par : mfuji09,