Просмотр исходного кода

fixed issue where some frames would not be saved

Gildas 7 лет назад
Родитель
Сommit
1514da1671

+ 0 - 1
cli/back-ends/jsdom.js

@@ -35,7 +35,6 @@ const SCRIPTS = [
 	"../../lib/frame-tree/content/content-frame-tree.js",
 	"../../lib/single-file/util/doc-util.js",
 	"../../lib/single-file/util/doc-helper.js",
-	"../../lib/single-file/util/timeout.js",
 	"../../lib/single-file/vendor/css-tree.js",
 	"../../lib/single-file/vendor/html-srcset-parser.js",
 	"../../lib/single-file/vendor/css-minifier.js",

+ 0 - 1
cli/back-ends/puppeteer.js

@@ -33,7 +33,6 @@ const SCRIPTS = [
 	"../../lib/lazy/content/content-lazy-loader.js",
 	"../../lib/single-file/util/doc-util.js",
 	"../../lib/single-file/util/doc-helper.js",
-	"../../lib/single-file/util/timeout.js",
 	"../../lib/single-file/vendor/css-tree.js",
 	"../../lib/single-file/vendor/html-srcset-parser.js",
 	"../../lib/single-file/vendor/css-minifier.js",

+ 0 - 1
cli/back-ends/webdriver-chromium.js

@@ -35,7 +35,6 @@ const SCRIPTS = [
 	"../../lib/lazy/content/content-lazy-loader.js",
 	"../../lib/single-file/util/doc-util.js",
 	"../../lib/single-file/util/doc-helper.js",
-	"../../lib/single-file/util/timeout.js",
 	"../../lib/single-file/vendor/css-tree.js",
 	"../../lib/single-file/vendor/html-srcset-parser.js",
 	"../../lib/single-file/vendor/css-minifier.js",

+ 0 - 1
cli/back-ends/webdriver-gecko.js

@@ -35,7 +35,6 @@ const SCRIPTS = [
 	"../../lib/lazy/content/content-lazy-loader.js",
 	"../../lib/single-file/util/doc-util.js",
 	"../../lib/single-file/util/doc-helper.js",
-	"../../lib/single-file/util/timeout.js",
 	"../../lib/single-file/vendor/css-tree.js",
 	"../../lib/single-file/vendor/html-srcset-parser.js",
 	"../../lib/single-file/vendor/css-minifier.js",

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

@@ -29,7 +29,6 @@ singlefile.core = (() => {
 		"/lib/browser-polyfill/chrome-browser-polyfill.js",
 		"/lib/single-file/vendor/css-tree.js",
 		"/lib/single-file/vendor/html-srcset-parser.js",
-		"/lib/single-file/util/timeout.js",
 		"/lib/single-file/util/doc-helper.js",
 		"/lib/single-file/util/doc-util.js",
 		"/lib/fetch/content/fetch.js",
@@ -45,7 +44,6 @@ singlefile.core = (() => {
 		"/lib/browser-polyfill/chrome-browser-polyfill.js",
 		"/extension/index.js",
 		"/lib/single-file/util/doc-helper.js",
-		"/lib/single-file/util/timeout.js",
 		"/lib/fetch/content/fetch.js",
 		"/lib/frame-tree/content/content-frame-tree.js",
 		"/extension/core/content/content-frame.js"

+ 2 - 2
extension/core/content/content.js

@@ -18,7 +18,7 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global browser, SingleFileBrowser, singlefile, frameTree, document, Blob, MouseEvent, addEventListener, window, lazyLoader, URL, timeout */
+/* global browser, SingleFileBrowser, singlefile, frameTree, document, Blob, MouseEvent, addEventListener, window, lazyLoader, URL, setTimeout */
 
 this.singlefile.top = this.singlefile.top || (() => {
 
@@ -76,7 +76,7 @@ this.singlefile.top = this.singlefile.top || (() => {
 			if (!options.removeFrames && this.frameTree) {
 				let frameTreePromise;
 				if (options.loadDeferredImages) {
-					frameTreePromise = new Promise(resolve => timeout.set(() => resolve(frameTree.getAsync(options)), options.loadDeferredImagesMaxIdleTime - frameTree.TIMEOUT_INIT_REQUEST_MESSAGE));
+					frameTreePromise = new Promise(resolve => setTimeout(() => resolve(frameTree.getAsync(options)), options.loadDeferredImagesMaxIdleTime - frameTree.TIMEOUT_INIT_REQUEST_MESSAGE));
 				} else {
 					frameTreePromise = frameTree.getAsync(options);
 				}

+ 5 - 65
lib/frame-tree/content/content-frame-tree.js

@@ -18,7 +18,7 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global window, top, document, addEventListener, docHelper, timeout, MessageChannel, superFetch, fetch, TextDecoder, DOMParser, lazyLoader, setTimeout, browser */
+/* global window, top, document, addEventListener, docHelper, MessageChannel, lazyLoader, browser, setTimeout */
 
 this.frameTree = this.frameTree || (() => {
 
@@ -29,7 +29,6 @@ this.frameTree = this.frameTree || (() => {
 	const INIT_RESPONSE_MESSAGE = "initResponse";
 	const TARGET_ORIGIN = "*";
 	const TIMEOUT_INIT_REQUEST_MESSAGE = 750;
-	const PREFIX_VALID_FRAME_URL = /^https?:\/\//;
 	const TOP_WINDOW_ID = "0";
 	const WINDOW_ID_SEPARATOR = ".";
 	const TOP_WINDOW = window == top;
@@ -93,12 +92,13 @@ this.frameTree = this.frameTree || (() => {
 
 	function initRequest(message) {
 		const sessionId = message.sessionId;
-		const frameElements = document.querySelectorAll(FRAMES_CSS_SELECTOR);
 		if (!TOP_WINDOW) {
 			windowId = message.windowId;
+		}
+		processFrames(document.querySelectorAll(FRAMES_CSS_SELECTOR), message.options, windowId, sessionId);
+		if (!TOP_WINDOW) {
 			sendInitResponse({ framesData: [getFrameData(document, window, windowId, message.options)], sessionId });
 		}
-		processFrames(frameElements, message.options, windowId, sessionId);
 	}
 
 	function cleanupRequest(message) {
@@ -163,16 +163,7 @@ this.frameTree = this.frameTree || (() => {
 				/* ignored */
 			}
 			setTimeout(async () => {
-				let frameDoc;
-				if (frameElement.src && frameElement.src.match(PREFIX_VALID_FRAME_URL)) {
-					frameDoc = await getFrameDoc(frameElement.src, parentWindowId);
-				}
-				if (frameDoc) {
-					sendInitResponse({ framesData: [getFrameData(frameDoc, null, windowId, options)] });
-					timeout.set(() => sendInitResponse({ framesData: [{ windowId, processed: true }], sessionId }));
-				} else {
-					sendInitResponse({ framesData: [{ windowId, processed: true }], sessionId });
-				}
+				sendInitResponse({ framesData: [{ windowId, processed: true }], sessionId });
 			}, TIMEOUT_INIT_REQUEST_MESSAGE);
 		});
 		sendInitResponse({ framesData, sessionId });
@@ -252,57 +243,6 @@ this.frameTree = this.frameTree || (() => {
 		}
 	}
 
-	async function getFrameDoc(frameUrl, parentWindowId) {
-		let frameContent;
-		try {
-			frameContent = await ((typeof superFetch !== "undefined" && superFetch.fetch) || fetch)(frameUrl);
-		} catch (error) {
-			/* ignored */
-		}
-		if (frameContent && frameContent.status >= 400 && superFetch.hostFetch) {
-			try {
-				frameContent = await superFetch.hostFetch(frameUrl);
-			} catch (error) {
-				/* ignored */
-			}
-		}
-		if (frameContent) {
-			const contentType = frameContent.headers && frameContent.headers.get("content-type");
-			let charset, mimeType;
-			if (contentType) {
-				const matchContentType = contentType.toLowerCase().split(";");
-				mimeType = matchContentType[0].trim();
-				if (!mimeType.includes("/")) {
-					mimeType = "text/html";
-				}
-				const charsetValue = matchContentType[1] && matchContentType[1].trim();
-				if (charsetValue) {
-					const matchCharset = charsetValue.match(/^charset=(.*)/);
-					if (matchCharset) {
-						charset = docHelper.removeQuotes(matchCharset[1]);
-					}
-				}
-			}
-			let doc;
-			try {
-				const buffer = await frameContent.arrayBuffer();
-				const content = (new TextDecoder(charset)).decode(buffer);
-				const domParser = new DOMParser();
-				doc = domParser.parseFromString(content, mimeType);
-			} catch (error) {
-				/* ignored */
-			}
-			if (doc) {
-				const frameElements = doc.documentElement.querySelectorAll(FRAMES_CSS_SELECTOR);
-				frameElements.forEach((frameElement, frameIndex) => {
-					const windowId = parentWindowId + WINDOW_ID_SEPARATOR + frameIndex;
-					frameElement.setAttribute(docHelper.WIN_ID_ATTRIBUTE_NAME, windowId);
-				});
-				return doc;
-			}
-		}
-	}
-
 	function getFrameData(document, window, windowId, options) {
 		const docData = docHelper.preProcessDoc(document, window, options);
 		const content = docHelper.serialize(document);

+ 0 - 56
lib/single-file/util/timeout.js

@@ -1,56 +0,0 @@
-/*
- * Copyright 2010-2019 Gildas Lormeau
- * contact : gildas.lormeau <at> gmail.com
- * 
- * This file is part of SingleFile.
- *
- *   SingleFile is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU Lesser General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
- *
- *   SingleFile 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 Lesser General Public License for more details.
- *
- *   You should have received a copy of the GNU Lesser General Public License
- *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* global setTimeout, clearTimeout */
-
-this.timeout = this.timeout || (() => {
-
-	const TIMEOUT_STEP = 100;
-
-	const timeoutIds = [];
-
-	return {
-		set(fn, delay) {
-			const id = timeoutIds.length;
-			let elapsedTime = 0;
-			timeoutIds[id] = setTimeout(step, 0);
-			return id;
-
-			function step() {
-				if (elapsedTime < delay) {
-					timeoutIds[id] = setTimeout(() => {
-						elapsedTime += TIMEOUT_STEP;
-						step();
-					}, TIMEOUT_STEP);
-				}
-				else {
-					fn();
-				}
-			}
-		},
-		clear(id) {
-			if (timeoutIds[id]) {
-				clearTimeout(timeoutIds[id]);
-				timeoutIds[id] = null;
-			}
-		}
-	};
-
-})();

+ 0 - 1
maff2html/back-ends/webdriver-gecko.js

@@ -35,7 +35,6 @@ const SCRIPTS = [
 	"../../lib/lazy/content/content-lazy-loader.js",
 	"../../lib/single-file/util/doc-util.js",
 	"../../lib/single-file/util/doc-helper.js",
-	"../../lib/single-file/util/timeout.js",
 	"../../lib/single-file/vendor/css-tree.js",
 	"../../lib/single-file/vendor/html-srcset-parser.js",
 	"../../lib/single-file/vendor/css-minifier.js",

+ 0 - 1
manifest.json

@@ -21,7 +21,6 @@
 				"lib/browser-polyfill/chrome-browser-polyfill.js",
 				"lib/single-file/util/doc-helper.js",
 				"lib/single-file/util/doc-util.js",
-				"lib/single-file/util/timeout.js",
 				"lib/frame-tree/content/content-frame-tree.js",
 				"extension/index.js",
 				"extension/core/content/content-frame.js"