From fc4a809985dde28e7fec88f03a9f74adab130e91 Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Mon, 27 Oct 2025 05:13:12 +0300 Subject: [PATCH] fix(cloudflare): Limit the waiting period for websites that captcha doesn't disappear after solving Also solves #100 --- scrapling/engines/_browsers/_camoufox.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scrapling/engines/_browsers/_camoufox.py b/scrapling/engines/_browsers/_camoufox.py index c0b2f2c..4ac0558 100644 --- a/scrapling/engines/_browsers/_camoufox.py +++ b/scrapling/engines/_browsers/_camoufox.py @@ -231,9 +231,14 @@ class StealthySession(StealthySessionMixin, SyncSession): page.mouse.click(captcha_x, captcha_y, delay=60, button="left") self._wait_for_networkidle(page) if iframe is not None: - # Wait for the frame to be removed from the page + # Wait for the frame to be removed from the page (with 30s timeout = 300 iterations * 100 ms) + attempts = 0 while iframe in page.frames: + if attempts >= 300: + log.info("Cloudflare iframe didn't disappear after 30s, continuing...") + break page.wait_for_timeout(100) + attempts += 1 if challenge_type != "embedded": page.locator(box_selector).last.wait_for(state="detached") page.locator(".zone-name-title").wait_for(state="hidden") @@ -513,9 +518,14 @@ class AsyncStealthySession(StealthySessionMixin, AsyncSession): await page.mouse.click(captcha_x, captcha_y, delay=60, button="left") await self._wait_for_networkidle(page) if iframe is not None: - # Wait for the frame to be removed from the page + # Wait for the frame to be removed from the page (with 30s timeout = 300 iterations * 100 ms) + attempts = 0 while iframe in page.frames: + if attempts >= 300: + log.info("Cloudflare iframe didn't disappear after 30s, continuing...") + break await page.wait_for_timeout(100) + attempts += 1 if challenge_type != "embedded": await page.locator(box_selector).wait_for(state="detached") await page.locator(".zone-name-title").wait_for(state="hidden")