diff options
author | Emilien Devos <contact@emiliendevos.be> | 2020-06-07 15:33:37 +0200 |
---|---|---|
committer | Emilien Devos <contact@emiliendevos.be> | 2020-06-07 15:33:37 +0200 |
commit | fe804f5b34c9b9289131b110877ca55cb5b38c93 (patch) | |
tree | ebda22854f19e5d92a5d425822de37f5d2caf7ca | |
parent | 1e6136e05ae923f25922f034a0c70074f45875c0 (diff) |
retry if the verification page is presented again
-rw-r--r-- | index.js | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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) |