Fix localStorage check when embedded in iframe (firefox)

This commit is contained in:
Matyas Albert Nagy 2018-02-24 14:14:39 +01:00 committed by GitHub
parent 6e20d5fccc
commit 9f867e7c16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,7 +10,13 @@ const TIME_KEY = '__rlT';
*/
export function isStorageSupported(storageName)
{
if (storageName in window && window[storageName] && window[storageName].setItem)
let storageIsAvailable = false;
try {
storageIsAvailable = storageName in window && window[storageName] && window[storageName].setItem;
}
catch(e) {} // at: window[storageName] firefox throws SecurityError: The operation is insecure. when in iframe
if (storageIsAvailable)
{
const
s = window[storageName],
@ -28,6 +34,7 @@ export function isStorageSupported(storageName)
catch (e) {} // eslint-disable-line no-empty
}
return false;
}