From 43e6dcd41dac1ea3615f1ee92a2ec665e8c7edbc Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sun, 18 Mar 2018 01:37:24 +1100 Subject: Fix for local storage issue --- src/js/storage.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/js/storage.js') 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; } -- cgit v1.2.3