browser: lift resource blocking once a challenge is detected (verification loads images/fonts)
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 changed file +5 −1
modified
packages/browser/src/index.ts
+5 −1
@@ -342,6 +342,9 @@ export class BrowserPool { | ||
| 342 | 342 | let redirects = 0; |
| 343 | 343 | let policyError: FetchaError | null = null; |
| 344 | 344 | let firstNav = true; |
| 345 | + // Resource blocking is lifted as soon as a challenge is detected: anti-bot scripts verify that | |
| 346 | + // images/fonts actually load (measured: solved tokens were rejected with blocking on). | |
| 347 | + let blockResources = req.blockResources; | |
| 345 | 348 | |
| 346 | 349 | const page = await context.newPage(); |
| 347 | 350 | page.setDefaultTimeout(Math.min(req.timeoutMs, 60_000)); |
@@ -383,7 +386,7 @@ export class BrowserPool { | ||
| 383 | 386 | // fallback() (not continue()) lets Patchright's context-level route inject the init scripts. |
| 384 | 387 | return route.fallback(); |
| 385 | 388 | } |
| 386 | − if (req.blockResources) { | |
| 389 | + if (blockResources) { | |
| 387 | 390 | const type = r.resourceType(); |
| 388 | 391 | if (type === "image" || type === "media" || type === "font" || type === "manifest" || type === "texttrack") return route.abort("blockedbyclient"); |
| 389 | 392 | } |
@@ -440,6 +443,7 @@ export class BrowserPool { | ||
| 440 | 443 | let html = await page.content().catch(() => ""); |
| 441 | 444 | let verdict = looksBlocked(status, html, headers); |
| 442 | 445 | if (verdict.blocked && verdict.challenge !== false && req.javascript) { |
| 446 | + blockResources = false; | |
| 443 | 447 | const challengeStatus = status; |
| 444 | 448 | const solverAllowed = Boolean(this.solver) && req.solveCaptcha !== false; |
| 445 | 449 | const loopStart = performance.now(); |
| 446 | 450 | |