Error Codes Wiki

Browser localStorage and sessionStorage Errors — Quota Exceeded and Access Issues

Warningweb development

About Browser localStorage and sessionStorage Errors

Fix browser storage errors including QuotaExceededError, localStorage access denied in incognito, storage eviction, and best practices for web storage. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Check storage usage: in DevTools Application tab > Storage section shows usage per origin. Wrap setItem in try-catch to handle QuotaExceededError gracefully. Clean old data: implement expiration logic to remove stale entries. For large data: use IndexedDB instead of localStorage (much larger quota: 50MB-unlimited). Handle private browsing: detect QuotaExceededError on first setItem and fall back to in-memory storage. Use navigator.storage.estimate() to check available quota before storing large amounts. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our Browser Errors collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

How much data can localStorage hold?

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.

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

  1. 1Check storage usage: in DevTools Application tab > Storage section shows usage per origin
  2. 2Wrap setItem in try-catch to handle QuotaExceededError gracefully
  3. 3Clean old data: implement expiration logic to remove stale entries
  4. 4For large data: use IndexedDB instead of localStorage (much larger quota: 50MB-unlimited)
  5. 5Handle private browsing: detect QuotaExceededError on first setItem and fall back to in-memory storage
  6. 6Use navigator.storage.estimate() to check available quota before storing large amounts

Tags

localstoragesessionstoragequotastorageweb-storage

Related Items

More in Web Development

Frequently 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.