-
Notifications
You must be signed in to change notification settings - Fork 1k
SecurityError: Dom Exception 18 is thrown when local storage/cookies are blocked in Safari on iOS 7.1.2 #629
Comments
When it is blocked so save, the storage handler can not save. That's fine. Therefor the patch seems to be okay. |
Ehm.. this has already landed in master? 59aa2a0 Is this an issue any more? |
Hey guys, Yes, the issue is in 59aa2a0. As I wrote in the top post, the exception is thrown when $window.localStorage is checked if it is not null on angular-translate-storage-local.js, line 25: var hasLocalStorageSupport = 'localStorage' in $window && $window.localStorage !== null; So the fix I thought about is to move the access to $window.localStorage inside try block (lines 28-30), so the exception is caught. |
You mean |
Yes, $window.localStorage !== null throws SecurityError: Dom Exception 18. I've found it out by decomposing the statement var hasLocalStorageSupport = 'localStorage' in $window && $window.localStorage !== null; into something like this: var hasLocalStorageSupport;
if ('localStorage' in $window) {
if ($window.localStorage !== null) {
hasLocalStorageSupport == true
}
} and noticed the exception was thrown from this line: if ($window.localStorage !== null) { |
@nbaronov Okay, I'm with you. Browsers' JS VMs have such neat api from time to time.. Do want make a PR? Be sure reading the contributions guidelines regarding the correct branches and so on.. |
This fixes a unhandled exception (i.e. iOS) when checking for local storage support. fixes angular-translate#629
After removing the block cookie settings from safari, works like a charm. thanks @nbaronov . |
Hello,
Please note an unhandled SecurityError exception is thrown, resulting in Angular crash, when storing something in local storage on Safari on iOS 7.1.2 with blocked cookies (Settings > Safari > Block Cookies > Always). I guess disabling cookies also disables local storage. With other two choices of block cookies setting ("From third parties and advertisers" and "Never") everything works fine.
The issue occurs on angular-translate-storage-local.js, line 25:
and more specifically while accessing $window.localStorage to check if it is null.
I was able to fix this by moving access to $window.localStorage inside the try block (lines 28-30) like this:
With above change the code never stores anything (since it can't), but at least Angular doesn't crash. I don't like silent failures like this one, but I'm not sure how to handle this within angular-translate. Maybe an event should be emitted ...
Please let me know what do you think.
Please note this is a repost of closed angular-translate/bower-angular-translate-storage-local#4, requested by @PascalPrecht.
The text was updated successfully, but these errors were encountered: