diff options
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; } |