fix: set default viewport for NewBrowser and align User-Agent with engine
All checks were successful
CI / vet (pull_request) Successful in 1m6s
CI / build (pull_request) Successful in 1m11s
CI / test (pull_request) Successful in 1m11s

NewBrowser previously had no viewport (strong headless signal) and used a
Firefox User-Agent unconditionally, even for Chromium instances (detectable
mismatch).

Add per-engine UA constants (DefaultFirefoxUserAgent, DefaultChromiumUserAgent)
and auto-select the matching UA in initBrowser when the caller hasn't set one
explicitly. Keep DefaultUserAgent as a backward-compatible alias.

Add 1920x1080 default viewport to NewBrowser (most common desktop resolution).
NewInteractiveBrowser keeps its existing 1280x720 default but also gains
engine-aware UA selection.

Closes #70

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 01:28:09 +00:00
parent ff1d6c491a
commit 6647e4f63d
4 changed files with 94 additions and 11 deletions

View File

@@ -52,6 +52,16 @@ func initBrowser(opt BrowserOptions) (*browserInitResult, error) {
return nil, ErrInvalidBrowserSelection
}
// Auto-select a User-Agent matching the browser engine when the caller hasn't set one.
if opt.UserAgent == "" {
switch opt.Browser {
case BrowserChromium:
opt.UserAgent = DefaultChromiumUserAgent
default:
opt.UserAgent = DefaultFirefoxUserAgent
}
}
// Collect launch args and init scripts, starting with any stealth-mode presets.
stealth := opt.Stealth == nil || *opt.Stealth
var launchArgs []string