Consolidate user-agent strings (#17) #39

Merged
Claude merged 1 commits from fix/user-agent-consistency into main 2026-02-15 16:25:03 +00:00
3 changed files with 7 additions and 4 deletions
Showing only changes of commit 097b2e12c7 - Show all commits

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)