Skip to content

Commit

Permalink
remove legacy env Remote and Quiet
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Sep 25, 2020
1 parent f164718 commit 0113baf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 55 deletions.
13 changes: 3 additions & 10 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,10 @@ func (b *Browser) DefaultViewport(viewport *proto.EmulationSetDeviceMetricsOverr
func (b *Browser) Connect() error {
if b.client == nil {
u := defaults.URL
if defaults.Remote {
if u == "" {
u = "ws://127.0.0.1:9222"
}
b.client = launcher.MustNewRemote(u).Client()
} else {
if u == "" {
u = launcher.New().Context(b.ctx).MustLaunch()
}
b.client = cdp.New(u)
if u == "" {
u = launcher.New().Context(b.ctx).MustLaunch()
}
b.client = cdp.New(u)
}

err := b.client.Connect(b.ctx)
Expand Down
9 changes: 0 additions & 9 deletions browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,6 @@ func (s *S) TestBinarySize() {
}

func (s *S) TestBrowserConnectErr() {
s.Panics(func() {
ctx, cancel := context.WithCancel(context.Background())
defaults.Remote = true
defer defaults.ResetWithEnv()

cancel()
rod.New().Context(ctx).MustConnect()
})

s.Panics(func() {
c := newMockClient(s, nil)
c.connect = func() error { return errors.New("err") }
Expand Down
46 changes: 16 additions & 30 deletions lib/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,36 @@ import (
"github.com/go-rod/rod/lib/utils"
)

// Show disables headless mode
var Show bool

// Trace enables tracing
// Trace is the default of rod.Browser.Trace
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
// Slow is the default of rod.Browser.Slowmotion
var Slow time.Duration

// Dir to store browser profile, such as cookies
// Monitor is the default of rod.Browser.ServeMonitor
var Monitor string

// Show is the default of launcher.Launcher.Headless
var Show bool

// Dir is the default of launcher.Launcher.UserDataDir
var Dir string

// Port of the remote debugging port
// Port is the default of launcher.Launcher.RemoteDebuggingPort
var Port string

// Bin path of chrome executable file
// Bin is the default of launcher.Launcher.Bin
var Bin string

// URL of the remote debugging address
var URL string
// Proxy is the default of launcher.Launcher.Proxy
var Proxy string

// Remote enables to launch browser remotely
var Remote bool
// URL is the default of cdp.Client.New
var URL string

// CDP enables cdp log
// CDP is the default of cdp.Client.Debug
var CDP bool

// Monitor enables the monitor server that plays the screenshots of each tab
var Monitor string

// Proxy for the browser
var Proxy string

// Parse the flags
func init() {
ResetWithEnv()
Expand All @@ -62,13 +56,11 @@ func init() {
func Reset() {
Show = false
Trace = false
Quiet = false
Slow = 0
Dir = ""
Port = "0"
Bin = ""
URL = ""
Remote = false
CDP = false
Monitor = ""
Proxy = ""
Expand Down Expand Up @@ -103,9 +95,6 @@ var rules = map[string]func(string){
"trace": func(string) {
Trace = true
},
"quiet": func(string) {
Quiet = true
},
"slow": func(v string) {
var err error
Slow, err = time.ParseDuration(v)
Expand All @@ -123,9 +112,6 @@ var rules = map[string]func(string){
"url": func(v string) {
URL = v
},
"remote": func(v string) {
Remote = true
},
"cdp": func(v string) {
CDP = true
},
Expand Down
8 changes: 2 additions & 6 deletions lib/defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,22 @@ func TestBasic(t *testing.T) {
Show = true
URL = "test"
Monitor = "test"
Remote = true

ResetWithEnv()
parse("")
assert.False(t, Show)
assert.Equal(t, "", Monitor)
assert.Equal(t, "", URL)
assert.False(t, Remote)

parse("show,trace,slow=2s,port=8080,remote,dir=tmp," +
"url=http://test.com,cdp,monitor,quiet,bin=/path/to/chrome," +
parse("show,trace,slow=2s,port=8080,dir=tmp," +
"url=http://test.com,cdp,monitor,bin=/path/to/chrome," +
"proxy=localhost:8080",
)

assert.True(t, Show)
assert.True(t, Trace)
assert.True(t, Quiet)
assert.Equal(t, 2*time.Second, Slow)
assert.Equal(t, "8080", Port)
assert.Equal(t, true, Remote)
assert.Equal(t, "/path/to/chrome", Bin)
assert.Equal(t, "tmp", Dir)
assert.Equal(t, "http://test.com", URL)
Expand Down

0 comments on commit 0113baf

Please sign in to comment.