feature: add stealth mode, launch args, and init scripts to BrowserOptions
Add anti-bot-detection evasion support to reduce blocking by sites like archive.ph. Stealth mode is enabled by default for all browsers and applies common evasions: navigator.webdriver override, plugin/mimeType spoofing, window.chrome stub, and outerWidth/outerHeight fixes. For Chromium, --disable-blink-features=AutomationControlled is also added. New BrowserOptions fields: - Stealth *bool: toggle stealth presets (default true) - LaunchArgs []string: custom browser launch arguments - InitScripts []string: JavaScript injected before page scripts Closes #56 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -70,6 +70,20 @@ type BrowserOptions struct {
|
||||
|
||||
// UseLocalOnly will, if set, not connect to the Playwright server, and instead launch a local browser.
|
||||
UseLocalOnly bool
|
||||
|
||||
// LaunchArgs are additional command-line arguments passed to the browser process.
|
||||
// For example: []string{"--disable-blink-features=AutomationControlled"}
|
||||
LaunchArgs []string
|
||||
|
||||
// InitScripts are JavaScript snippets injected into every new browser context
|
||||
// before any page scripts run. Useful for overriding detectable properties like
|
||||
// navigator.webdriver.
|
||||
InitScripts []string
|
||||
|
||||
// Stealth enables anti-bot-detection measures. When non-nil and true, common
|
||||
// evasions are applied automatically (launch args + init scripts). When nil,
|
||||
// defaults to true in NewBrowser / NewInteractiveBrowser.
|
||||
Stealth *bool
|
||||
}
|
||||
|
||||
func sameSiteToPlaywright(s SameSite) *playwright.SameSiteAttribute {
|
||||
@@ -134,6 +148,7 @@ func NewBrowser(ctx context.Context, opts ...BrowserOptions) (Browser, error) {
|
||||
UserAgent: DefaultUserAgent,
|
||||
Browser: BrowserFirefox,
|
||||
Timeout: &thirtySeconds,
|
||||
Stealth: Bool(true),
|
||||
}, opts)
|
||||
|
||||
if err := ctx.Err(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user