Skip to content

Commit 4600b5d

Browse files
committed
Cross-browser and cross-manifest compatibility down to Gecko 115.
1 parent 27e83da commit 4600b5d

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed

manifest.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ if (MANIFEST_VER.includes(3)) {
4949
json.manifest_version = 3;
5050
if (!isFirefox) {
5151
delete json.browser_specific_settings;
52+
delete json.content_security_policy;
5253
const {scripts} = json.background;
5354
delete json.background.scripts;
5455
delete json.background.persistent;
@@ -70,15 +71,15 @@ if (MANIFEST_VER.includes(3)) {
7071
"webRequestFilterResponse",
7172
"webRequestFilterResponse.serviceWorkerScript",
7273
]) {
73-
permissions.delete (p);
74+
permissions.delete(p);
7475
}
7576

7677
const excludedScriptsRx = /\bcontent\/(?:embeddingDocument|dirindex)\.js$/;
7778
for (const cs of json.content_scripts) {
7879
cs.js = cs.js.filter(src => !excludedScriptsRx.test(src));
7980
}
8081
delete json.browser_action;
81-
delete json.commands._execute_browser_action
82+
delete json.commands._execute_browser_action;
8283
} else {
8384
// MV2
8485
json.manifest_version = 2;
@@ -92,16 +93,25 @@ if (MANIFEST_VER.includes(3)) {
9293
permissions.delete(p);
9394
}
9495

95-
// TODO: just scan ${MANIFEST_SRC_DIR}/nscl/mv2main/*.js
96-
const mainWorldPatchers = [
97-
"patchWorkers",
98-
"prefetchCSSResources",
99-
"WebGLHook"
100-
];
101-
const mainWorldPatchersRx = new RegExp(`nscl/content/(${mainWorldPatchers.join("|")})\\b`);
102-
(json.content_scripts = json.content_scripts.filter(cs => !cs.world)).forEach(cs => {
103-
cs.js = cs.js.map(src => src.replace(mainWorldPatchersRx, "nscl/mv2main/$1"));
104-
});
96+
// Append MAIN world "*.main.js" scripts to their isolated counterparts
97+
// (on Gecko we will patch windows through xray)
98+
const isolatedWorldJS = json.content_scripts.find(
99+
cs => cs.world != "MAIN" && cs.js?.some(src => src.endsWith("/Worlds.js"))).js;
100+
101+
json.content_scripts.find(cs => cs.world == "MAIN" && cs.js?.some(src => src.endsWith("/Worlds.main.js")))
102+
.js.filter(src => src.endsWith(".main.js"))
103+
.forEach(src => {
104+
const isolatedSrc = src.replace(/.*(\/[\w+.]+)\.main(?=\.js$)/, "$1");
105+
const idx = isolatedWorldJS.findIndex(src => src.endsWith(isolatedSrc));
106+
if (idx > -1) {
107+
isolatedWorldJS.splice(idx + 1, 0, src)
108+
} else {
109+
isolatedWorldJS.push(src);
110+
}
111+
});
112+
113+
// remove all the MAIN world content script
114+
json.content_scripts = json.content_scripts.filter(cs => cs.world != "MAIN");
105115
}
106116

107117
// remove developer-only stuff

src/bg/main.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,9 @@
238238
} catch (e) {
239239
console.error(e);
240240
}
241-
const ret = {"vintage": await Themes.isVintage()};
241+
const ret = {"vintage": !!(await Themes.isVintage())};
242242
console.debug("Returning from getTheme", ret); // DEV_ONLY
243-
return ret;
244-
},
245-
246-
async promptHook(msg, {tabId}) {
247-
const func = () => {
248-
try { if (document.fullscreenElement) document.exitFullscreen(); } catch (e) {}
249-
};
250-
await Scripting.executeScript({
251-
target: {tabId},
252-
func,
253-
});
243+
return Promise.resolve(ret);
254244
},
255245

256246
async reloadWithCredentials({tabId, remember}) {
@@ -309,7 +299,10 @@
309299

310300
async computeChildPolicy({url, contextUrl}, sender) {
311301
await ns.initializing;
312-
let {tab} = sender;
302+
let {tab, origin} = sender;
303+
if (url == sender.url && url == "about:blank") {
304+
url = origin;
305+
}
313306
let policy = ns.policy;
314307
const {isTorBrowser} = ns.local;
315308
if (!policy) {
@@ -443,7 +436,7 @@
443436
return seen;
444437
} catch (e) {
445438
try {
446-
const {url} = (await browser.tabs.get(tabId)).url;
439+
const {url} = (await browser.tabs.get(tabId));
447440
await include("/nscl/common/restricted.js");
448441
if (!isRestrictedURL(url)) {
449442
// probably a page where content scripts cannot run, let's open the options instead

src/content/content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ window.addEventListener("securitypolicyviolation", async e => {
165165
Messages.send("violation", {url: reportUrl, type, isReport});
166166
}, true);
167167

168-
if (!/^https:/.test(location.protocol)) {
168+
if (!/^http/.test(location.protocol)) {
169169
// Reporting CSP can only be injected in HTTP responses,
170170
// let's emulate them using mutation observers
171171
const checked = new Set();

src/manifest.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
"browser_specific_settings": {
66
"gecko": {
77
"id": "{73a6fe31-595d-460b-a920-fcc0f8843232}",
8-
"strict_min_version": "66.0",
9-
"strict_max_version": "665.0"
8+
"strict_min_version": "115.0"
109
},
1110
"gecko_android": {}
1211
},
1312
"version": "12.0.8.901",
1413
"description": "__MSG_Description__",
1514
"incognito": "spanning",
1615

16+
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'none'",
17+
1718
"icons": {
1819
"48": "img/icon48.png",
1920
"96": "img/icon96.png",
@@ -106,7 +107,6 @@
106107
"/nscl/common/RequestKey.js",
107108
"/nscl/content/DocRewriter.js",
108109
"/nscl/content/Worlds.js",
109-
"/nscl/content/patchWindow.js",
110110
"/nscl/content/patchWorkers.js",
111111
"/nscl/content/DocumentCSP.js",
112112
"/nscl/content/NoscriptElements.js",
@@ -117,7 +117,6 @@
117117
"content/staticNS.js",
118118
"/nscl/content/media.js",
119119
"/nscl/content/WebGLHook.js",
120-
"/nscl/content/promptHook.js",
121120
"content/embeddingDocument.js",
122121
"content/content.js",
123122
"content/dirindex.js",

src/nscl

Submodule nscl updated from 44008d5 to 42b0ded

0 commit comments

Comments
 (0)