Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package rod

import (
"context"
"net/http"
"reflect"
"strings"
"sync"
Expand Down Expand Up @@ -145,7 +146,8 @@ func (b *Browser) NoDefaultDevice() *Browser {

// Connect to the browser and start to control it.
// If fails to connect, try to launch a local browser, if local browser not found try to download one.
func (b *Browser) Connect() error {
// If connect websocket not chromium,use header and set Sec-WebSocket-Key, for example websocket for transfer chromium.
func (b *Browser) Connect(h http.Header) error {
if b.client == nil {
u := b.controlURL
if u == "" {
Expand All @@ -156,7 +158,7 @@ func (b *Browser) Connect() error {
}
}

c, err := cdp.StartWithURL(b.ctx, u, nil)
c, err := cdp.StartWithURL(b.ctx, u, h)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func TestBrowserConnectFailure(t *testing.T) {

c := g.Context()
c.Cancel()
err := rod.New().Context(c).Connect()
err := rod.New().Context(c).Connect(nil)
if err == nil {
g.Fatal("expected an error on connect failure")
}
Expand All @@ -447,7 +447,7 @@ func TestBrowserPool(t *testing.T) {

b, err := pool.Get(func() (*rod.Browser, error) {
browser := rod.New()
return browser, browser.Connect()
return browser, browser.Connect(nil)
})
g.E(err)
pool.Put(b)
Expand Down
2 changes: 1 addition & 1 deletion must.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (b *Browser) WithPanic(fail func(interface{})) *Browser {

// MustConnect is similar to [Browser.Connect].
func (b *Browser) MustConnect() *Browser {
b.e(b.Connect())
b.e(b.Connect(nil))
return b
}

Expand Down