From 340cb39083e7380f80abde95e46e192fd7b40bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Sat, 6 Jun 2015 17:18:46 +0200 Subject: [PATCH] Detect Safari incognito localstorage fail Fixes #591 --- js/localstorage.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/localstorage.js b/js/localstorage.js index 0c1218e..041e359 100644 --- a/js/localstorage.js +++ b/js/localstorage.js @@ -10,6 +10,15 @@ ls.factory("$store", ["$parse", function($parse){ var storage = (typeof window.localStorage === 'undefined') ? undefined : window.localStorage, supported = !(typeof storage == 'undefined' || typeof window.JSON == 'undefined'); + // Safari reports a localStorage object in incognito mode, but trying + // to use it raises an exception. Catch that case. + try { + storage.setItem('dummy', 'dummy'); + storage.removeItem('dummy'); + } catch (error) { + supported = false; + } + if (!supported) { console.log('Warning: localStorage is not supported'); }