Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to NewRemoteAllocator to avoid URL detection #990

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions allocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ func CombinedOutput(w io.Writer) ExecAllocatorOption {
// websocket address, such as "ws://127.0.0.1:$PORT/devtools/browser/...".
// If the url does not contain "/devtools/browser/", it will try to detect
// the correct one by sending a request to "http://$HOST:$PORT/json/version".
// In case a RemoteAllocatorOption with FetchJSONDebuggerURL set as false
// is passed, the URL won't be detected and will use the original URL
//
// The url with the following formats are accepted:
// * ws://127.0.0.1:9222/
Expand All @@ -507,10 +509,17 @@ func CombinedOutput(w io.Writer) ExecAllocatorOption {
// But "ws://127.0.0.1:9222/devtools/browser/" are not accepted.
// Because it contains "/devtools/browser/" and will be considered
// as a valid websocket debugger URL.
func NewRemoteAllocator(parent context.Context, url string) (context.Context, context.CancelFunc) {
func NewRemoteAllocator(parent context.Context, url string, opts ...RemoteAllocatorOption) (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancel(parent)
var wsURL string
if opts != nil && !opts[0].FetchJSONDebuggerURL {
wsURL = url
} else {
wsURL = detectURL(url)
}

c := &Context{Allocator: &RemoteAllocator{
wsURL: detectURL(url),
wsURL: wsURL,
}}
ctx = context.WithValue(ctx, contextKey{}, c)
return ctx, cancel
Expand All @@ -524,6 +533,12 @@ type RemoteAllocator struct {
wg sync.WaitGroup
}

type RemoteAllocatorOption struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should stick with the functional options pattern. Refer to how ExecAllocatorOption is implemented.

FetchJSONDebuggerURL bool
}

var PersistDebuggerURL = RemoteAllocatorOption{ FetchJSONDebuggerURL: false }

// Allocate satisfies the Allocator interface.
func (a *RemoteAllocator) Allocate(ctx context.Context, opts ...BrowserOption) (*Browser, error) {
c := FromContext(ctx)
Expand Down