From 777fc068343f85c552fde3abe8b2feabdf0f1616 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 28 Aug 2017 13:10:38 +0300 Subject: [PATCH] FF: avoid reloading if dysfunctional --- js/dom.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/js/dom.js b/js/dom.js index c56a2b4b..a4d90489 100644 --- a/js/dom.js +++ b/js/dom.js @@ -264,9 +264,16 @@ function dieOnDysfunction() { }); // TODO: fallback to sendMessage in FF since private windows can't get bg page chrome.windows.getCurrent(wnd => wnd.incognito && die()); - // check if privacy settings were fixed but the extension wasn't reloaded - const bg = chrome.extension.getBackgroundPage(); - if (bg && !(bg.cachedStyles || {}).list) { - chrome.runtime.reload(); - } + // check if privacy settings were fixed but the extension wasn't reloaded, + // use setTimeout to auto-cancel if already dead + setTimeout(() => { + const bg = chrome.extension.getBackgroundPage(); + if (bg && !(bg.cachedStyles || {}).list) { + chrome.storage.local.get('reloaded', data => { + if (!data || Date.now() - (data.reloaded || 0) > 10e3) { + chrome.storage.local.set({reloaded: Date.now()}, () => chrome.runtime.reload()); + } + }); + } + }); }