QuotaExceededError (DOM Exception 22): The quota has been exceeded on Safari in incognito
Asked Answered
F

2

27

I'm getting QuotaExceededError (DOM Exception 22): The quota has been exceeded. on Safari when I'm in incognito mode.

I went through similar questions like this: QuotaExceededError: Dom exception 22: An attempt was made to add something to storage that exceeded the quota

But they talk about setItem, I get this error somewhere else.

I get this error on this line: localStorage['gallery.extensions'] = JSON.stringify({}); or localStorage['asdf'] = 'asdfg';

I tried combining this answer and replacing every line like localStorage['asdf'] = 'asdfg'; to be localStorage.setItem('asdf', 'asdfg') and every access like localStorage['asdf'] to be localStorage.getItem('asdf') but that didn't help either.

Furred answered 26/2, 2017 at 11:30 Comment(4)
I get this error on this line - that's just like using setItem - so same constraintsRia
the accepted answer in the question you linked to #21159801 applies to your situationRia
I added the code from here: https://mcmap.net/q/117693/-quotaexceedederror-dom-exception-22-an-attempt-was-made-to-add-something-to-storage-that-exceeded-the-quota but it still threw this error on that line.Furred
But I need to test my app in incognito because I don't want to go and clean my data every time I change something. @JaromandaXFurred
W
33

You can't use local storage in incognito mode. By wrapping your setItem or getItem calls in a try/catch just helps your code handle the failed usage of local storage, and then alert the user that they need to use your application in a non-private mode.

The error you're getting is by design.

EDIT 2021: You can now use localStorage in Incognito mode. This error can also occur when you run out of the allowed storage space limit per app/domain. At the time of writing most browsers limit to 10mb.

Warila answered 26/2, 2017 at 11:35 Comment(6)
So how do developers on OSX test their app if they need to clean the cache and data each time?Furred
@kuhaku This link may help. Personally when developing in Chrome by having the developer tools window open, the cache is cleared automatically on every page refresh. You could also add code to your web page to forcibly delete items from localstorage every time your page loads, just to ensure it's clean before your page loads.Warila
With remote debugging of Mobile Safari you can clear the cache also with Command-Option-e: #19250461 (developer.apple.com/library/content/documentation/…)Huang
Just tested now and I can totally use Local Storage in incognito. Come to think of it I always could (anyway this comment is 3.5 years after the last ones). I don't know where the QuotaExceededError is coming from - it happened to me on a colleague's machine, doesn't happen on mine. Go figure. Anyway my lesson was to wrap the localStorage.setItem and localStorage.getItem methods in try and catch. Always good practice (if the local storage isn't critical to the application). Note to self: apply also with other non-critical code that can unnecessarily crash the app.Falkirk
localStorage can be use in incognito modeMd
this means the localStrorage.setItem cannot save any thing. because of run out of cache storageSheeb
L
27

The accepted answer is incorrect. This happens when localStorage.setItem runs out of memory and throws an error. As another commenter wrote, always wrap setItem in try {} catch() {}

Lidstone answered 12/1, 2021 at 0:8 Comment(3)
when it exceeds allowed memory limit (10 MB on chrome / firefox).Bantu
To confirm that you can indeed use web storage on incognito is by using this: dev-test.nemikor.com/web-storage/support-testCorymb
related question about localStorage limits: #2989784Spry

© 2022 - 2024 — McMap. All rights reserved.