Skip to content

Commit 2c38441

Browse files
committed
Merge pull request #168 from yields/fix/security-error
fix: security error on safari - closes #167
2 parents 24cc5c0 + 988592b commit 2c38441

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

browser.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var storage;
2121
if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined')
2222
storage = chrome.storage.local;
2323
else
24-
storage = window.localStorage;
24+
storage = localstorage();
2525

2626
/**
2727
* Colors.
@@ -156,3 +156,20 @@ function load() {
156156
*/
157157

158158
exports.enable(load());
159+
160+
/**
161+
* Localstorage attempts to return the localstorage.
162+
*
163+
* This is necessary because safari throws
164+
* when a user disables cookies/localstorage
165+
* and you attempt to access it.
166+
*
167+
* @return {LocalStorage}
168+
* @api private
169+
*/
170+
171+
function localstorage(){
172+
try {
173+
return window.localStorage;
174+
} catch (e) {}
175+
}

0 commit comments

Comments
 (0)