gsklee / ngStorage

localStorage and sessionStorage done right for AngularJS.
MIT License
2.33k stars 461 forks source link

fix DOM Exception 18 when cookies are blocked by user in Safari #103

Closed everdimension closed 9 years ago

everdimension commented 9 years ago

If cookies are disabled in Safari browser (Privacy —> Cookies and website data —> "Always block"), then simply calling localStorage ($window['localStorage']) throws an error, which breaks the whole app.

This fix simply catches the error.

bmulholland commented 9 years ago

+1 This PR would also fix #75

Here's some language for the IE issue in 75:

// Some installations of IE, for an unknown reason, throw "SCRIPT5: Error: Access is denied"
// when accessing window.localStorage. This happens before you try to do anything with it. Catch
// that error and allow execution to continue.