gblazex/smoothscroll-for-websites

QuotaExceededError with SmoothScroll

Enalmada opened this issue · 1 comments

I am getting client errors about "QuotaExceededError" after putting smoothscroll on my site.

QuotaExceededError: QuotaExceededError: DOM Exception 22
  at None (/ajax/libs/smoothscroll/1.4.4/SmoothScroll.min.js:1:8002)

From what I can tell, safari private browsing mode throws this error if you try to use localStorage.
http://stackoverflow.com/questions/21159301/quotaexceedederror-dom-exception-22-an-attempt-was-made-to-add-something-to-st

It is extremely frustrating that safari private browsing works this way. It appears as if the only way to actually know for sure that localStorage wont throw error is to try to use it and catch the exception before you really use it:

// https://stackoverflow.com/questions/11214404/how-to-detect-if-browser-supports-html5-local-storage
function supportLocalStorage() {
    var mod = 'test';
    try {
        if (typeof(Storage) !== "undefined") {
            localStorage.setItem(mod, mod);
            localStorage.removeItem(mod);
            return true;
        } else
            return false;
    } catch (e) {
        return false;
    }
}

For others using smoothscroll and getting errors, I have not tried it but there seems to be a way to fake the function calls:

// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
// throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem
// to avoid the entire page breaking, without having to do a check at each usage of Storage.
if (typeof localStorage === 'object') {
    try {
        localStorage.setItem('localStorage', 1);
        localStorage.removeItem('localStorage');
    } catch (e) {
        Storage.prototype._setItem = Storage.prototype.setItem;
        Storage.prototype.setItem = function() {};
         // if your app actually relies on localStorage, let users know 
        // alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.');

    }
}

It would be nice if something like this could be added so that smoothscroll js wouldn't throw errors for people using private mode.

will be fixed in the next version. thanks