Get to know MDN better
The Storage Access API can be used by embedded cross-site documents to verify whether they have access to third-party cookies and unpartitioned state and, if not, to request access. We'll briefly look at a common storage access scenario.
Note: When we talk about third-party cookies in the content of the Storage Access API, we implicitly mean unpartitioned third-party cookies.
The Storage Access API is designed to allow embedded content to request access to third-party cookies and unpartitioned state — most modern browsers block such access by default to protect user privacy. Since embedded content won't know what a browser's behavior is going to be in this regard, it's best to always check whether the embedded <iframe> has storage access before attempting to read or write a cookie. This is particularly true for Document.cookie access, as browsers will often return an empty cookie jar when third-party cookie access is blocked.
In the example below, we show how an embedded cross-site <iframe> can access third-party cookies and unpartitioned state under a browser storage access policy that would otherwise block access to them.
First of all, if the <iframe> is sandboxed, the embedding website needs to add the allow-storage-access-by-user-activation sandbox token to allow Storage Access API requests to be successful, along with allow-scripts and allow-same-origin to allow it to execute a script to call the API and execute it in an origin that can have cookies and state:
Now on to the code executed inside the embedded document. In this code:
Note: requestStorageAccess() requests are automatically denied unless the embedded content is currently processing a user gesture such as a tap or click (transient activation), or if permission was already granted previously. If permission was not previously granted, requestStorageAccess() requests must be run inside a user gesture-based event handler, as shown above.
The Chrome-only related website sets feature can be considered a progressive enhancement mechanism that works alongside the Storage Access API — supporting browsers grant default third-party cookie and unpartitioned state access between websites in the same set. This means not having to go through the usual user permission prompt workflow described above, meaning a more user-friendly experience for users of sites in the set.
The Storage Access API features above allow an embedded document to request its own third-party cookie access. There is an additional experimental method available, Document.requestStorageAccessFor(), a proposed extension to the Storage Access API that allows top-level sites to request storage access on behalf of specific related origins.
The requestStorageAccessFor() method addresses challenges in adopting the Storage Access API on top-level sites that use cross-site images or scripts requiring cookies. It can enable third-party cookie access for cross-site resources directly embedded into the top-level site that are unable to request their own storage access, for example via <img> or <script> elements.
For requestStorageAccessFor() to work, both the calling top-level page and the embedded resource it is requesting storage access for need to be part of the same related website set.
Typical usage of requestStorageAccessFor() looks like this (this time written in regular promise-style rather than async/await):
Note: Unlike with requestStorageAccess(), Chrome doesn't check for an interaction in a top-level document within the last 30 days when requestStorageAccessFor() is called because the user is already on the page. See Browser-specific variations > Chrome for more details of this behavior.
When querying permission status for storage access requests made on behalf of another origin, the permission name used is different from the rest of the Storage Access API: "top-level-storage-access" rather than "storage-access". In the above code, we use the following call:
to discover if the origin has previously been granted permission or if cookie access still needs to be requested.
After the "top-level-storage-access" permission is granted, cross-site requests will include cookies if they include CORS / crossorigin, so sites may want to wait before triggering a request. Such requests must use the credentials: "include" option and resources must include the crossorigin="use-credentials" attribute.
For example:
This page was last modified on Jun 24, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.