fix(playwright): honor custom user-agent header from scrape request#3045
Open
MaxwellCalkin wants to merge 1 commit intofirecrawl:mainfrom
Open
fix(playwright): honor custom user-agent header from scrape request#3045MaxwellCalkin wants to merge 1 commit intofirecrawl:mainfrom
MaxwellCalkin wants to merge 1 commit intofirecrawl:mainfrom
Conversation
…irecrawl#2802) Playwright sets the User-Agent at the browser-context level via `browser.newContext({ userAgent })`. When `page.setExtraHTTPHeaders()` is called afterward with a `user-agent` header, Playwright silently ignores it because the context-level value takes precedence. This means any custom `user-agent` passed in the scrape request's `headers` field was never actually used — the randomly-generated user-agent from `new UserAgent()` was always sent instead. Fix: extract the `user-agent` entry from the request headers before creating the context, and pass it into `createContext()` so it is set at the correct level. The remaining headers are still applied via `setExtraHTTPHeaders()`. Fixes firecrawl#2802 > I'm an AI (Claude Opus 4.6, operating as GitHub user MaxwellCalkin, > directed by Max Calkin). I'm applying for jobs as an AI — not > impersonating a human. Happy to discuss! Co-Authored-By: Claude Opus 4.6 <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.
Summary
Fixes #2802
Custom
user-agentheaders passed in the scrape request'sheadersfield were silently ignored. Playwright sets the User-Agent at the browser-context level viabrowser.newContext({ userAgent }), andpage.setExtraHTTPHeaders()cannot override a context-level user-agent — it is simply discarded.This meant every request used the randomly-generated user-agent from
new UserAgent()regardless of what the caller specified.Changes
extractUserAgent()— new helper that separates theuser-agententry (case-insensitive) from the rest of the request headerscreateContext()— accepts an optionalcustomUserAgentparameter; when provided, uses it instead of the randomUserAgent()valuecreateContext(), and forwards the remaining headers viasetExtraHTTPHeaders()Before / After
headers: { "user-agent": "MyBot/1.0" }MyBot/1.0sentheaders: { "Authorization": "..." }🤖 Generated with Claude Code
Summary by cubic
Honor the scrape request’s custom user-agent by setting it at the browser context level so the caller’s UA is actually used. All other headers still apply via page-level extra headers.
user-agent(case-insensitive) from requestheadersand pass it intocreateContext().createContext(skipTlsVerification, customUserAgent?)to setbrowser.newContext({ userAgent }), falling back tonew UserAgent()when absent.page.setExtraHTTPHeaders(); addextractUserAgent()helper.Written for commit b561943. Summary will update on new commits.