Console: SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document
The page cannot use localStorage because cookies/site data are blocked, it runs in a sandboxed iframe, or the browser is in a restricted mode.
Failed to read the 'localStorage' property from 'Window'Access is denied for this documentSecurityError: The operation is insecureFailed to read the 'sessionStorage' propertyDOMException: Failed to execute 'getItem' on 'Storage' Meaning
Browsers deny web storage when "Block all cookies" is set, for third-party iframes with blocked storage, for sandboxed iframes without allow-same-origin, in some private modes, and for file:// or opaque origins (data: URLs). Wrap storage access in try/catch and fall back to memory.
Common causes
- "Block third-party cookies" or all site data enabled
- Embedded in a cross-site iframe (storage partitioned/blocked)
- Sandboxed iframe lacking
allow-same-origin - Privacy mode/extension blocking storage
- Opaque origin (about:blank in a sandbox, data: URL)
⚡ Quick fix
- Guard storage access with
try/catchand provide a fallback - For iframes add
allow-same-origin(only if safe) or use the Storage Access API - Ask users to allow site data for your domain
Detailed fix by platform
JavaScript
function store() { try { localStorage.setItem('k','v'); return localStorage; } catch (e) { return new Map(); } }document.requestStorageAccess()in third-party iframes after a user gesture
Code examples
Safe storage wrapper
const safeStorage = (() => {
try {
const k = '__t'; localStorage.setItem(k, '1'); localStorage.removeItem(k);
return localStorage;
} catch (e) {
const mem = new Map();
return { getItem: k => mem.get(k) ?? null, setItem: (k, v) => mem.set(k, String(v)), removeItem: k => mem.delete(k) };
}
})();How to diagnose
- Context — Top-level page or iframe?
- Settings — Cookies/site data blocked?
- Sandbox — iframe sandbox attribute?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Browser
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026