summaryrefslogtreecommitdiff
path: root/src/bg
diff options
context:
space:
mode:
authorhackademix2018-07-11 19:26:50 +0200
committerhackademix2018-07-11 19:26:50 +0200
commit9815e0f7cfca84a0d397259d88767f354dec85a8 (patch)
treef3f3bef2f965fdb64193cab2737f25d223988761 /src/bg
parent9a0a76ec3c0f2ed02e5fb345e5f9dbfc8e8e004a (diff)
downloadnoscript-9815e0f7cfca84a0d397259d88767f354dec85a8.tar.gz
noscript-9815e0f7cfca84a0d397259d88767f354dec85a8.tar.xz
noscript-9815e0f7cfca84a0d397259d88767f354dec85a8.zip
Fixed race condition in work-around for broken feeds in ESR60.
Diffstat (limited to 'src/bg')
-rw-r--r--src/bg/RequestUtil.js27
1 files changed, 15 insertions, 12 deletions
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});
+ }
+ }
}
}
}