[nscl] Refactored ContentScriptOnce.js to the library.
This commit is contained in:
parent
d97b2f6d18
commit
c293ebc250
|
@ -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)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
2
src/nscl
2
src/nscl
|
@ -1 +1 @@
|
||||||
Subproject commit efa5fbede1c54f0a9cd0b0ad54b10772a60dfb09
|
Subproject commit b6506b0275720233a500fbdb1cdb6548815405eb
|
|
@ -97,7 +97,7 @@ var XSS = (() => {
|
||||||
let block = !!(reasons.urlInjection || reasons.postInjection)
|
let block = !!(reasons.urlInjection || reasons.postInjection)
|
||||||
|
|
||||||
if (reasons.protectName) {
|
if (reasons.protectName) {
|
||||||
await include("bg/ContentScriptOnce.js");
|
await include("/nscl/service/ContentScriptOnce.js");
|
||||||
await ContentScriptOnce.execute(request, {
|
await ContentScriptOnce.execute(request, {
|
||||||
js: [{file: "/xss/sanitizeName.js"}],
|
js: [{file: "/xss/sanitizeName.js"}],
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue