Skip to content

Commit

Permalink
Fix security exception on iOS when localStorage is disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriszarate committed Jul 12, 2017
1 parent e086240 commit 923b1ff
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions backbone.fetch-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {});
Expand Down

0 comments on commit 923b1ff

Please sign in to comment.