-
-
Notifications
You must be signed in to change notification settings - Fork 334
/
main.go
104 lines (86 loc) · 2.01 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Package defaults holds some commonly used options parsed from env var "rod".
// Set them will set the default value of options used by rod.
// Each value is separated by a ",", key and value are separated by "=",
// For example:
//
// rod=show,trace,slow,monitor
//
// rod=show,trace,slow=1s,port=9222,monitor=:9223
//
package defaults
import (
"os"
"strings"
"time"
"github.com/ysmood/kit"
)
// Show disables headless mode
var Show bool
// Trace enables tracing
var Trace bool
// Quiet is only useful when Trace is enabled. It decides whether to log tracing message or not.
var Quiet bool
// Slow enables slowmotion mode if not zero
var Slow time.Duration
// Dir to store browser profile, such as cookies
var Dir string
// Port of the remote debugging port
var Port = "0"
// Bin path of chrome executable file
var Bin = ""
// URL of the remote debugging address
var URL = ""
// Remote enables to launch browser remotely
var Remote bool
// CDP enables cdp log
var CDP bool
// Monitor enables the monitor server that plays the screenshots of each tab, default value is 0.0.0.0:9273
var Monitor string
// Blind is only useful when Monitor is enabled, it decides whether to open a browser to watch the screenshots or not
var Blind bool
// Parse the flags
func init() {
parse(os.Getenv("rod"))
}
// parse options and set them globally
func parse(options string) {
if options == "" {
return
}
for _, f := range strings.Split(options, ",") {
kv := strings.Split(f, "=")
switch kv[0] {
case "show":
Show = true
case "trace":
Trace = true
case "quiet":
Quiet = true
case "slow":
var err error
Slow, err = time.ParseDuration(kv[1])
kit.E(err)
case "bin":
Bin = kv[1]
case "dir":
Dir = kv[1]
case "port":
Port = kv[1]
case "url":
URL = kv[1]
case "remote":
Remote = true
case "cdp":
CDP = true
case "monitor":
Monitor = ":9273"
if len(kv) == 2 {
Monitor = kv[1]
}
case "blind":
Blind = true
default:
panic("no such rod option: " + kv[0])
}
}
}