JavaScript Document hasStorageAccess() Method

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance method

What You’ll Learn

document.hasStorageAccess() is an instance method that returns a Promise resolving to whether this document can use third-party, unpartitioned cookies (see MDN Document: hasStorageAccess()). Learn the Storage Access API flow, when to call requestStorageAccess(), and important accuracy caveats.

01

Kind

Instance method

02

Args

None

03

Returns

Promise<boolean>

04

API

Storage Access

05

Alias

hasUnpartitionedCookieAccess

06

Status

Baseline

Introduction

Embedded widgets (login buttons, comment tools, payment frames) often need their own cookies while living inside another site. Browsers increasingly partition or block that access. The Storage Access API lets embeds check and request permission.

MDN: hasStorageAccess() returns a Promise that resolves with a boolean indicating whether the document has access to third-party, unpartitioned cookies.

💡
Think: “Do I already have cookie access here?”

1) Feature-detect document.hasStorageAccess
2) await document.hasStorageAccess()
3) true — use cookies / state
4) false — consider requestStorageAccess() (MDN)

⚠️
Result can be imperfect (MDN)

User settings may still block cookies even when the Promise resolves to true. Conversely, some browsers may return false even when cookies are still readable. Handle missing cookie values gracefully, and optionally probe document.cookie.

Related tutorials: hasRedemptionRecord(), hasPrivateToken(), hasUnpartitionedCookieAccess().

Understanding document.hasStorageAccess()

An instance method on the Document interface from the Storage Access API (MDN). It takes no arguments and returns a Promise<boolean>.

  • No parameters — call it with empty parentheses (MDN).
  • Return value — a Promise that resolves to true or false (MDN).
  • Meaning — whether the document has access to third-party, unpartitioned cookies (MDN).
  • Alias — another name for hasUnpartitionedCookieAccess() (MDN).
  • Next step — if false, you may call requestStorageAccess() (MDN).
  • User gesture note — if a user gesture was active when you called it, the resolve handler can still call APIs that need user activation (MDN).

📝 Syntax

General form of Document.hasStorageAccess (MDN):

JavaScript
hasStorageAccess()

Parameters

None (MDN).

Return value

A Promise that resolves with a boolean value indicating whether the document has access to third-party cookies — true if it does, and false if not (MDN).

Exceptions

  • InvalidStateError — thrown if the current Document is not yet active (MDN).

MDN quick sample

JavaScript
document.hasStorageAccess().then((hasAccess) => {
  if (hasAccess) {
    // storage access has been granted already.
    console.log("cookie access granted");
  } else {
    // storage access hasn't been granted already;
    // you may want to call requestStorageAccess().
    console.log("cookie access denied");
  }
});

⚡ Quick Reference

GoalCode
Feature-detecttypeof document.hasStorageAccess === "function"
Check accessawait document.hasStorageAccess()
Promise styledocument.hasStorageAccess().then((ok) => { ... })
If deniedConsider document.requestStorageAccess() (MDN)
Newer aliasdocument.hasUnpartitionedCookieAccess() (MDN)
MDN statusBaseline Widely available (since Dec 2023)

🔍 At a Glance

Four facts about document.hasStorageAccess().

Returns
Promise

boolean

Args
none

MDN

Checks
3P cookies

unpartitioned

Status
Baseline

since 2023

📋 First-party page vs third-party embed

ContextWhat beginners usually seeTip
Top-level site (you own the tab)Often already has cookie accessMethod still works; result is commonly true
Cross-site iframe embedMay be false until grantedMain reason the Storage Access API exists (MDN)
User blocks third-party cookiesMay report true but cookies failHandle cookie errors gracefully (MDN)
Browser does not block by defaultMay report false while cookies workProbe document.cookie if needed (MDN)

Examples Gallery

Examples follow MDN Document: hasStorageAccess() and practical Storage Access patterns.

📚 Getting Started

Read the boolean Promise from the Storage Access API.

Example 1 — MDN: then() branch

Classic MDN sample: granted vs denied messaging.

JavaScript
document.hasStorageAccess().then((hasAccess) => {
  if (hasAccess) {
    console.log("cookie access granted");
  } else {
    console.log("cookie access denied");
  }
});
Try It Yourself

How It Works

On a normal top-level tutorial page you will often see granted. The interesting cases appear inside cross-site iframes.

Example 2 — async/await form

Same check with modern async syntax.

JavaScript
async function checkAccess() {
  const hasAccess = await document.hasStorageAccess();
  return hasAccess ? "granted" : "denied";
}

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

How It Works

Remember it is always asynchronous — even though the result is “just” a boolean.

📈 Practical Patterns

Feature detection, requesting access, and cookie probing.

Example 3 — Feature-detect first

MDN’s Using guide starts with if (document.hasStorageAccess).

JavaScript
async function run() {
  if (typeof document.hasStorageAccess !== "function") {
    console.log("Storage Access API missing — handle cookies defensively");
    return;
  }
  console.log("hasAccess:", await document.hasStorageAccess());
}

run();
Try It Yourself

