Switch from deferWebTraffic to Wakening.
This commit is contained in:
parent
6344d120cb
commit
7fd88e6228
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* NoScript - a Firefox extension for whitelist driven safe JavaScript execution
|
||||
*
|
||||
* Copyright (C) 2005-2024 Giorgio Maone <https://maone.net>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
function deferWebTraffic(promiseToWaitFor, next) {
|
||||
debug("deferWebTraffic on %o", promiseToWaitFor);
|
||||
let seenTabs = new Set();
|
||||
function checkNavigation(nav) {
|
||||
if (nav.tabId !== browser.tabs.TAB_ID_NONE && nav.url.startsWith("http")) {
|
||||
let seen = seenTabs.has(nav.tabId);
|
||||
debug(`%s navigation %o`, seen ? "seen" : "unseen", nav);
|
||||
if (!seen) {
|
||||
reloadTab(nav.tabId);
|
||||
}
|
||||
}
|
||||
}
|
||||
browser.webNavigation.onCommitted.addListener(checkNavigation);
|
||||
function reloadTab(tabId) {
|
||||
seenTabs.add(tabId);
|
||||
try {
|
||||
browser.tabs.executeScript(tabId, {
|
||||
runAt: "document_start",
|
||||
code: "if (performance.now() < 60000) window.location.reload(false)"
|
||||
});
|
||||
debug("Reloading tab", tabId);
|
||||
} catch (e) {
|
||||
error(e, "Can't reload tab", tabId);
|
||||
}
|
||||
}
|
||||
|
||||
async function waitFor(request) {
|
||||
let {type, documentUrl, url, tabId, frameId} = request;
|
||||
debug("deferWebTraffic probing",request);
|
||||
if (tabId === browser.tabs.TAB_ID_NONE) return;
|
||||
if (!seenTabs.has(tabId)) {
|
||||
if (type === "main_frame") {
|
||||
seenTabs.add(tabId);
|
||||
} else if (documentUrl) {
|
||||
if (frameId !== 0 && request.frameAncestors) {
|
||||
documentUrl = request.frameAncestors.pop().url;
|
||||
}
|
||||
reloadTab(tabId);
|
||||
}
|
||||
}
|
||||
debug("Deferring %s %s from %s", type, url, documentUrl);
|
||||
try {
|
||||
await promiseToWaitFor;
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
debug("Green light to %s %s from %s", type, url, documentUrl);
|
||||
}
|
||||
|
||||
function spyTabs(request) {
|
||||
debug("Spying request %o", request);
|
||||
}
|
||||
|
||||
browser.webRequest.onHeadersReceived.addListener(spyTabs, {
|
||||
urls: ["<all_urls>"],
|
||||
types: ["main_frame"],
|
||||
}, ["blocking", "responseHeaders"]);
|
||||
browser.webRequest.onBeforeRequest.addListener(waitFor, {
|
||||
urls: ["<all_urls>"]
|
||||
}, ["blocking"]);
|
||||
|
||||
(async () => {
|
||||
await promiseToWaitFor;
|
||||
browser.webNavigation.onCommitted.removeListener(checkNavigation);
|
||||
browser.webRequest.onBeforeRequest.removeListener(waitFor);
|
||||
browser.webRequest.onHeadersReceived.removeListener(spyTabs);
|
||||
if (next) next();
|
||||
})();
|
||||
}
|
|
@ -317,12 +317,9 @@
|
|||
return {permissions, unrestricted, cascaded, isTorBrowser};
|
||||
},
|
||||
|
||||
start() {
|
||||
if (this.running) return;
|
||||
this.running = true;
|
||||
async init() {
|
||||
browser.runtime.onSyncMessage.addListener(onSyncMessage);
|
||||
deferWebTraffic(Messages.wakening = this.initializing = init(),
|
||||
async () => {
|
||||
await Wakening.waitFor(Messages.wakening = this.initializing = init());
|
||||
Commands.install();
|
||||
try {
|
||||
this.devMode = (await browser.management.getSelf()).installType === "development";
|
||||
|
@ -330,16 +327,6 @@
|
|||
if (!(this.local.debug || this.devMode)) {
|
||||
debug = () => {}; // suppress verbosity
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
stop() {
|
||||
if (!this.running) return;
|
||||
this.running = false;
|
||||
browser.runtime.onSyncMessage.removeListener(onSyncMessage);
|
||||
Messages.removeHandler(messageHandler);
|
||||
RequestGuard.stop();
|
||||
log("STOPPED");
|
||||
},
|
||||
|
||||
test() {
|
||||
|
@ -406,4 +393,4 @@
|
|||
};
|
||||
}
|
||||
|
||||
ns.start();
|
||||
ns.init();
|
||||
|
|
|
@ -64,10 +64,10 @@
|
|||
"/nscl/service/patchWorkers.js",
|
||||
"/nscl/service/TabCache.js",
|
||||
"/nscl/service/TabTies.js",
|
||||
"/nscl/service/Wakening.js",
|
||||
"ui/Prompts.js",
|
||||
"xss/XSS.js",
|
||||
"bg/ReportingCSP.js",
|
||||
"bg/deferWebTraffic.js",
|
||||
"bg/Defaults.js",
|
||||
"bg/TabGuard.js",
|
||||
"bg/RequestGuard.js",
|
||||
|
|
Loading…
Reference in New Issue