Skip to content

Commit 482f725

Browse files
committed
Remove random UA generator
1 parent 923b7c2 commit 482f725

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

core/browser.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package core
33
import (
44
"time"
55

6-
"github.com/corpix/uarand"
76
"github.com/go-rod/rod"
87
"github.com/go-rod/rod/lib/devices"
98
"github.com/go-rod/rod/lib/launcher"
@@ -12,13 +11,15 @@ import (
1211
)
1312

1413
type BrowserOpts struct {
15-
IsHeadless bool // Use browser interface
16-
IsLeakless bool // Force to kill browser
17-
Timeout time.Duration // Timeout
18-
LanguageCode string
19-
WaitRequests bool // Wait requests to complete after navigation
20-
LeavePageOpen bool // Leave pages and browser open
21-
WaitLoadTime time.Duration // Time to wait till page loads
14+
IsHeadless bool // Use browser interface
15+
IsLeakless bool // Force to kill browser
16+
Timeout time.Duration // Timeout
17+
LanguageCode string
18+
WaitRequests bool // Wait requests to complete after navigation
19+
LeavePageOpen bool // Leave pages and browser open
20+
WaitLoadTime time.Duration // Time to wait till page loads
21+
CaptchaSolverApiKey string // 2Captcha api key
22+
2223
}
2324

2425
// Initialize browser parameters with default values if they are not set
@@ -34,8 +35,9 @@ func (o *BrowserOpts) Check() {
3435

3536
type Browser struct {
3637
BrowserOpts
37-
browserAddr string
38-
browser *rod.Browser
38+
browserAddr string
39+
browser *rod.Browser
40+
CaptchaSolver *CaptchaSolver
3941
}
4042

4143
func NewBrowser(opts BrowserOpts) (*Browser, error) {
@@ -49,6 +51,11 @@ func NewBrowser(opts BrowserOpts) (*Browser, error) {
4951
b := Browser{BrowserOpts: opts}
5052
b.browserAddr, err = launcher.New().Bin(path).Leakless(opts.IsLeakless).Headless(opts.IsHeadless).Launch()
5153

54+
if opts.CaptchaSolverApiKey != "" {
55+
b.CaptchaSolver = NewSolver(opts.CaptchaSolverApiKey)
56+
logrus.Debug("Captcha solver initialized")
57+
}
58+
5259
return &b, err
5360
}
5461

@@ -69,22 +76,22 @@ func (b *Browser) Navigate(URL string) *rod.Page {
6976
b.browser.MustConnect()
7077
b.browser.SetCookies(nil)
7178

79+
//page := b.browser.MustPage(URL)
7280
page := stealth.MustPage(b.browser)
73-
wait := page.MustWaitRequestIdle()
81+
page.MustEmulate(devices.Device{
82+
//UserAgent: uarand.GetRandom(),
83+
AcceptLanguage: b.LanguageCode,
84+
})
7485
page.MustNavigate(URL)
7586

76-
// causes bugs in google
87+
wait := page.MustWaitRequestIdle()
88+
// may cause bugs with google
7789
if b.WaitRequests {
7890
wait()
7991
}
8092

81-
page.MustEmulate(devices.Device{
82-
UserAgent: uarand.GetRandom(),
83-
AcceptLanguage: b.LanguageCode,
84-
})
85-
8693
// Wait till page loads
87-
time.Sleep(b.WaitLoadTime)
94+
//time.Sleep(b.WaitLoadTime)
8895

8996
return page
9097
}

0 commit comments

Comments
 (0)