[nscl] Refactored ContentScriptOnce.js to the library.

This commit is contained in:
hackademix 2021-04-13 12:39:08 +02:00
parent d97b2f6d18
commit c293ebc250
3 changed files with 2 additions and 54 deletions

View File

@ -1,52 +0,0 @@
var ContentScriptOnce = (() => {
"use strict";
let requestMap = new Map();
{
let cleanup = r => {
let {requestId} = r;
let scripts = requestMap.get(requestId);
if (scripts) {
window.setTimeout(() => {
requestMap.delete(requestId);
for (let s of scripts) s.unregister();
}, 0);
}
}
let filter = {
urls: ["<all_urls>"],
types: ["main_frame", "sub_frame", "object"]
};
let wr = browser.webRequest;
for (let event of ["onCompleted", "onErrorOccurred"]) {
wr[event].addListener(cleanup, filter);
}
}
return {
async execute(request, options) {
let {requestId, url} = request;
let scripts = requestMap.get(requestId);
if (!scripts) requestMap.set(requestId, scripts = new Set());
try {
let urlObj = new URL(url);
if (urlObj.port) {
urlObj.port = "";
url = urlObj.toString();
}
} catch (e) {}
let defOpts = {
runAt: "document_start",
matchAboutBlank: true,
matches: [url],
allFrames: true,
};
scripts.add(await browser.contentScripts.register(
Object.assign(defOpts, options)
));
}
}
})();

@ -1 +1 @@
Subproject commit efa5fbede1c54f0a9cd0b0ad54b10772a60dfb09
Subproject commit b6506b0275720233a500fbdb1cdb6548815405eb

View File

@ -97,7 +97,7 @@ var XSS = (() => {
let block = !!(reasons.urlInjection || reasons.postInjection)
if (reasons.protectName) {
await include("bg/ContentScriptOnce.js");
await include("/nscl/service/ContentScriptOnce.js");
await ContentScriptOnce.execute(request, {
js: [{file: "/xss/sanitizeName.js"}],
});