From 988592b640bf10faac2d8ebafa3135c0f3351123 Mon Sep 17 00:00:00 2001 From: Amir Abushareb Date: Wed, 7 Jan 2015 11:16:20 +0200 Subject: [PATCH] fix: security error on safari - closes #167 --- browser.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/browser.js b/browser.js index 52c3d32f..55f4cf92 100644 --- a/browser.js +++ b/browser.js @@ -21,7 +21,7 @@ var storage; if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined') storage = chrome.storage.local; else - storage = window.localStorage; + storage = localstorage(); /** * Colors. @@ -156,3 +156,20 @@ function load() { */ exports.enable(load()); + +/** + * Localstorage attempts to return the localstorage. + * + * This is necessary because safari throws + * when a user disables cookies/localstorage + * and you attempt to access it. + * + * @return {LocalStorage} + * @api private + */ + +function localstorage(){ + try { + return window.localStorage; + } catch (e) {} +}