From 9815e0f7cfca84a0d397259d88767f354dec85a8 Mon Sep 17 00:00:00 2001 From: hackademix Date: Wed, 11 Jul 2018 19:26:50 +0200 Subject: Fixed race condition in work-around for broken feeds in ESR60. --- src/bg/RequestUtil.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/bg') diff --git a/src/bg/RequestUtil.js b/src/bg/RequestUtil.js index fa099d6..e151f5b 100644 --- a/src/bg/RequestUtil.js +++ b/src/bg/RequestUtil.js @@ -19,17 +19,8 @@ types: ["main_frame", "sub_frame", "object"] }; - - browser.webRequest.onCompleted.addListener(r => { - cleanup(r); - let {tabId, url} = r; - let key = tabKey(tabId, url); - if (reloadingTabs.has(key)) { - debug("Reloading tab", key); - browser.tabs.update(tabId, {url}); - } - }, filter); - browser.webRequest.onErrorOccurred.addListener(cleanup, filter); + for (let event of ["onCompleted", "onErrorOccurred"]) + browser.webRequest[event].addListener(cleanup, filter); let executeAll = async (scripts, where) => { let {url, tabId, frameId} = where; @@ -99,9 +90,12 @@ let filter = browser.webRequest.filterResponseData(requestId); let buffer = []; let first = true; + let done = false; + let mustReload = false; let runAndFlush = async () => { let scriptsRan = await executeAll(scripts, request); if (mustCheckFeed && !scriptsRan) { + mustReload = true; debug(`Marking as "must reload"`, tabId, url); reloadingTabs.add(tabKey(tabId, url)); } @@ -113,6 +107,9 @@ filter.disconnect(); buffer = null; } + if (done) { + filter.onstop(null); + } }; if (brokenOnLoad) { @@ -137,7 +134,13 @@ filter.disconnect(); }; - + filter.onstop = event => { + done = true; + if (mustReload && !buffer) { + mustReload = false; + browser.tabs.update(tabId, {url}); + } + } } } } -- cgit v1.2.3