JavaScript Document requestStorageAccessFor() Method

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated
Non-standard
Instance method

What You’ll Learn

document.requestStorageAccessFor() is a Deprecated & Non-standard instance method that lets a top-level page request third-party cookie access on behalf of another origin in the same related website set (see MDN Document: requestStorageAccessFor()). Learn how it differs from requestStorageAccess(), the top-level-storage-access permission name, gesture rules, and five try-it labs.

01

Kind

Instance method

02

Caller

Top-level page

03

Arg

requestedOrigin

04

Returns

Promise

05

Status

Deprecated

06

Also

Non-standard

Introduction

Some top-level sites embed cross-site images or scripts that need cookies, but those resources cannot run requestStorageAccess() themselves. MDN describes requestStorageAccessFor() as a proposed extension so the top-level site can request access for another origin in the same related website set.

Cross-site content inside an <iframe> that has its own logic should still use Document.requestStorageAccess() (MDN).

💡
Think: “I am the top page; please unlock cookies for this related origin”

1) Confirm you are the top-level document
2) Optionally query top-level-storage-access (MDN)
3) On a click, call requestStorageAccessFor("https://partner.example")
4) On grant, fetch with credentials: "include" (MDN)

⚠️
Learning only — not for new products

Because MDN marks this API Deprecated and Non-standard, treat labs as literacy. Outside Chromium + a valid related-site setup, the Promise usually rejects.

Related tutorials: requestStorageAccess(), hasStorageAccess(), hasUnpartitionedCookieAccess().

Understanding document.requestStorageAccessFor()

An instance method on Document (proposed Storage Access extension).

  • Caller — top-level site (not a nested iframe) (MDN).
  • ArgumentrequestedOrigin string URL (MDN).
  • ReturnsPromise that fulfills with undefined on grant, rejects on deny (MDN).
  • Related sites — top-level and embedded sites must be in the same related website set (MDN).
  • Permission name"top-level-storage-access" (different from "storage-access") (MDN).
  • Secure context — required (MDN).
  • Status — Deprecated & Non-standard; not defined in a specification (MDN).

📝 Syntax

General form of Document.requestStorageAccessFor (MDN):

JavaScript
requestStorageAccessFor(requestedOrigin)

Parameters

  • requestedOrigin — a string representing the URL of the origin you are requesting third-party cookie access for (MDN).

Return value

A Promise that fulfills with undefined if access to third-party cookies was granted, and rejects if access was denied (MDN).

Exceptions

  • InvalidStateError DOMException — Document not yet active (MDN).
  • NotAllowedError DOMException — not a secure context; not the top-level document; null / opaque origin; sites not in the same related website set; sandbox missing allow-storage-access-by-user-activation; blocked by Permissions Policy; or the user agent denies permission (MDN).
  • TypeErrorrequestedOrigin is not a valid URL (MDN).

MDN sample

JavaScript
function rSAFor() {
  if ("requestStorageAccessFor" in document) {
    document.requestStorageAccessFor("https://example.com").then(
      (res) => {
        // Use storage access
        doThingsWithCookies();
      },
      (err) => {
        // Handle errors
      },
    );
  }
}

⚡ Quick Reference

GoalCode / note
Feature-detect"requestStorageAccessFor" in document
Request for origindocument.requestStorageAccessFor("https://example.com")
Permission querynavigator.permissions.query({ name: "top-level-storage-access", requestedOrigin: "https://www.example.com" }) (MDN)
After grant (fetch)fetch(url, { credentials: "include" }) (MDN)
After grant (img)crossorigin="use-credentials" (MDN)
Embed alternativedocument.requestStorageAccess() inside the iframe
MDN statusDeprecated & Non-standard

🔍 At a Glance

Four facts about document.requestStorageAccessFor().

Returns
Promise

undefined

Arg
origin URL

string

Caller
top-level

MDN

Status
Dep+NStd

MDN

📋 When grants succeed or fail

SituationLikely resultTip
Top-level + related website set + gestureMay grant (supporting engines)Still handle reject
Called from an iframeNotAllowedError (must be top-level) (MDN)Use requestStorageAccess() instead
Origins not in the same setDenied (MDN)API is not a general cross-site cookie unlock
Invalid URL stringTypeError (MDN)Pass a full origin URL
Promise rejectsGesture consumed (MDN)Do not loop the request

