fix(examples): wait for reCAPTCHA score to render before screenshot (#374)

networkidle raced the async scoring and the dead button-click never ran.
Wait on the rendered result instead. Verified 4/4 in Docker.
This commit is contained in:
CloakHQ
2026-06-15 17:58:50 +02:00
parent b06499b0c1
commit 39db492b04
+12 -11
View File
@@ -5,7 +5,7 @@ Expected: 0.9 (human-level) with cloakbrowser.
Default Playwright typically scores 0.1-0.3.
"""
import time
import re
from cloakbrowser import launch
@@ -13,19 +13,20 @@ print("Launching stealth browser...", flush=True)
browser = launch(headless=True)
page = browser.new_page()
# Google's official reCAPTCHA v3 demo
# Google's official reCAPTCHA v3 demo — scores automatically on page load.
page.goto("https://recaptcha-demo.appspot.com/recaptcha-v3-request-scores.php")
page.wait_for_load_state("networkidle")
# Click to trigger reCAPTCHA scoring
button = page.query_selector("button")
if button:
button.click()
time.sleep(3)
# The score renders only after an async token + backend-verify round-trip,
# which can finish *after* "networkidle". Wait for the actual result text
# instead of a proxy signal, or the screenshot races the scoring.
page.wait_for_function(
"() => document.body.innerText.includes('Received response from our backend')",
timeout=20000,
)
# Extract score from page
content = page.content()
print("Page loaded. Check the score in the response.")
# Extract score from the rendered response
match = re.search(r'"score":\s*([0-9.]+)', page.inner_text("body"))
print(f"reCAPTCHA v3 score: {match.group(1) if match else 'not found'}")
print(f"URL: {page.url}")
# Take screenshot as proof