summaryrefslogtreecommitdiff
path: root/src/bg/RequestUtil.js
diff options
context:
space:
mode:
authorhackademix2018-07-26 19:33:46 +0200
committerhackademix2018-07-26 19:33:46 +0200
commitd3cacf634fad5a80c8a715df60d3e53f008252df (patch)
tree377b4f57c20a3f64b8d5f4a754a0aafe6cb61b9c /src/bg/RequestUtil.js
parenta8a6dd4c7bd47ff6960fd71d1a20d151fa08de12 (diff)
downloadnoscript-d3cacf634fad5a80c8a715df60d3e53f008252df.tar.gz
noscript-d3cacf634fad5a80c8a715df60d3e53f008252df.tar.xz
noscript-d3cacf634fad5a80c8a715df60d3e53f008252df.zip
More edge cases covered in dynamic script injection.
Diffstat (limited to 'src/bg/RequestUtil.js')
-rw-r--r--src/bg/RequestUtil.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/bg/RequestUtil.js b/src/bg/RequestUtil.js
index 2999cc1..690d7ba 100644
--- a/src/bg/RequestUtil.js
+++ b/src/bg/RequestUtil.js
@@ -20,32 +20,39 @@
};
let executeAll = async request => {
- let {url, tabId, frameId, requestId} = request;
+ let {url, tabId, frameId, requestId, type} = request;
let scripts = pendingScripts.get(requestId);
if (!scripts) return -1;
pendingScripts.delete(requestId);
+
+ let where = type === "object" ? {allFrames: true} : {frameId};
let count = 0;
- await Promise.all([...scripts.values()].map(async details => {
+ let run = async details => {
details = Object.assign({
runAt: "document_start",
matchAboutBlank: true,
- frameId,
- }, details);
+ }, details, where);
try {
+ let res;
for (let attempts = 10; attempts-- > 0;) {
try {
- await browser.tabs.executeScript(tabId, details);
+ res = await browser.tabs.executeScript(tabId, details);
+ break;
} catch(e) {
if (!/No matching message handler/.test(e.message)) throw e;
debug("Couldn't inject script into %s: too early? Retrying up to %s times...", url, attempts);
}
}
count++;
- debug("Execute on start OK", url, details);
+ debug("Execute on start OK, result=%o", res, url, details);
} catch (e) {
error(e, "Execute on start failed", url, details);
}
- }));
+ };
+
+ await run({code: `void(window.correctFrame = () => "${url}" === document.URL && document.readyState === "loading")`});
+ await Promise.all([...scripts.values()].map(run));
+ await run({code: `void(window.correctFrame = () => false)`});
return count;
};
@@ -59,7 +66,6 @@
wr[event].addListener(cleanup, filter);
}
- filter.types = ["main_frame"];
wr.onResponseStarted.addListener(r => {
let scripts = pendingScripts.get(r.requestId);
if (scripts) scripts.runAndFlush();
@@ -73,7 +79,7 @@
},
executeOnStart(request, details) {
- let {requestId, url, tabId, frameId, statusCode} = request;
+ let {requestId, url, tabId, frameId, statusCode, type} = request;
if (statusCode >= 300 && statusCode < 400) return;
if (frameId === 0) {