fix: consolidate user-agent strings into DefaultUserAgent constant
All checks were successful
CI / build (pull_request) Successful in 44s
CI / test (pull_request) Successful in 46s
CI / vet (pull_request) Successful in 1m28s

Define DefaultUserAgent (Firefox/147.0) in playwright.go and reference
it from NewBrowser, NewInteractiveBrowser, and CLI flags. Previously
three different UA strings existed (two at 142.0, one outdated at 133.0).

Closes #17

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 16:24:44 +00:00
parent 0df639abea
commit 097b2e12c7
3 changed files with 7 additions and 4 deletions

View File

@@ -16,7 +16,7 @@ var Flags = BrowserFlags{
Name: "user-agent", Name: "user-agent",
Aliases: []string{"ua"}, Aliases: []string{"ua"},
Usage: "User-Agent to use for requests", Usage: "User-Agent to use for requests",
DefaultText: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0", DefaultText: extractor.DefaultUserAgent,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "timeout", Name: "timeout",

View File

@@ -59,7 +59,7 @@ type interactiveBrowser struct {
func NewInteractiveBrowser(ctx context.Context, opts ...BrowserOptions) (InteractiveBrowser, error) { func NewInteractiveBrowser(ctx context.Context, opts ...BrowserOptions) (InteractiveBrowser, error) {
var thirtySeconds = 30 * time.Second var thirtySeconds = 30 * time.Second
opt := mergeOptions(BrowserOptions{ opt := mergeOptions(BrowserOptions{
UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0", UserAgent: DefaultUserAgent,
Browser: BrowserFirefox, Browser: BrowserFirefox,
Timeout: &thirtySeconds, Timeout: &thirtySeconds,
Dimensions: Size{ Dimensions: Size{

View File

@@ -36,6 +36,9 @@ const (
BrowserWebKit BrowserSelection = "webkit" BrowserWebKit BrowserSelection = "webkit"
) )
// DefaultUserAgent is the user-agent string used by all browser instances.
const DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0"
// Bool returns a pointer to the given bool value. // Bool returns a pointer to the given bool value.
func Bool(v bool) *bool { return &v } func Bool(v bool) *bool { return &v }
@@ -44,7 +47,7 @@ type Size struct {
Height int Height int
} }
type BrowserOptions struct { type BrowserOptions struct {
UserAgent string // If empty, defaults to "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" UserAgent string // If empty, defaults to DefaultUserAgent
Browser BrowserSelection // If unset defaults to Firefox. Browser BrowserSelection // If unset defaults to Firefox.
Timeout *time.Duration // If unset defaults to 30 seconds timeout. If set to 0, no timeout Timeout *time.Duration // If unset defaults to 30 seconds timeout. If set to 0, no timeout
@@ -94,7 +97,7 @@ func playwrightCookieToCookie(cookie playwright.Cookie) Cookie {
func NewBrowser(ctx context.Context, opts ...BrowserOptions) (Browser, error) { func NewBrowser(ctx context.Context, opts ...BrowserOptions) (Browser, error) {
var thirtySeconds = 30 * time.Second var thirtySeconds = 30 * time.Second
opt := mergeOptions(BrowserOptions{ opt := mergeOptions(BrowserOptions{
UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0", UserAgent: DefaultUserAgent,
Browser: BrowserFirefox, Browser: BrowserFirefox,
Timeout: &thirtySeconds, Timeout: &thirtySeconds,
}, opts) }, opts)