-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.go
56 lines (39 loc) · 1005 Bytes
/
browser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package request
import (
"os"
"time"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
)
func Browser(proxy string, timeout int, chromium bool) *rod.Browser {
var (
launch = launcher.New()
browser = rod.New()
chrome_path = []string{
`C:\Program Files\Google\Chrome\Application\chrome.exe`, // Windows
`/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`, // MacOS
`/usr/bin/google-chrome`, // Linux
`/opt/google/chrome/chrome`, // Linux
}
)
if !chromium {
for _, path := range chrome_path {
if exists(path) {
launch.Bin(path)
break
}
}
}
if proxy != "" {
launch.Set("proxy-server", proxy)
}
browser.Timeout(time.Duration(timeout) * time.Minute)
browser.ControlURL(launch.MustLaunch())
return browser.MustConnect()
}
func exists(file_path string) bool {
if _, err := os.Stat(file_path); err == nil {
return true
}
return false
}