From 53310a0a805c1fb6f77ca1798d9efe89ebd6fc13 Mon Sep 17 00:00:00 2001 From: Billy Lamberta Date: Wed, 10 Apr 2013 20:28:54 -0700 Subject: [PATCH] Wrap localStorage check in try/catch. --- src/persistent_storage.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/persistent_storage.js b/src/persistent_storage.js index 2812c019..bd8b21aa 100644 --- a/src/persistent_storage.js +++ b/src/persistent_storage.js @@ -5,15 +5,21 @@ */ var PersistentStorage = (function() { - var ls = window.localStorage, methods; + var ls, methods; + try { + ls = window.localStorage; + } catch (err) { + ls = null; + } + function PersistentStorage(namespace) { this.prefix = ['__', namespace, '__'].join(''); this.ttlKey = '__ttl__'; this.keyMatcher = new RegExp('^' + this.prefix); } - if (window.localStorage && window.JSON) { + if (ls && window.JSON) { methods = { // private methods