Skip to content

Commit

Permalink
Disable localStorage.setItem in Private mode
Browse files Browse the repository at this point in the history
Will throw QuotaExceededError when called.
There shouldn’t be any need to use a shim for this since no solution would be persistent in Private mode.
  • Loading branch information
el1t committed Dec 26, 2016
1 parent 9264178 commit 718efdb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions platform/safari/vapi-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,16 @@ Number.prototype.toLocaleString = function() {

vAPI.localStorage = self.localStorage;

// Disable localStorage.setItem in Private Browsing mode (throws error)
// https://gist.github.com/philfreo/68ea3cd980d72383c951
if (typeof self.localStorage === 'object') {
try {
self.localStorage.setItem('localStorage', 1);
self.localStorage.removeItem('localStorage');
} catch (e) {
Storage.prototype._setItem = Storage.prototype.setItem;
Storage.prototype.setItem = function() {};
}
}

})();

0 comments on commit 718efdb

Please sign in to comment.