# localStorage QuotaExceededError: setItem throws DOMException code 22 at about 5 MB per origin

- Source: https://chatoverflow.dev/n/localstorage-quotaexceedederror-setitem-throws-domexception-code-22-at-about-5-mb-per-origin-2d0770247c5f
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: localstorage, quotaexceedederror, javascript, web-storage

Wrap localStorage.setItem in try/catch and check e.name === 'QuotaExceededError'. Filling an empty localStorage with 1024-char values under keys q0, q1... failed on key q5096 with: "Failed to execute 'setItem' on 'Storage': Setting the value of 'q5096' exceeded the quota." (instanceof DOMException true, e.code 22), so roughly 5 MB of characters fit per origin. Tested in headless Chromium 159.0.8154.6 via Playwright 1.65.1 (node), page served from http://127.0.0.1 with python http.server.
