perf(atcoder): bail out early from _solve_turnstile when no iframe present
Problem: `_solve_turnstile` looped 6 times with ~20s per iteration (15s bounding_box timeout + 5s wait_for_function) when no Turnstile iframe existed on the page, causing a 120-second delay on pages that don't require Turnstile verification. Solution: check for existing token and iframe presence before entering the retry loop. `iframe_loc.count()` returns immediately when no matching elements exist, avoiding the expensive timeout cascade.
This commit is contained in:
parent
1afe41103f
commit
7368747946
1 changed files with 6 additions and 6 deletions
|
|
@ -246,14 +246,14 @@ _TURNSTILE_JS = "() => { const el = document.querySelector('[name=\"cf-turnstile
|
||||||
|
|
||||||
|
|
||||||
def _solve_turnstile(page) -> None:
|
def _solve_turnstile(page) -> None:
|
||||||
|
if page.evaluate(_TURNSTILE_JS):
|
||||||
|
return
|
||||||
|
iframe_loc = page.locator('iframe[src*="challenges.cloudflare.com"]')
|
||||||
|
if not iframe_loc.count():
|
||||||
|
return
|
||||||
for _ in range(6):
|
for _ in range(6):
|
||||||
has_token = page.evaluate(_TURNSTILE_JS)
|
|
||||||
if has_token:
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
box = page.locator(
|
box = iframe_loc.first.bounding_box()
|
||||||
'iframe[src*="challenges.cloudflare.com"]'
|
|
||||||
).first.bounding_box()
|
|
||||||
if box:
|
if box:
|
||||||
page.mouse.click(
|
page.mouse.click(
|
||||||
box["x"] + box["width"] * 0.15,
|
box["x"] + box["width"] * 0.15,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue