From 52a775dbd3daf86ef34affabf7c27a5a13bd8efc Mon Sep 17 00:00:00 2001 From: Emilien Devos Date: Sat, 2 Oct 2021 16:02:25 +0200 Subject: handle the case where there is an instant response from cloudflare --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a266cd6..98dd889 100644 --- a/index.js +++ b/index.js @@ -81,12 +81,13 @@ const responseHeadersToRemove = ["Accept-Ranges", "Content-Length", "Keep-Alive" responseBody = await response.text(); responseData = await response.buffer(); while (responseBody.includes("cf-browser-verification") && tryCount <= 10) { - response = await page.waitForNavigation({ timeout: 30000, waitUntil: 'domcontentloaded' }); + newResponse = await page.waitForNavigation({ timeout: 30000, waitUntil: 'domcontentloaded' }); + if (newResponse) response = newResponse; responseBody = await response.text(); responseData = await response.buffer(); tryCount++; } - responseHeaders = response.headers(); + responseHeaders = await response.headers(); const cookies = await page.cookies(); if (cookies) cookies.forEach(cookie => { -- cgit v1.2.3