From 0113baf7aa78d3d266692917cdf31763a94dd991 Mon Sep 17 00:00:00 2001 From: Yad Smood Date: Fri, 25 Sep 2020 08:38:11 +0900 Subject: [PATCH] remove legacy env Remote and Quiet --- browser.go | 13 +++------- browser_test.go | 9 ------- lib/defaults/defaults.go | 46 ++++++++++++----------------------- lib/defaults/defaults_test.go | 8 ++---- 4 files changed, 21 insertions(+), 55 deletions(-) diff --git a/browser.go b/browser.go index 7e86f320..186804a6 100644 --- a/browser.go +++ b/browser.go @@ -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) diff --git a/browser_test.go b/browser_test.go index ccdda814..fe1e8ae8 100644 --- a/browser_test.go +++ b/browser_test.go @@ -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") } diff --git a/lib/defaults/defaults.go b/lib/defaults/defaults.go index 36e469b8..e3762291 100644 --- a/lib/defaults/defaults.go +++ b/lib/defaults/defaults.go @@ -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() @@ -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 = "" @@ -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) @@ -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 }, diff --git a/lib/defaults/defaults_test.go b/lib/defaults/defaults_test.go index 8c7a32ae..8474fd09 100644 --- a/lib/defaults/defaults_test.go +++ b/lib/defaults/defaults_test.go @@ -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)