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.
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.
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() {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With