From 718efdbd78e7d5f30d2f534d5118761318e00cfa Mon Sep 17 00:00:00 2001 From: Ellis Tsung Date: Sun, 25 Dec 2016 21:45:05 -0500 Subject: [PATCH] Disable localStorage.setItem in Private mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- platform/safari/vapi-common.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js index a2285462b71b7..26d99e11b11bf 100644 --- a/platform/safari/vapi-common.js +++ b/platform/safari/vapi-common.js @@ -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() {}; + } +} + })();