From 6fb6b4ed989ee9b6c0f910ede2f3d38ea99581e8 Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 26 Jul 2017 08:11:22 -0400 Subject: [PATCH] fix #2824: use dummy localStorage if none available --- platform/chromium/vapi-background.js | 4 ++-- platform/chromium/vapi-common.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index e6b58751b..20acf3454 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -1394,7 +1394,7 @@ vAPI.cloud = (function() { var options = { defaultDeviceName: window.navigator.platform, - deviceName: window.localStorage.getItem('deviceName') || '' + deviceName: vAPI.localStorage.getItem('deviceName') || '' }; // This is used to find out a rough count of how many chunks exists: @@ -1538,7 +1538,7 @@ vAPI.cloud = (function() { } if ( typeof details.deviceName === 'string' ) { - window.localStorage.setItem('deviceName', details.deviceName); + vAPI.localStorage.setItem('deviceName', details.deviceName); options.deviceName = details.deviceName; } diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index 5a2c27993..28419f3ca 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -100,6 +100,26 @@ try { } catch (ex) { } +// https://github.com/gorhill/uBlock/issues/2824 +// Use a dummy localStorage if for some reasons it's not available. +if ( vAPI.localStorage instanceof Object === false ) { + vAPI.localStorage = { + length: 0, + clear: function() { + }, + getItem: function() { + return null; + }, + key: function() { + throw new RangeError(); + }, + removeItem: function() { + }, + setItem: function() { + } + }; +} + /******************************************************************************/ })(this);