summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilien Devos <contact@emiliendevos.be>2020-06-07 15:33:37 +0200
committerEmilien Devos <contact@emiliendevos.be>2020-06-07 15:33:37 +0200
commitfe804f5b34c9b9289131b110877ca55cb5b38c93 (patch)
treeebda22854f19e5d92a5d425822de37f5d2caf7ca
parent1e6136e05ae923f25922f034a0c70074f45875c0 (diff)
retry if the verification page is presented again
-rw-r--r--index.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/index.js b/index.js
index c8661cd..3670639 100644
--- a/index.js
+++ b/index.js
@@ -15,7 +15,7 @@ const responseHeadersToRemove = ["Accept-Ranges", "Content-Length", "Keep-Alive"
(async () => {
let options = {
- headless: true,
+ headless: false,
args: ['--no-sandbox', '--disable-setuid-sandbox']
};
if (process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD)
@@ -71,10 +71,14 @@ const responseHeadersToRemove = ["Accept-Ranges", "Content-Length", "Keep-Alive"
await page.setExtraHTTPHeaders(headers);
try {
let response;
+ let tryCount = 0;
response = await page.goto(url, { timeout: 30000, waitUntil: 'domcontentloaded' });
- if ((await page.content()).includes("cf-browser-verification"))
- response = await page.waitForNavigation({ timeout: 30000, waitUntil: 'domcontentloaded' });
responseBody = await response.text();
+ while (responseBody.includes("cf-browser-verification") && tryCount <= 10) {
+ response = await page.waitForNavigation({ timeout: 30000, waitUntil: 'domcontentloaded' });
+ responseBody = await response.text();
+ tryCount++;
+ }
responseHeaders = response.headers();
const cookies = await page.cookies();
if (cookies)