Handle Cloudflare Turnstile challenges in `main.py`
mainWhen using lmarenabridge, you may need to implement a Cloudflare/Turnstile pass-through logic within the get_recaptcha_v3_token function in main.py to bypass security challenges on https://arena.ai/.
To implement this:
- Ensure
AsyncCamoufoxis initialized withheadless=Falseandmain_world_eval=True. - Navigate to
https://arena.ai/usingdomcontentloadedwait state. - Implement a loop to check for the "Just a moment" page title or the presence of the Turnstile widget.
- Use the
click_turnstile(page)function to interact with the challenge if detected. - Remove any existing logic that specifically waits for the
arena-auth-prod-v1cookie, as the priority is passing the challenge to allow thegrecaptchalibrary to load.
# Step 1: Ensure browser initialization is set to non-headless
async with AsyncCamoufox(headless=False, main_world_eval=True) as browser:
# Step 2: Implement Challenge Logic inside get_recaptcha_v3_token
debug_print(" 🌐 Navigating to arena.ai...")
await page.goto("https://arena.ai/", wait_until="domcontentloaded")
# --- NEW: Cloudflare/Turnstile Pass-Through ---
debug_print(" 🛡️ Checking for Cloudflare Turnstile...")
try:
for _ in range(5):
title = await page.title()
if "Just a moment" in title:
debug_print(" 🔒 Cloudflare challenge active. Attempting to click...")
clicked = await click_turnstile(page)
if clicked:
debug_print(" ✅ Clicked Turnstile.")
await asyncio.sleep(3)
else:
await click_turnstile(page)
break
await asyncio.sleep(1)
await page.wait_for_load_state("domcontentloaded")
except Exception as e:
debug_print(f" ⚠️ Error handling Turnstile: {e}")
# ----------------------------------------------