Examples Gallery

Examples follow MDN Document: requestStorageAccessFor(). Labs teach API shape; real grants need Chromium support plus a related website set.

📚 Getting Started

Detect support and call the MDN request pattern safely.

Example 1 — Feature-detect first

MDN examples check "requestStorageAccessFor" in document.

JavaScript
const supported = "requestStorageAccessFor" in document;
console.log("requestStorageAccessFor:", supported);
console.log("secure context:", window.isSecureContext);
console.log("is top-level:", window.top === window.self);

if (!supported) {
  console.log("Prefer requestStorageAccess() inside embeds when needed");
}
Try It Yourself

How It Works

Firefox and Safari do not implement this method. Chromium may expose it while still denying grants without a related website set.

Example 2 — MDN: request for an origin

Promise fulfills on grant, rejects on deny.

JavaScript
function rSAFor() {
  if (!("requestStorageAccessFor" in document)) {
    console.log("unsupported");
    return;
  }
  document.requestStorageAccessFor("https://example.com").then(
    () => {
      console.log("access granted");
    },
    (err) => {
      console.log("access denied", err && err.name);
    },
  );
}

rSAFor();
Try It Yourself

How It Works

Without a related website set and often without a gesture, supporting browsers reject. That is expected in a simple try-it page.

📈 Practical Patterns

User gestures, permission queries, and credentialed requests after a grant.

Example 3 — Request from a user gesture

MDN: first grants usually need a tap or click on the top-level page.

JavaScript
const btn = document.getElementById("ask");
const log = document.getElementById("log");

btn.addEventListener("click", async () => {
  if (!("requestStorageAccessFor" in document)) {
    log.textContent = "unsupported";
    return;
  }
  try {
    await document.requestStorageAccessFor("https://example.com");
    log.textContent = "granted";
  } catch (err) {
    log.textContent = "denied: " + (err && err.name ? err.name : err);
  }
});
Try It Yourself

How It Works

If the Promise rejects, MDN notes the gesture is consumed so scripts cannot spam the API in a loop.

Example 4 — Permissions.query with top-level-storage-access

MDN: this permission name is different from storage-access.

JavaScript
async function checkTopLevelAccess() {
  if (!navigator.permissions || !navigator.permissions.query) {
    return "Permissions API unavailable";
  }
  try {
    const permission = await navigator.permissions.query({
      name: "top-level-storage-access",
      requestedOrigin: "https://www.example.com",
    });
    return "state: " + permission.state;
  } catch (err) {
    return "query failed: " + (err && err.name ? err.name : err);
  }
}

checkTopLevelAccess().then(console.log);
Try It Yourself

How It Works

Use the query to decide whether to call requestStorageAccessFor() from a button when the state is prompt (MDN Using guide pattern).

Example 5 — After grant: credentialed fetch

MDN: include credentials so cookies can ride along on cross-site requests.

JavaScript
function checkCookie() {
  return fetch("https://example.com/getcookies.json", {
    method: "GET",
    credentials: "include",
  })
    .then((response) => response.json())
    .then((json) => {
      console.log("got json", json);
    })
    .catch((err) => {
      console.log("fetch failed", err && err.message);
    });
}

// After a successful requestStorageAccessFor():
// checkCookie();
Try It Yourself

How It Works

MDN: resources may also need crossorigin="use-credentials". Wait until after a successful grant before triggering cookie-dependent requests.

🚀 Common Use Cases

  • Legacy literacy — recognize Deprecated / Non-standard top-level Storage Access extensions (MDN).
  • Related Website Sets demos — top-level request on behalf of a partner origin (MDN).
  • Cookie-dependent <img> / script tags — resources that cannot call requestStorageAccess() themselves (MDN).
  • Permission UX — query top-level-storage-access before prompting (MDN).
  • Not for new products — prefer Baseline requestStorageAccess() in embeds where possible.
  • Credentialed follow-up requestscredentials: "include" after grant (MDN).

🧠 How requestStorageAccessFor() Works

1

Top-level page needs a partner origin

