Set default viewport for NewBrowser and align User-Agent with browser engine #70
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parent Epic: #68
Problem
Missing viewport in
NewBrowserNewInteractiveBrowsersetsViewportSize: &playwright.Size{Width: 1280, Height: 720}, butNewBrowsersets no viewport at all. A missing viewport is a strong headless signal — real browsers always have a viewport. Many anti-bot systems check for this.User-Agent / browser engine mismatch
The codebase defines
defaultFirefoxUserAgentand uses it as a fallback, but there's no equivalent Chromium UA constant. When a caller usesBrowserChromiumwithout explicitly setting a UA, the browser may end up with:HeadlessChrome)Either case is a detectable mismatch.
Proposed Solution
Viewport
Add a default viewport to
NewBrowserwhen none is provided:Use 1920x1080 as the default (most common desktop resolution globally).
User-Agent alignment
defaultChromiumUserAgentconstant alongside the existing Firefox oneNewBrowser/ browser init, auto-select the matching UA based onopt.Browserwhen the caller hasn't explicitly setopt.UserAgentHeadlessChromefrom the UA only runs on ChromiumFiles to Modify
playwright.go— add default viewport logic, add Chromium UA constantbrowser_init.go— auto-select UA based on browser enginestealth_test.go— test viewport defaults and UA selectionReferences
Starting implementation. Plan:
1. Per-engine UA constants (
playwright.go)DefaultFirefoxUserAgent(existing value) andDefaultChromiumUserAgent(Chrome/131 Windows 10 UA)DefaultUserAgent = DefaultFirefoxUserAgentas backward-compatible aliasUserAgent: DefaultUserAgentfromNewBrowserbase defaults soinitBrowsercan auto-select2. Default viewport (
playwright.go)Dimensions: Size{Width: 1920, Height: 1080}toNewBrowserbase defaults (matching issue recommendation)3. UA auto-selection (
browser_init.go)opt.UserAgent == "", selectDefaultChromiumUserAgentorDefaultFirefoxUserAgentbased onopt.Browser4. Interactive browser alignment (
interactive.go)UserAgent: DefaultUserAgentfromNewInteractiveBrowserbase defaults (same auto-selection)5. Tests (
stealth_test.go)Branch:
fix/70-default-viewport-ua-alignmentImplementation complete. PR: #73
What was done:
DefaultFirefoxUserAgentandDefaultChromiumUserAgentconstants;DefaultUserAgentkept as backward-compatible aliasinitBrowsernow auto-selects the matching UA based onopt.Browserwhen none is explicitly set — fixes Firefox UA being applied to Chromium instancesNewBrowser(previously nil — a strong headless signal)NewInteractiveBrowseralso gains engine-aware UA selection (keeps its 1280x720 viewport)