Closed szechyjs closed 5 years ago
Ah, thanks for reporting this. The fallback is working in some cases (Safari in private mode), but I haven't actually seen this case. I'll try to release a patch later today
Looking at the implementation of isStorageAvailable
it looks like it's doing something similar to modernizr. The solution may just be to remove the checks for undefined, as they are what throw the exceptions (and not being caught).
typeof sessionStorage as any === 'undefined'
Those are actually necessary when the module is used in a NodeJS environment (e.g. when using Angular Universal).
@szechyjs Should be fixed in version 3.1.2. Thanks again for reporting the issue! :+1:
Oops, I messed up the condition :(
Fixed in version 3.1.3
I've disabled localstorage in Chrome to test the fallback, however it is not working.
ngx-webstorage-service.js:185 maps to -> https://github.com/dscheerens/ngx-webstorage-service/blob/master/lib/src/storage-service.module.ts#L22
A similar error occurs for session storage.
ngx-webstorage-service.js:179 maps to -> https://github.com/dscheerens/ngx-webstorage-service/blob/master/lib/src/storage-service.module.ts#L14
This is how modernizr detects availability: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js
Seems a try/catch is the only way to properly do this, as browsers like Chrome throw an exception when trying to access
localStorage
andsessionStorage
.