You can calculate these numbers if you want. Basically, the default limit for localStorage and webStorage is 5 MB, where the name and values are stored as UTF16, so it really is half what is 2.5 MB in terms of stored characters. In webStorage, you can increase this by adding "unlimited_storage" to the manifest.
The same applies to WebStorage, but you need to go through all the tables and find out how many characters in each row.
In localStorage, you can verify this by running the population script:
var row = 0; localStorage.clear(); var populator = function () { localStorage[row] = ''; var x = ''; for (var i = 0; i < (1024 * 100); i++) { x += 'A'; } localStorage[row] = x; row++; console.log('Populating row: ' + row); populator(); } populator();
The above should crash on line 25 if there is not enough space, which is about 2.5 MB. You can invert and count the number of characters in a string and determine how much space you have.
Another way to do this is to always add a “payload” and check for an exception, if it exists, if so, then you know that you are out of space.
try { localStorage['foo'] = 'SOME_DATA'; } catch (e) { console.log('LIMIT REACHED! Do something else'); }
Internet Explorer did something called "remaining space", but it doesn’t work in Chrome / Safari: http://msdn.microsoft.com/en-us/library/cc197016(v=VS.85).aspx
source share