Преглед изворни кода

don't lazy load content scripts in frames (Firefox issues with executeScript)

Gildas пре 7 година
родитељ
комит
37cf117d6d
3 измењених фајлова са 18 додато и 20 уклоњено
  1. 0 8
      extension/core/bg/bg.js
  2. 12 10
      extension/ui/content/infobar.js
  3. 6 2
      manifest.json

+ 0 - 8
extension/core/bg/bg.js

@@ -24,13 +24,6 @@ singlefile.core = (() => {
 
 	const TIMEOUT_PROCESS_START_MESSAGE = 10000;
 
-	const frameScriptFiles = [
-		"/lib/browser-polyfill/custom-browser-polyfill.js",
-		"/extension/index.js",
-		"/lib/frame-tree/content/frame-tree.js",
-		"/extension/core/content/content-frame.js"
-	];
-
 	const topScriptFiles = [
 		"/lib/browser-polyfill/custom-browser-polyfill.js",
 		"/extension/index.js",
@@ -75,7 +68,6 @@ singlefile.core = (() => {
 
 	async function processStart(tab, options) {
 		if (!options.removeFrames) {
-			await executeScripts(tab.id, frameScriptFiles, { allFrames: true, matchAboutBlank: true });
 			await FrameTree.initialize(tab.id);
 		}
 		await executeScripts(tab.id, topScriptFiles, { allFrames: false });

+ 12 - 10
extension/ui/content/infobar.js

@@ -26,17 +26,19 @@ this.singlefile.infobar = this.singlefile.infobar || (() => {
 	const LINK_ICON = "<svg style=\"vertical-align: middle\" xmlns=\"http://www.w3.org/2000/svg\" width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"#9AA0A6\"><path d=\"M19 19H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z\"/></svg>";
 	const SINGLEFILE_COMMENT = "Archive processed by SingleFile";
 
-	document.addEventListener("DOMContentLoaded", async () => {
-		const singleFileComment = document.documentElement.childNodes[0];
-		if (singleFileComment.nodeType == Node.COMMENT_NODE && singleFileComment.textContent.includes(SINGLEFILE_COMMENT)) {
-			const info = singleFileComment.textContent.split("\n");
-			const [, , url, saveDate] = info;
-			const config = await browser.runtime.sendMessage({ getConfig: true });
-			if (config.displayInfobar) {
-				initInfobar(url, saveDate);
+	if (window == top) {
+		document.addEventListener("DOMContentLoaded", async () => {
+			const singleFileComment = document.documentElement.childNodes[0];
+			if (singleFileComment.nodeType == Node.COMMENT_NODE && singleFileComment.textContent.includes(SINGLEFILE_COMMENT)) {
+				const info = singleFileComment.textContent.split("\n");
+				const [, , url, saveDate] = info;
+				const config = await browser.runtime.sendMessage({ getConfig: true });
+				if (config.displayInfobar) {
+					initInfobar(url, saveDate);
+				}
 			}
-		}
-	});
+		});
+	}
 	return true;
 
 	function initInfobar(url, saveDate) {

+ 6 - 2
manifest.json

@@ -17,8 +17,12 @@
             "js": [
                 "lib/browser-polyfill/custom-browser-polyfill.js",
                 "extension/index.js",
-                "extension/ui/content/infobar.js"
-            ]
+                "extension/ui/content/infobar.js",
+                "lib/frame-tree/content/frame-tree.js",
+                "extension/core/content/content-frame.js"
+            ],
+            "all_frames": true,
+            "match_about_blank": true
         }
     ],
     "background": {