Explorar o código

removed max js redirects and use waitForNavigation instead

Former-commit-id: f6efdc97bb8e803299cd7b3cc04abd58a2d17de8
Gildas %!s(int64=6) %!d(string=hai) anos
pai
achega
15f9d12c66
Modificáronse 1 ficheiros con 5 adicións e 10 borrados
  1. 5 10
      cli/back-ends/puppeteer.js

+ 5 - 10
cli/back-ends/puppeteer.js

@@ -52,10 +52,6 @@ const SCRIPTS = [
 	"../../lib/single-file/single-file.js"
 ];
 
-const MAX_JS_REDIRECTS = 100;
-
-let jsRedirects = 0;
-
 exports.getPageData = async options => {
 	const browserOptions = {};
 	if (options.browserHeadless !== undefined) {
@@ -131,18 +127,17 @@ exports.getPageData = async options => {
 			if (error.message.includes("Execution context was destroyed")) {
 				const pages = await browser.pages();
 				const page = pages[1] || pages[0];
+				await page.waitForNavigation(options.url, {
+					timeout: 0,
+					waitUntil: options.browserWaitUntil || "networkidle0"
+				});
 				const url = page.url();
 				await browser.close();
 				if (url != options.url) {
 					options.url = url;
 					return exports.getPageData(options);
 				} else {
-					jsRedirects++;
-					if (jsRedirects < MAX_JS_REDIRECTS) {
-						return exports.getPageData(options);
-					} else {
-						throw error;
-					}
+					throw error;
 				}
 			} else {
 				throw error;