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

shinzou picture shinzou · Feb 26, 2017 · Viewed 29.5k times · Source

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.

Answer

David Thomas picture David Thomas · Feb 26, 2017

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.