From 8572ff6b42a3f960dd7dc841c1069b616878a387 Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Thu, 12 Oct 2017 21:51:19 -0700 Subject: [PATCH] Work around localStorage not available in private windows. Fix #1163. --- .../src/coffee/background.coffee | 8 ++++++-- .../src/js/omega_target_popup.js | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/omega-target-chromium-extension/src/coffee/background.coffee b/omega-target-chromium-extension/src/coffee/background.coffee index 77a8e19..2e489c7 100644 --- a/omega-target-chromium-extension/src/coffee/background.coffee +++ b/omega-target-chromium-extension/src/coffee/background.coffee @@ -311,8 +311,12 @@ refreshActivePageIfEnabled = -> chrome.runtime.onMessage.addListener (request, sender, respond) -> return unless request and request.method options.ready.then -> - target = options - method = target[request.method] + if request.method == 'getState' + target = state + method = state.get + else + target = options + method = target[request.method] if typeof method != 'function' Log.error("No such method #{request.method}!") respond( diff --git a/omega-target-chromium-extension/src/js/omega_target_popup.js b/omega-target-chromium-extension/src/js/omega_target_popup.js index f734d39..ae0b893 100644 --- a/omega-target-chromium-extension/src/js/omega_target_popup.js +++ b/omega-target-chromium-extension/src/js/omega_target_popup.js @@ -24,6 +24,10 @@ var requestInfoCallback = null; OmegaTargetPopup = { getState: function (keys, cb) { + if (typeof localStorage === 'undefined' || !localStorage.length) { + callBackground('getState', [keys], cb); + return; + } var results = {}; keys.forEach(function(key) { try {