Skip to content

Commit 72382c6

Browse files
committed
protective code for init connection
1 parent 0d0e59e commit 72382c6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

browser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ func (b *Browser) Connect() error {
157157
return err
158158
}
159159
b.client = c
160+
} else if b.controlURL != "" {
161+
panic("Browser.Client and Browser.ControlURL can't be set at the same time")
160162
}
161163

162164
b.initEvents()

browser_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/go-rod/rod"
14+
"github.com/go-rod/rod/lib/cdp"
1415
"github.com/go-rod/rod/lib/devices"
1516
"github.com/go-rod/rod/lib/launcher"
1617
"github.com/go-rod/rod/lib/proto"
@@ -474,3 +475,10 @@ func TestBrowserLostConnection(t *testing.T) {
474475
_, err := p.Eval(`() => new Promise(r => {})`)
475476
g.Err(err)
476477
}
478+
479+
func TestBrowserConnectConflict(t *testing.T) {
480+
g := setup(t)
481+
g.Panic(func() {
482+
rod.New().Client(&cdp.Client{}).ControlURL("test").MustConnect()
483+
})
484+
}

0 commit comments

Comments
 (0)