diff options
author | Sam Potts <sam@potts.es> | 2018-03-18 01:37:24 +1100 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2018-03-18 01:37:24 +1100 |
commit | 43e6dcd41dac1ea3615f1ee92a2ec665e8c7edbc (patch) | |
tree | e290a6e508452f5cd466606a9937de7412c71643 /src/js/storage.js | |
parent | b06c8ae43fa9cce4d395dcef8a55067cb9198e8f (diff) | |
download | plyr-43e6dcd41dac1ea3615f1ee92a2ec665e8c7edbc.tar.lz plyr-43e6dcd41dac1ea3615f1ee92a2ec665e8c7edbc.tar.xz plyr-43e6dcd41dac1ea3615f1ee92a2ec665e8c7edbc.zip |
Fix for local storage issue
Diffstat (limited to 'src/js/storage.js')
-rw-r--r-- | src/js/storage.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/js/storage.js b/src/js/storage.js index 5f663ab5..5b914331 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -12,17 +12,18 @@ class Storage { // Check for actual support (see if we can use it) static get supported() { - if (!('localStorage' in window)) { - return false; - } + try { + if (!('localStorage' in window)) { + return false; + } - const test = '___test'; + const test = '___test'; - // Try to use it (it might be disabled, e.g. user is in private mode) - // see: https://github.com/sampotts/plyr/issues/131 - try { + // Try to use it (it might be disabled, e.g. user is in private mode) + // see: https://github.com/sampotts/plyr/issues/131 window.localStorage.setItem(test, test); window.localStorage.removeItem(test); + return true; } catch (e) { return false; @@ -30,9 +31,13 @@ class Storage { } get(key) { + if (!Storage.supported) { + return null; + } + const store = window.localStorage.getItem(this.key); - if (!Storage.supported || utils.is.empty(store)) { + if (utils.is.empty(store)) { return null; } |