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
Fundamentals
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.
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).
Foundation
📝 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");
}
});
already granted
(or request flow result in embeds)
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.
Example 5 — Probe cookies when unsure
MDN: the boolean can be inaccurate; verify with real cookie reads.
JavaScript
async function diagnose() {
const apiSays = typeof document.hasStorageAccess === "function"
? await document.hasStorageAccess()
: null;
let cookieReadable = false;
try {
// Write+read a short-lived test cookie when allowed by your app policy
document.cookie = "sa_probe=1; path=/; SameSite=None; Secure";
cookieReadable = document.cookie.includes("sa_probe=");
} catch (err) {
cookieReadable = false;
}
return { apiSays, cookieReadable };
}
diagnose().then(console.log);
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.
BaselineWidely available
Google Chrome119+
Yes
Mozilla Firefox65+
Yes
Apple Safari11.1+
Yes
Microsoft Edge85+
Yes
Opera105+
Yes
Internet ExplorerNot supported
No
hasStorageAccess()Wide
Bottom line: Use hasStorageAccess to decide whether to call requestStorageAccess. Always handle cookie read/write failures gracefully.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about hasStorageAccess()
Check third-party unpartitioned cookie access.
5
Core concepts
📝01
Returns
Promise<bool>
MDN
🔄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.