Browser localStorage and sessionStorage Errors — Quota Exceeded and Access Issues
Warningweb development
Overview
Fix browser storage errors including QuotaExceededError, localStorage access denied in incognito, storage eviction, and best practices for web storage.
Key Details
- localStorage persists across sessions; sessionStorage clears when the tab closes
- Storage quota is typically 5-10MB per origin (varies by browser)
- QuotaExceededError thrown when storage is full and you try to add more data
- Safari in Private Browsing sets localStorage quota to 0 bytes (Safari 17+ partially fixed this)
- Storage can be cleared by the browser for storage pressure management
Common Causes
- Storing too much data exceeding the per-origin quota (5-10MB)
- Attempting to store non-string data without JSON.stringify()
- Private/incognito mode restricting storage access
- Browser storage cleanup (especially in Safari) evicting data for inactive origins
- Third-party iframe trying to access storage blocked by tracking prevention
Steps
- 1Check storage usage: in DevTools Application tab > Storage section shows usage per origin
- 2Wrap setItem in try-catch to handle QuotaExceededError gracefully
- 3Clean old data: implement expiration logic to remove stale entries
- 4For large data: use IndexedDB instead of localStorage (much larger quota: 50MB-unlimited)
- 5Handle private browsing: detect QuotaExceededError on first setItem and fall back to in-memory storage
- 6Use navigator.storage.estimate() to check available quota before storing large amounts
Tags
localstoragesessionstoragequotastorageweb-storage
Related Items
More in Web Development
browser-cors-error-explainedBrowser CORS Error Explained — Cross-Origin Request Blocked
Warningbrowser-websocket-errorsBrowser WebSocket Errors — Connection Failed, Closed & Protocol Errors
Warningbrowser-indexeddb-errorsBrowser IndexedDB Errors — Quota Exceeded, Blocked & Corruption
Warningbrowser-localstorage-quota-exceededBrowser localStorage Quota Exceeded — Storage Limit & Alternatives
Warningbrowser-service-worker-errorsBrowser Service Worker Errors — Registration, Cache & Update Failures
Warningbrowser-webgl-context-lostBrowser WebGL Context Lost — GPU Rendering Failure in Browser
WarningFrequently Asked Questions
Typically 5-10MB per origin. Chrome allows ~5MB, Firefox ~10MB, Safari ~5MB. This limit includes all data for the origin across all keys. Use IndexedDB for larger storage needs.