Documentation
¶
Overview ¶
Package headless_browser provides a simple headless browser library powered by go-rod with built-in stealth mode support.
Index ¶
- type Browser
- type Config
- type Option
- func WithChromeBinPath(path string) Option
- func WithCookies(cookies string) Option
- func WithExtraFlags(flags map[string]string) Option
- func WithFingerprint(platform string) Option
- func WithFingerprintSeed(seed int) Option
- func WithHeadless(headless bool) Option
- func WithLanguage(lang string) Option
- func WithProxy(proxy string) Option
- func WithStealthJS(enabled bool) Option
- func WithTrace() Option
- func WithUserAgent(userAgent string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser represents a headless browser instance with an underlying rod.Browser and launcher.
type Config ¶
type Config struct {
Headless bool // Whether to run browser in headless mode
UserAgent string // 自定义 UA。空 = 不覆盖,交给浏览器/指纹补丁自报(推荐,避免与 Client Hints 矛盾)
Cookies string // JSON string of cookies to set
ChromeBinPath string // Custom Chrome/Chromium executable path
Proxy string // Proxy server URL (e.g. "http://host:port", "socks5://host:port")
// Fingerprint 为 true 时,传入 CloakBrowser 的源码级指纹参数
// (--fingerprint={seed} 与 --fingerprint-platform={platform}),激活其一致指纹引擎。
// 仅对 CloakBrowser Chromium 有效;普通 Chrome 会忽略这些未知参数。
Fingerprint bool
FingerprintPlatform string // 空 = 按运行 OS 自动:linux/windows→windows,darwin→macos
FingerprintSeed int // 0 = 每次启动随机 seed
// StealthJS 是否用 go-rod/stealth 注入 JS 指纹补丁。
// 用 CloakBrowser 时应设为 false:源码级补丁已处理,再注入 JS 反而制造矛盾且本身可被检测。
StealthJS bool
// Language 覆盖 Accept-Language 与 navigator.languages(如 "zh-CN")。空 = 不覆盖。
// 仅在启用 Fingerprint 的一致 UA 覆盖时生效。
Language string
// ExtraFlags 透传任意浏览器启动 flag(如 fingerprint-chromium 的
// "fingerprint-brand":"Chrome"、"fingerprint-hardware-concurrency":"8")。
// 键不带前导 "--"。
ExtraFlags map[string]string
Trace bool // Whether to enable tracing (not implemented yet)
}
Config holds the configuration options for the browser.
type Option ¶
type Option func(*Config)
Option is a functional option for configuring the browser.
func WithChromeBinPath ¶ added in v0.1.0
WithChromeBinPath sets a custom Chrome/Chromium executable path. If not set or empty, launcher will auto-detect or download a browser. Common paths:
- macOS: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
- Linux: "/usr/bin/google-chrome" or "/usr/bin/chromium"
- Windows: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
func WithCookies ¶
WithCookies sets cookies for the browser from a JSON string. The cookies should be in the format expected by proto.NetworkCookie.
func WithExtraFlags ¶ added in v0.4.0
WithExtraFlags 透传任意浏览器启动 flag(键不带前导 "--")。
func WithFingerprint ¶ added in v0.4.0
WithFingerprint 启用 CloakBrowser 源码级指纹引擎。 platform 传空则按运行 OS 自动选择(Linux 服务器呈现 Windows 画像,mac 呈现 macOS)。
func WithFingerprintSeed ¶ added in v0.4.0
WithFingerprintSeed 固定指纹 seed(0 表示每次随机)。同一 seed 产出同一套一致指纹。
func WithHeadless ¶
WithHeadless sets whether the browser should run in headless mode.
func WithLanguage ¶ added in v0.4.0
WithLanguage 覆盖 Accept-Language 与 navigator.languages(如 "zh-CN")。仅在启用 Fingerprint 时生效。
func WithProxy ¶ added in v0.3.0
WithProxy sets a proxy server for all browser requests. Supports HTTP, HTTPS, and SOCKS5 proxies. Example: "http://proxy.example.com:8080", "socks5://127.0.0.1:1080"
Note: Chrome's --proxy-server flag does not support embedded credentials (e.g. "http://user:pass@host:port"). For authenticated proxies, handle authentication separately at the page level.
func WithStealthJS ¶ added in v0.4.0
WithStealthJS 控制是否注入 go-rod/stealth 的 JS 补丁。用 CloakBrowser 时应传 false。
func WithUserAgent ¶
WithUserAgent sets a custom user agent string for the browser. 注意:配合 CloakBrowser 使用时不建议设置,强制 UA 会与 Client Hints 产生矛盾。