Error handling "Out of Memory Exception" in browser? Error handling "Out of Memory Exception" in browser? google-chrome google-chrome

Error handling "Out of Memory Exception" in browser?


You should calclulate size of your localStorage,window.localStorage is full

as a solution is to try to add something

var localStorageSpace = function(){    var allStrings = '';    for(var key in window.localStorage){        if(window.localStorage.hasOwnProperty(key)){            allStrings += window.localStorage[key];        }    }    return allStrings ? 3 + ((allStrings.length*16)/(8*1024)) + ' KB' : 'Empty (0 KB)';};var storageIsFull = function () {    var size = localStorageSpace(); // old size    // try to add data    var er;    try {         window.localStorage.setItem("test-size", "1");    } catch(er) {}    // check if data added    var isFull = (size === localStorageSpace());    window.localStorage.removeItem("test-size");    return isFull;}


I also got the same error message recently when working on a project having lots of JS and sending Json, but the solution which I found was to update input type="submit" attribute to input type="button". I know there are limitations of using input type="button"..> and the solution looks weird, but if your application has ajax with JS,Json data, you can give it a try. Thanks.


Faced the same problem in Firefox then later I came to know I was trying to reload a HTML page even before setting up some data into local-storage inside if loop. So you need to take care of that one and also check somewhere ID is repeating or not.

But same thing was working great in Chrome. Maybe Chrome is more Intelligent.