@@ -17,23 +17,35 @@ import (
1717 "github.com/sirupsen/logrus"
1818)
1919
20+ // BrowserOpts configures Chromium launch and navigation behavior.
2021type BrowserOpts struct {
21- IsHeadless bool // Use browser interface
22- IsLeakless bool // Force to kill browser
23- Timeout time.Duration // Timeout
24- LanguageCode string
25- WaitRequests bool // Wait requests to complete after navigation
26- LeavePageOpen bool // Leave pages and browser open
27- WaitLoadTime time.Duration // Time to wait till page loads
28- CaptchaSolverApiKey string // 2Captcha api key
29- BrowserPath string // Explicit browser executable path
30- ProxyURL string // Proxy URL
31- Insecure bool // Allow insecure TLS connections
32- UseStealth bool // Use go-rod stealth plugin
33-
22+ // IsHeadless runs Chromium without visible UI.
23+ IsHeadless bool
24+ // IsLeakless forces child browser process cleanup when the parent exits.
25+ IsLeakless bool
26+ // Timeout is applied to browser connect and page navigation operations.
27+ Timeout time.Duration
28+ // LanguageCode sets Accept-Language for emulated requests.
29+ LanguageCode string
30+ // WaitRequests waits for request-idle state after navigation.
31+ WaitRequests bool
32+ // LeavePageOpen keeps pages open after search operations.
33+ LeavePageOpen bool
34+ // WaitLoadTime is an additional fixed wait after load/idle checks.
35+ WaitLoadTime time.Duration
36+ // CaptchaSolverApiKey enables 2Captcha integration for supported engines.
37+ CaptchaSolverApiKey string
38+ // BrowserPath optionally points to a specific browser executable.
39+ BrowserPath string
40+ // ProxyURL defines the upstream proxy for browser traffic.
41+ ProxyURL string
42+ // Insecure allows invalid TLS certificates for browser requests.
43+ Insecure bool
44+ // UseStealth enables go-rod stealth page creation.
45+ UseStealth bool
3446}
3547
36- // Initialize browser parameters with default values if they are not set
48+ // Check applies default option values when optional fields are unset.
3749func (o * BrowserOpts ) Check () {
3850 if o .Timeout == 0 {
3951 o .Timeout = time .Second * 30
@@ -44,13 +56,16 @@ func (o *BrowserOpts) Check() {
4456 }
4557}
4658
59+ // Browser wraps a launched Chromium instance used by engine implementations.
4760type Browser struct {
4861 BrowserOpts
4962 browserAddr string
5063 browser * rod.Browser
5164 CaptchaSolver * CaptchaSolver
5265}
5366
67+ // NewBrowser launches a new Chromium process via Rod launcher and returns a
68+ // Browser wrapper configured with proxy and captcha solver settings.
5469func NewBrowser (opts BrowserOpts ) (* Browser , error ) {
5570 opts .Check ()
5671 logrus .Debugf ("Browser options: %+v" , opts )
@@ -151,7 +166,7 @@ func resolveBrowserBinaryPath(browserPath string, lookPath func() (string, bool)
151166 return "" , nil
152167}
153168
154- // Check whether browser instance is already created
169+ // IsInitialized reports whether the browser launcher has been created.
155170func (b * Browser ) IsInitialized () bool {
156171 if b .browserAddr != "" {
157172 return true
@@ -160,7 +175,9 @@ func (b *Browser) IsInitialized() bool {
160175 }
161176}
162177
163- // Open URL
178+ // Navigate connects to Chromium, creates a page, applies stealth/emulation and
179+ // proxy auth, then navigates to URL. It returns an initialized page ready for
180+ // selector queries, or an error when browser setup/navigation fails.
164181func (b * Browser ) Navigate (URL string ) (* rod.Page , error ) {
165182 logrus .Debug ("Navigate to: " , URL )
166183
@@ -280,6 +297,7 @@ func (b *Browser) Navigate(URL string) (*rod.Page, error) {
280297 return page , nil
281298}
282299
300+ // Close closes the active browser connection.
283301func (b * Browser ) Close () error {
284302 return b .browser .Close ()
285303}
0 commit comments