| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor | [Back] [Original] |
Get to know MDN better
This feature is pending removal from browsers. Using it now may lead to broken functionality in future updates. Following the announcement that Chrome will maintain its current approach to third-party cookies, Chrome decided to withdraw certain Privacy Sandbox features including the related website sets.
Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
The requestStorageAccessFor() method of the Document interface allows top-level sites to request third-party cookie access on behalf of embedded content originating from another site in the same related website set. It returns a Promise that resolves if the access was granted, and rejects if access was denied.
requestStorageAccessFor(requestedOrigin)
requestedOriginA string representing the URL of the origin you are requesting third-party cookie access for.
A Promise that fulfills with undefined if the access to third-party cookies was granted and rejects if access was denied.
requestStorageAccessFor() requests are automatically denied unless the top-level content is currently processing a user gesture such as a tap or click (transient activation), or unless permission was already granted previously. If permission was not previously granted, they must run inside a user gesture-based event handler. The user gesture behavior depends on the state of the promise:
requestStorageAccessFor() again if permission is denied.InvalidStateError DOMExceptionThrown if the current Document is not yet active.
NotAllowedError DOMExceptionThrown if:
null origin.requestedOrigin is opaque.<iframe> is sandboxed, and the allow-storage-access-by-user-activation token is not set.storage-access Permissions Policy.TypeErrorThrown if requestedOrigin is not a valid URL.
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 is relevant to user agents that by default block access to third-party, unpartitioned cookies to improve privacy (e.g., to prevent tracking), and is a proposed extension of the Storage Access API.
requestStorageAccessFor() can enable third-party cookie access for cross-site resources directly embedded into a top-level site that are unable to request storage access themselves, for example <img> elements. Cross-site content embedded in <iframe>s that has its own logic and resources and needs third-party cookie access should request storage access via Document.requestStorageAccess().
To check whether permission to access third-party cookies has already been granted via requestStorageAccessFor(), you can call Permissions.query(), specifying the feature name "top-level-storage-access". This is different from the feature name used for the regular Document.requestStorageAccess() method, which is "storage-access".
The Permissions.query() call must specify the embedded origin; for example:
navigator.permissions.query({
name: "top-level-storage-access",
requestedOrigin: "https://www.example.com",
});
Note:
Usage of this feature may be blocked by a storage-access Permissions Policy set on your server (the same one that controls the rest of the Storage Access API). In addition, the document must pass additional browser-specific checks such as allowlists, blocklists, on-device classification, user settings, or anti-clickjacking heuristics.
function rSAFor() {
if ("requestStorageAccessFor" in document) {
document.requestStorageAccessFor("https://example.com").then(
(res) => {
// Use storage access
doThingsWithCookies();
},
(err) => {
// Handle errors
},
);
}
}
After a successful requestStorageAccessFor() call, 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:
function checkCookie() {
fetch("https://example.com/getcookies.json", {
method: "GET",
credentials: "include",
})
.then((response) => response.json())
.then((json) => {
// Do something
});
}
Note: See Using the Storage Access API for a more complete example.
Document.hasStorageAccess(), Document.hasUnpartitionedCookieAccess(), Document.requestStorageAccess()This page was last modified on Jun 11, 2026 by MDN contributors.
DocumentactiveElementactiveViewTransitionadoptedStyleSheetsalinkColorallanchorsappletsbgColorbodycharacterSetchildElementCountchildrencompatModecontentTypecookiecurrentScriptcustomElementRegistrydefaultViewdesignModedirdoctypedocumentElementdocumentURIdomainembedsfeaturePolicyfgColorfirstElementChildfontsformsfragmentDirectivefullscreenfullscreenElementfullscreenEnabledheadhiddenimagesimplementationlastElementChildlastModifiedlastStyleSheetSetlinkColorlinkslocationpictureInPictureElementpictureInPictureEnabledpluginspointerLockElementpreferredStyleSheetSetprerenderingreadyStatereferrerrootElementscriptsscrollingElementselectedStyleSheetSetstyleSheetsstyleSheetSetstimelinetitleURLvisibilityStatevlinkColorxmlEncodingxmlVersionadoptNode()append()ariaNotify()browsingTopics()caretPositionFromPoint()caretRangeFromPoint()clear()close()createAttribute()createAttributeNS()createCDATASection()createComment()createDocumentFragment()createElement()createElementNS()createEvent()createExpression()createNodeIterator()createNSResolver()createProcessingInstruction()createRange()createTextNode()createTouch()createTouchList()createTreeWalker()elementFromPoint()elementsFromPoint()enableStyleSheetsForSet()evaluate()execCommand()exitFullscreen()exitPictureInPicture()exitPointerLock()getAnimations()getElementById()getElementsByClassName()getElementsByName()getElementsByTagName()getElementsByTagNameNS()getSelection()hasFocus()hasPrivateToken()hasRedemptionRecord()hasStorageAccess()hasUnpartitionedCookieAccess()importNode()moveBefore()mozSetImageElement()open()prepend()queryCommandEnabled()queryCommandState()queryCommandSupported()querySelector()querySelectorAll()releaseCapture()replaceChildren()requestStorageAccess()requestStorageAccessFor()startViewTransition()write()writeln()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |