Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuotaExceededError in Safari incognito mode #42

Closed
AndreasHogstrom opened this issue Sep 10, 2015 · 4 comments · Fixed by #75
Closed

QuotaExceededError in Safari incognito mode #42

AndreasHogstrom opened this issue Sep 10, 2015 · 4 comments · Fixed by #75

Comments

@AndreasHogstrom
Copy link
Contributor

When using safari in incognito mode, navigation fails with the following exception:

QuotaExceededError: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.

Safari denies usage of local/session storages when in incognito mode, and raises this error when you try to.

I am using the BrowserHistory history and it seems like the error stems from history/DOMStateStorage.

@mjackson
Copy link
Member

Thanks for reporting this bug, @AndreasHogstrom :)

The solution is probably two-fold:

  1. We should catch the QuotaExceededError and emit a warning instead
  2. We should make sure we are only ever calling saveState when we actually need to (i.e. when there is some state to save, e.g. a call to pushState(null, '/path') shouldn't actually try to saveState)

I think that would give developers the flexibility they need to either a) use state and ignore the warnings for users in incognito mode (or possibly try to detect when someone is in incognito mode and do the right thing) or 2) avoid using state entirely, thereby avoiding the warnings.

Would you care to make a PR @AndreasHogstrom?

@iam4x
Copy link
Contributor

iam4x commented Sep 30, 2015

@mjackson I ran into this today, does a simple in memory storage that polyfill the localStorage can make the trick?

I can drop you a PR with warning emitting for now.

@ArnaudValensi
Copy link

You can use this pollyfill to use the localStorage in memory:

(function () {
  function isSupported() {
    var item = 'localStoragePollyfill';
    try {
      localStorage.setItem(item, item);
      localStorage.removeItem(item);
      return true;
    } catch (e) {
      return false;
    }
  }

  if (!isSupported()) {
    try {
      Storage.prototype._data = {};

      Storage.prototype.setItem = function (id, val) {
        return this._data[id] = String(val);
      };

      Storage.prototype.getItem = function (id) {
        return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
      },

      Storage.prototype.removeItem = function (id) {
        return delete this._data[id];
      },

      Storage.prototype.clear = function () {
        return this._data = {};
      }
    } catch (e) {
      console.error('localStorage pollyfill error: ', e);
    }
  }
}());

@xwchris
Copy link

xwchris commented Jul 28, 2017

Yeah ! Finally I get the solution here~

@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants