Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 326
shinzou Avatar asked Feb 26 '17 11:02

shinzou


2 Answers

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.

like image 157
David Thomas Avatar answered Nov 18 '22 02:11

David Thomas


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() {}

like image 23
hedgehogrider Avatar answered Nov 18 '22 03:11

hedgehogrider