Cross-site image/script cannot request storage access itself (MDN).

Need
2

Optional permission query

top-level-storage-access + requestedOrigin (MDN).

Query
3

User gesture + requestStorageAccessFor

Must be top-level, secure, and usually related-site eligible (MDN).

Request
4

Grant → credentialed requests; deny → fallback

Use credentials: "include" / crossorigin="use-credentials" (MDN).

📝 Notes

  • MDN: marked Deprecated and Non-standard.
  • MDN: does not appear to be defined in any specification.
  • Must run in a secure top-level document (MDN).
  • Top-level and embedded sites must be in the same related website set (MDN).
  • Permission feature name is top-level-storage-access, not storage-access (MDN).
  • Related: requestStorageAccess(), hasStorageAccess(), hasUnpartitionedCookieAccess().

Deprecated / Non-standard Browser Support

Document.requestStorageAccessFor() is Deprecated and Non-standard on MDN and is not defined in a specification. Historical support is Chromium-oriented (Chrome / Edge / Opera). Firefox and Safari do not implement it. Logos use the shared browser-image-sprite.png sprite from this project.

Deprecated · Non-standard

Document.requestStorageAccessFor()

Top-level request for third-party cookie access on behalf of a related origin. Feature-detect; prefer Baseline requestStorageAccess() for embeds.

Narrow Deprecated
Google Chrome 119+
Yes*
Microsoft Edge 119+
Yes*
Opera 105+
Yes*
Mozilla Firefox Not supported
No
Apple Safari Not supported
No
Internet Explorer Not supported
No
requestStorageAccessFor() Chromium-leaning

Bottom line: Use only for legacy literacy. New embed flows should prefer Document.requestStorageAccess(). Expect denials without Related Website Sets.

Conclusion

document.requestStorageAccessFor() is a Deprecated, Non-standard way for a top-level page to request cookie access on behalf of a related origin. Learn the MDN shape for literacy, then build new embed experiences with Baseline requestStorageAccess() when that fits.

Continue with startViewTransition(), requestStorageAccess(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before calling
  • Prefer requestStorageAccess() inside embeds for new work
  • Call from a user gesture when permission is prompt (MDN)
  • Use credentials: "include" after a grant (MDN)
  • Plan a non-cookie fallback UX

❌ Don’t

  • Build new products on this Deprecated API (MDN)
  • Call it from nested iframes (must be top-level) (MDN)
  • Assume Firefox / Safari support
  • Loop requests after a reject (gesture consumed) (MDN)
  • Confuse top-level-storage-access with storage-access

Key Takeaways

Knowledge Unlocked

Five things to remember about requestStorageAccessFor()

Deprecated top-level Storage Access request for a related origin.

5
Core concepts
🏠02

Caller

top-level

MDN
🔗03

Arg

origin URL

MDN
⚠️04

Status

Deprecated

MDN
🛡05

Also

Non-std

MDN

❓ Frequently Asked Questions

MDN: Document.requestStorageAccessFor() 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 access was granted and rejects if denied.
MDN marks Document.requestStorageAccessFor() as Deprecated and Non-standard. It does not appear to be defined in any specification. Prefer Document.requestStorageAccess() inside embeds when that fits your use case, and avoid building new products on this API.
requestStorageAccess() is called by third-party embedded content to request access for itself. requestStorageAccessFor() is called by the top-level page to request access on behalf of another origin (for resources that cannot call the API themselves, such as cross-site images or scripts) (MDN).
A string requestedOrigin — the URL of the origin you are requesting third-party cookie access for (MDN). Invalid URLs throw TypeError.
MDN: call Permissions.query() with name "top-level-storage-access" and a requestedOrigin. That feature name is different from "storage-access" used with requestStorageAccess().
Yes in the common case. MDN: requests are automatically denied unless the top-level content is processing a user gesture (transient activation), or permission was already granted previously.
Did you know?

MDN uses a different Permissions API feature name for this method: "top-level-storage-access". The embed-facing requestStorageAccess() method uses "storage-access" instead — mixing them up is a common beginner mistake.

Next: startViewTransition()

Learn how Document.startViewTransition() animates same-document SPA updates with the View Transition API.

startViewTransition() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful