fix(scraper): make browser fetcher robust to non-navigable urls and idle hangs#442
Open
evilhamsterman wants to merge 1 commit into
Open
fix(scraper): make browser fetcher robust to non-navigable urls and idle hangs#442evilhamsterman wants to merge 1 commit into
evilhamsterman wants to merge 1 commit into
Conversation
…dle hangs BrowserFetcher gated page.goto on "networkidle", but many sites (analytics, Cloudflare telemetry, websockets) never reach network idle, so navigation timed out after the full browser timeout even though the document was ready. Gate on "load" instead, then wait for networkidle only on a best-effort basis. Also handle resources the browser cannot navigate to (Markdown, JSON, plain text): page.goto rejects them with ERR_INVALID_ARGUMENT / ERR_ABORTED because the browser starts a download. These now fall back to the browser context's request API, which reuses cookies (so any anti-bot clearance carries over) but does not try to render the response. A still-blocked fallback surfaces as a retryable ScraperError rather than crashing the job. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #441.
Summary
Makes
BrowserFetcherrobust to the two failure modes described in #441:networkidle→load.page.gotonow gates on"load"and waits fornetworkidleonly on a best-effort basis (with a short timeout, swallowed on failure), matching whatHtmlPlaywrightMiddlewarealready does. Sites that never go network-idle (Cloudflare telemetry, analytics, websockets) no longer time out the navigation.page.gotorejects withERR_INVALID_ARGUMENT/ERR_ABORTED(Markdown/JSON/plain-text resources the browser tries to download), the fetcher loads the origin first (so any JS/anti-bot challenge is solved and clearance cookies are set on the context) and then retrieves the bytes viapage.request.get, which reuses those cookies but does not try to render the response. A still-blocked fetch surfaces as a retryableScraperErrorrather than crashing the job.Why
The
llms.txtfeature seeds Markdown (.md) URL variants at depth 0. Behind a Cloudflare Managed Challenge these get routed to the browser fallback, wherepage.gotoon a Markdown URL throwsERR_INVALID_ARGUMENT; since depth-0 failures are fatal inBaseScraperStrategy, one such seed aborts the whole scrape. Thenetworkidlegate independently caused navigation timeouts on the same class of sites.Changes
src/scraper/fetcher/BrowserFetcher.ts—loadgate + best-effort networkidle; newfetchViaRequest()fallback for non-navigable URLs.src/scraper/fetcher/BrowserFetcher.test.ts— refactored mocks into amockBrowser()helper; added tests for the request-API fallback (success path) and for a still-blocked fallback raising aScraperError.Testing
npx vitest run src/scraper/fetcher/BrowserFetcher.test.ts— passes (incl. new cases).npx tsc --noEmitandbiome check— clean.docs.vyos.io): the scrape that previously aborted in ~30s now completes the full tree with noERR_INVALID_ARGUMENTornetworkidletimeouts; pages that genuinely can't be cleared fail individually (non-fatal) instead of killing the job.Notes
The depth-0-seed-fatal behavior in
BaseScraperStrategy(any singlellms.txtseed failure aborting the whole job) is a related but separate issue; this PR makes the browser path degrade gracefully so it no longer triggers that path, but the underlying strategy behavior is left for a follow-up.