From c565351c2f87094a30906d30c3821c4eb23d1fef Mon Sep 17 00:00:00 2001 From: openhands Date: Tue, 4 Aug 2026 18:17:20 +0200 Subject: [PATCH] fix: improve CF challenge detection and add timeout in cf-fetch --- src/lib/services/cf-fetch.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib/services/cf-fetch.ts b/src/lib/services/cf-fetch.ts index 96fbeb88..787c2381 100644 --- a/src/lib/services/cf-fetch.ts +++ b/src/lib/services/cf-fetch.ts @@ -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 {