Merge pull request #168 from yields/fix/security-error

fix: security error on safari - closes #167
This commit is contained in:
Nathan Rajlich 2015-01-13 13:03:05 -08:00
commit 2c384416fb

View File

@ -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) {}
}