NewInteractiveBrowser sets ViewportSize: &playwright.Size{Width: 1280, Height: 720}, but NewBrowser sets 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 defaultFirefoxUserAgent and uses it as a fallback, but there's no equivalent Chromium UA constant. When a caller uses BrowserChromium without explicitly setting a UA, the browser may end up with:
The Playwright default UA (contains HeadlessChrome)
Or the Firefox UA constant applied to a Chromium instance
Either case is a detectable mismatch.
Proposed Solution
Viewport
Add a default viewport to NewBrowser when none is provided:
**Parent Epic:** #68
## Problem
### Missing viewport in `NewBrowser`
`NewInteractiveBrowser` sets `ViewportSize: &playwright.Size{Width: 1280, Height: 720}`, but `NewBrowser` sets 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 `defaultFirefoxUserAgent` and uses it as a fallback, but there's no equivalent Chromium UA constant. When a caller uses `BrowserChromium` without explicitly setting a UA, the browser may end up with:
- The Playwright default UA (contains `HeadlessChrome`)
- Or the Firefox UA constant applied to a Chromium instance
Either case is a detectable mismatch.
## Proposed Solution
### Viewport
Add a default viewport to `NewBrowser` when none is provided:
```go
if opt.ViewportSize == nil {
opt.ViewportSize = &playwright.Size{Width: 1920, Height: 1080}
}
```
Use 1920x1080 as the default (most common desktop resolution globally).
### User-Agent alignment
1. Add a `defaultChromiumUserAgent` constant alongside the existing Firefox one
2. In `NewBrowser` / browser init, auto-select the matching UA based on `opt.Browser` when the caller hasn't explicitly set `opt.UserAgent`
3. Ensure the stealth script that strips `HeadlessChrome` from the UA only runs on Chromium
## Files to Modify
- `playwright.go` — add default viewport logic, add Chromium UA constant
- `browser_init.go` — auto-select UA based on browser engine
- `stealth_test.go` — test viewport defaults and UA selection
## References
- #68 — parent epic
Added DefaultFirefoxUserAgent and DefaultChromiumUserAgent constants; DefaultUserAgent kept as backward-compatible alias
initBrowser now auto-selects the matching UA based on opt.Browser when none is explicitly set — fixes Firefox UA being applied to Chromium instances
Added 1920x1080 default viewport to NewBrowser (previously nil — a strong headless signal)
NewInteractiveBrowser also gains engine-aware UA selection (keeps its 1280x720 viewport)
8 new tests: UA constant content validation, backward-compat alias, mergeOptions viewport/UA behavior
All builds, tests, and vet pass cleanly
Implementation complete. PR: #73
**What was done:**
- Added `DefaultFirefoxUserAgent` and `DefaultChromiumUserAgent` constants; `DefaultUserAgent` kept as backward-compatible alias
- `initBrowser` now auto-selects the matching UA based on `opt.Browser` when none is explicitly set — fixes Firefox UA being applied to Chromium instances
- Added 1920x1080 default viewport to `NewBrowser` (previously nil — a strong headless signal)
- `NewInteractiveBrowser` also gains engine-aware UA selection (keeps its 1280x720 viewport)
- 8 new tests: UA constant content validation, backward-compat alias, mergeOptions viewport/UA behavior
- All builds, tests, and vet pass cleanly
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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)