How It Works

Older browsers may lack the API. Defensive cookie code still matters even when the method exists (MDN accuracy notes).

Example 4 — Request access when denied

MDN: if access is not granted, you may want to call requestStorageAccess().

JavaScript
async function ensureAccess() {
  if (typeof document.hasStorageAccess !== "function") {
    return "unsupported";
  }

  if (await document.hasStorageAccess()) {
    return "already granted";
  }

  if (typeof document.requestStorageAccess !== "function") {
    return "cannot request";
  }

  try {
    await document.requestStorageAccess();
    return "granted after request";
  } catch (err) {
    return "request denied: " + err.name;
  }
}

// Often call this from a button click (user gesture)
Try It Yourself

How It Works

Requests often need a user gesture. MDN also notes that if you called hasStorageAccess() during a gesture, the resolve handler can preserve that activation for follow-up APIs.

🚀 Common Use Cases

  • Embedded login widgets — check cookie access before showing a signed-in state.
  • Comment / chat embeds — decide whether to request storage access.
  • Payment / identity iframes — gate features on unpartitioned cookie access.
  • Defensive UX — invite users to sign in again when cookies fail despite true (MDN).
  • Alias awareness — recognize hasUnpartitionedCookieAccess() as the same idea (MDN).
  • Gesture-aware flows — request access from a button after a false check.

🧠 How hasStorageAccess() Works

1

Call with no arguments

Ask the document whether storage access is already available (MDN).

Call
2

Browser evaluates cookie policy

Considers third-party / unpartitioned cookie access for this document (MDN).

Policy
3

Promise resolves to a boolean

true if access is indicated; false otherwise (MDN).

Result
4

Use cookies or request access

Proceed, or call requestStorageAccess() and still handle cookie errors.

📝 Notes

  • MDN: Baseline Widely available since December 2023.
  • MDN: part of the Storage Access API.
  • MDN: alias of hasUnpartitionedCookieAccess(); no current plan to remove this name.
  • MDN: result can be inaccurate under some browser/user settings — handle cookie failures.
  • MDN: InvalidStateError if the Document is not yet active.
  • Related: hasRedemptionRecord(), hasUnpartitionedCookieAccess(), hasPrivateToken().

Browser Support

Document.hasStorageAccess() is Baseline Widely available on MDN (since December 2023). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Widely available

Document.hasStorageAccess()

Promise-based check for third-party unpartitioned cookie access across modern browsers.

Baseline Widely available
Google Chrome 119+
Yes
Mozilla Firefox 65+
Yes
Apple Safari 11.1+
Yes
Microsoft Edge 85+
Yes
Opera 105+
Yes
Internet Explorer Not supported
No
hasStorageAccess() Wide

Bottom line: Use hasStorageAccess to decide whether to call requestStorageAccess. Always handle cookie read/write failures gracefully.

Conclusion

document.hasStorageAccess() tells embeds whether they already have access to third-party, unpartitioned cookies. Use it as the first step in a Storage Access flow, then request access when needed — and still treat cookie failures as possible.

Continue with hasUnpartitionedCookieAccess(), parseHTML(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before calling
  • Branch on the Promise boolean (MDN)
  • Call requestStorageAccess() from a user gesture when needed
  • Handle cookie errors even after true (MDN)
  • Know the alias hasUnpartitionedCookieAccess() (MDN)

❌ Don’t

  • Treat the boolean as perfect truth in every browser (MDN)
  • Forget that embeds are the main use case
  • Skip defensive UX when personalized state is blocked
  • Assume IE support
  • Confuse this with Private State Token methods

Key Takeaways

Knowledge Unlocked

Five things to remember about hasStorageAccess()

Check third-party unpartitioned cookie access.

5
Core concepts
🔄02

Args

none

MDN
🎯03

API

Storage Access

cookies
04

Caveat

not perfect

MDN
🛡05

Status

Baseline

2023

❓ Frequently Asked Questions

MDN: Document.hasStorageAccess() returns a Promise that resolves with a boolean indicating whether the document has access to third-party, unpartitioned cookies. It is part of the Storage Access API.
No. MDN marks Document.hasStorageAccess() as Baseline Widely available (since December 2023). It is not Deprecated, Experimental, or Non-standard.
No. MDN: hasStorageAccess() takes no parameters.
MDN example: storage access has not been granted already; you may want to call document.requestStorageAccess().
Not always. MDN notes user settings may block third-party cookies even when true is returned, and some browsers may return false even when cookies are still accessible. Handle cookie errors gracefully and optionally probe document.cookie.
MDN: hasStorageAccess() is another name for Document.hasUnpartitionedCookieAccess(). There are no current plans to remove hasStorageAccess() in favor of the newer name.
Did you know?

MDN keeps both names on purpose: hasStorageAccess() and hasUnpartitionedCookieAccess() refer to the same check, and there are currently no plans to remove the original method.

Next: hasUnpartitionedCookieAccess()

Learn the newer Storage Access method name and how it relates to hasStorageAccess().

hasUnpartitionedCookieAccess() →

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