v4: respectRobotsTxtFile fetches robots.txt with a bare FetchHttpClient
With respectRobotsTxtFile, BasicCrawler calls RobotsTxtFile.find(url, { logger }) (packages/basic-crawler/src/internals/basic-crawler.ts), and find() defaults to new FetchHttpClient() (packages/utils/src/internals/robots.ts). The robots.txt request therefore bypasses the crawler's configured httpClient, proxy configuration and impersonation, so a site that only answers through the proxy, or that blocks plain fetch, gets a wrong or failed robots result while the crawl itself goes through the proxy.
find() already accepts httpClient and proxyUrl, so the fix is probably to pass the crawler's client and a proxy URL from the session. Decide whether that should land before GA.
[🤖] Claude Code using Fable 5.1
Confirmed on current master (checked today):
basic-crawler.tscallsRobotsTxtFile.find(url, { logger: this.log })(~line 2559) — the crawler's ownhttpClientand the session's proxy URL are not passed.robots.ts#loadthen defaults tohttpClient = new FetchHttpClient().
So with respectRobotsTxtFile: true, the robots.txt request goes out as a plain fetch — no configured proxy, no browser impersonation, no custom headers. For a target that only answers through the configured proxy (or that blocks fetch-style TLS fingerprints), robots resolution fails or returns the wrong result while the crawl itself goes through the proxy. RFC 9309 semantics make this worse downstream: an unreachable (5xx) robots.txt disallows everything, so a proxy-blocked robots fetch can silently stall the whole crawl.
Suggested fix shape: thread the crawler's httpClient plus a proxy URL resolved from proxyConfiguration (via the context/session, same as page requests) into find(). find() already accepts both parameters, so the code surface is small. The one real design decision is which proxy to use when the robots check runs before a session is assigned — first proxy from the tier-0 list, or an explicit session-less "no proxy" fallback. Worth deciding explicitly either way.
On the GA question: I'd lean toward landing it before GA. Enabling respectRobotsTxtFile on a proxy-only target is broken and silent today, which is the kind of behavioral contract v4 should not ship on.
Happy to open a PR with a regression test (mock httpClient asserting the robots fetch goes through the configured client + proxy) if this gets picked up.
pass the crawler's client and a proxy URL (to the
RobotsTxtFile.findcall)
Yes, that sounds reasonable to me. I believe the original reasoning was "we don't need proxies / special HTTP clients for robots.txt" (which I still stand behind), but the crawler instance should likely use just one "fingerprint" if possible (be it at the robots.txt endpoint or anywhere else).
The FetchHttpClient client should still be the default one, as we don't want large dependencies in the @crawlee/utils package.
Agreed on both counts — keeping `FetchHttpClient` as the `@crawlee/utils` default (no new deps) and having `BasicCrawler` pass its own `httpClient` + the session proxy URL into `RobotsTxtFile.find` is the minimal shape of the single-fingerprint principle.
One nuance worth a doc note: the robots result cache is keyed per origin, so once the request goes through the crawler client, cached responses are shared across sessions that may have different proxy exit IPs. For robots.txt that is almost certainly fine (content is not session-specific), but it makes "who fetched the cached entry" a fingerprint-history question, same as the issue title frames it.
Happy to open a PR for the `basic-crawler.ts` call-site change (pass `this.httpClient` + `proxyConfiguration.newProxyUrl(sessionId)`, defaulting untouched) if that helps before GA.
#4218 (opened on Oct 6 for #4180) does this. BasicCrawler passes its own httpClient to RobotsTxtFile.find() together with a session from the crawler's session pool, so robots.txt is fetched with the same fingerprint and proxy as the pages. FetchHttpClient stays the default in @crawlee/utils. I've just pushed the proxy part and brought it up to date with master.
Good — that matches what I saw in the trace: the fix belongs in BasicCrawler passing its own client + session to RobotsTxtFile.find(), with FetchHttpClient staying the default in @crawlee/utils for callers outside a crawler. Since you've now pushed the proxy part and rebased: once CI is green I can run the robots-txt-behind-proxy scenario from my side (the case that surfaced this: a proxy that terminates the fetch fine, where a bare client leaks the real fingerprint on the robots fetch) and report back here with the result. If #4218 lands, I'd suggest closing this against it so the canonical fix has one home.
Thanks! CI on #4218 is green now, so a run of the behind-proxy scenario would be great.
Ran the behind-proxy scenario against #4218 (a66efa0) with a local origin + a local terminating proxy:
- origin:
/robots.txtanswers403("blocked to bare clients" — the bot-protection stand-in),/answers200. - proxy: terminates all traffic; answers
/robots.txtwith a real200 User-agent: * Disallow: /secret.
Result on the PR branch: the proxy records the robots.txt fetch (it went through the crawler's httpClient + session proxy), the origin receives no direct robots request, and the crawl proceeds against the proxy's robots answer. 1/1 request succeeded.
Same test on master (04ffaba): fails exactly as reported — robotsViaProxy=false, the robots fetch bypasses the proxy and hits the origin bare, where the 403 decides the verdict. So the assertion has teeth in both directions, and the fix on #4218 is what flips it.
Minimal repro (express origin/proxy + BasicCrawler with proxyConfiguration + respectRobotsTxtFile: true, vitest) — happy to drop it into the PR as a regression test if useful, or you can fold it into your existing robots tests.
Thanks for running it! #4218 already has a regression test for the proxy (fetches robots.txt through the proxy of a crawler session), so I'd keep it there.
Makes sense — the regression test in #4218 covers it, no need to duplicate. Consider my run a second confirmation from the behind-proxy side; nothing further from me here.