Error Codes Wiki

localStorage Not Available — Browser Storage Blocked in Private Mode or Settings

Warninggeneral

Overview

Fix localStorage access errors when browser privacy settings, private browsing mode, or storage quotas prevent web applications from saving data locally.

Key Details

  • localStorage provides 5-10MB of synchronous key-value storage per origin
  • Private/incognito mode may restrict localStorage or clear it when the session ends
  • Some browsers throw a QuotaExceededError when localStorage is full (5MB typical limit)
  • Safari in private mode used to block localStorage entirely; newer versions allow it but clear on close
  • Enterprise browser policies and privacy extensions can disable localStorage for specific sites

Common Causes

  • Browser in private/incognito mode restricting or disabling localStorage
  • Third-party cookie settings blocking third-party iframe localStorage access
  • localStorage quota (typically 5MB) exceeded from accumulated stored data
  • Browser storage settings or enterprise policy disabling web storage APIs

Steps

  1. 1Wrap localStorage access in try/catch: some modes throw SecurityError when accessing localStorage
  2. 2Feature detect: if (typeof localStorage !== 'undefined') { try { localStorage.setItem('test', 'test'); } catch(e) { /* fallback */ } }
  3. 3Use IndexedDB as a fallback for larger storage needs (better quota and async API)
  4. 4Clear old data: localStorage.removeItem('old-key') or localStorage.clear() to free space
  5. 5For cross-tab synchronization: listen for the 'storage' event to react to changes from other tabs

Tags

localstorageprivate-modestoragequotaweb-storage

Related Items

More in General

Frequently Asked Questions

Modern behavior: Chrome and Firefox allow localStorage in private mode but clear it when the window closes. Safari now does the same (older Safari threw exceptions). Always test and handle both scenarios.