From 923b1ff4ec547be25bbe89cddc0b0dc849e40c90 Mon Sep 17 00:00:00 2001 From: chriszarate Date: Tue, 11 Jul 2017 13:57:52 -0400 Subject: [PATCH] Fix security exception on iOS when localStorage is disabled. See, e.g.: https://github.com/angular-translate/angular-translate/issues/629 --- backbone.fetch-cache.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/backbone.fetch-cache.js b/backbone.fetch-cache.js index 0d446f7..8794cdd 100644 --- a/backbone.fetch-cache.js +++ b/backbone.fetch-cache.js @@ -26,18 +26,16 @@ collectionFetch: Backbone.Collection.prototype.fetch }, supportLocalStorage = (function() { - var supported = typeof window.localStorage !== 'undefined'; - if (supported) { - try { - // impossible to write on some platforms when private browsing is on and - // throws an exception = local storage not supported. - localStorage.setItem('test_support', 'test_support'); - localStorage.removeItem('test_support'); - } catch (e) { - supported = false; - } + try { + // impossible to write on some platforms when private browsing is on and + // throws an exception = local storage not supported. + localStorage.setItem('test_support', 'test_support'); + localStorage.removeItem('test_support'); + } catch (e) { + return false; } - return supported; + + return true; })(); Backbone.fetchCache = (Backbone.fetchCache || {});