فهرست منبع

added "browser-load-max-time" option

Gildas 7 سال پیش
والد
کامیت
0307810550
2فایلهای تغییر یافته به همراه8 افزوده شده و 6 حذف شده
  1. 2 3
      maff2html/back-ends/webdriver-gecko.js
  2. 6 3
      maff2html/single-file

+ 2 - 3
maff2html/back-ends/webdriver-gecko.js

@@ -51,7 +51,6 @@ const SCRIPTS = [
 	"../../lib/single-file/single-file-core.js",
 	"../../lib/single-file/single-file-browser.js"
 ];
-const NETWORK_IDLE_MAX_DELAY = 60000;
 
 exports.getPageData = async options => {
 	const RESOLVED_CONTENTS = {
@@ -89,7 +88,7 @@ exports.getPageData = async options => {
 		firefoxOptions.setProfile(profile);
 		builder.setFirefoxOptions(firefoxOptions);
 		driver = await builder.forBrowser("firefox").build();
-		driver.manage().setTimeouts({ script: 2 * NETWORK_IDLE_MAX_DELAY, pageLoad: 2 * NETWORK_IDLE_MAX_DELAY, implicit: 2 * NETWORK_IDLE_MAX_DELAY });
+		driver.manage().setTimeouts({ script: options.browserLoadMaxTime, pageLoad: options.browserLoadMaxTime, implicit: options.browserLoadMaxTime });
 		if (options.browserWidth && options.browserHeight) {
 			const window = driver.manage().window();
 			if (window.setRect) {
@@ -113,7 +112,7 @@ exports.getPageData = async options => {
 			}
 			let cancelTimeout;
 			const timeoutPromise = new Promise(resolve => {
-				const timeoutId = setTimeout(resolve, NETWORK_IDLE_MAX_DELAY);
+				const timeoutId = setTimeout(resolve, Math.max(0, options.browserLoadMaxTime - 5000));
 				cancelTimeout = () => {
 					clearTimeout(timeoutId);
 					resolve();

+ 6 - 3
maff2html/single-file

@@ -36,6 +36,7 @@ const args = require("yargs")
 		"browser-executable-path": "",
 		"browser-width": 1280,
 		"browser-height": 720,
+		"browser-load-max-time": 60000,
 		"browser-wait-until": "load",
 		"compress-CSS": true,
 		"compress-HTML": true,
@@ -66,6 +67,8 @@ const args = require("yargs")
 	.number("browser-width")
 	.options("browser-height", { description: "Height of the browser viewport in pixels" })
 	.number("browser-height")
+	.options("browser-load-max-time", { description: "Maximum delay of time to wait for page loading (in ms)" })
+	.number("browser-load-max-time")
 	.options("browser-wait-until", { description: "When to consider the page is loaded" })
 	.choices("browser-wait-until", ["networkidle0", "networkidle2", "load", "domcontentloaded"])
 	.options("compress-CSS", { description: "Compress CSS stylesheets" })
@@ -78,11 +81,11 @@ const args = require("yargs")
 	.boolean("group-duplicate-images")
 	.options("load-deferred-images", { description: "Load deferred (a.k.a. lazy-loaded) images" })
 	.boolean("load-deferred-images")
-	.options("load-deferred-images-max-idle-time", { description: "Maximum delay of time to wait for deferred images" })
-	.number("load-deferred-images-max-idle-time")
+	.options("load-deferred-images-max-idle-time", { description: "Maximum delay of time to wait for deferred images (in ms)" })
+	.number("load-deferred-images-max-idle-time")	
 	.options("max-resource-size-enabled", { description: "Enable removal of embedded resources exceeding a given size" })
 	.boolean("max-resource-size-enabled")
-	.options("max-resource-size", { description: "Maximum size of embedded resources (i.e. images, stylesheets, scripts and iframes)" })
+	.options("max-resource-size", { description: "Maximum size of embedded resources (i.e. images, stylesheets, scripts and iframes) (in MB)" })
 	.number("max-resource-size")
 	.options("remove-frames", { description: "Remove frames (puppeteer, webdriver-gecko, webdriver-chromium)" })
 	.boolean("remove-frames")