From 37ce825dc1d719fe04c59998eae5457fce78502c Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 17 Aug 2017 11:23:19 -0400 Subject: [PATCH] fix https://github.com/gorhill/uBlock/issues/2824 --- platform/chromium/vapi-common.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index e6a3a70..932ce9b 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -91,7 +91,31 @@ vAPI.closePopup = function() { // This storage is optional, but it is nice to have, for a more polished user // experience. -vAPI.localStorage = self.localStorage; +// This can throw in some contexts (like in devtool). +try { + vAPI.localStorage = self.localStorage; +} 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() { + } + }; +} /******************************************************************************/