fix: improve CF challenge detection and add timeout in cf-fetch
This commit is contained in:
1 parent
847febbe64
commit
c565351c2f
1 file changed
+12
-7
@@ -49,15 +49,20 @@ export async function fetchWithCfBypass(
|
||||
status === 403;
|
||||
|
||||
if (isCfChallenge) {
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
!document.body.innerHTML.includes("Attention Required") &&
|
||||
!document.body.innerHTML.includes("Checking your browser") &&
|
||||
!document.body.innerHTML.includes("Just a moment"),
|
||||
{ timeout: 10000 },
|
||||
);
|
||||
try {
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.body.innerHTML.includes("cf-captcha") ||
|
||||
document.body.innerHTML.includes("challenge-platform"),
|
||||
{ timeout: 5000 },
|
||||
);
|
||||
} catch {
|
||||
// CF challenge might have been solved already
|
||||
}
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
|
||||
const finalBody = await page.content();
|
||||
return finalBody;
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user