Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 4e48ccc

Browse files
committed
Make browser launch options optional
So that users can launch a browser without giving any options: const browser = chromium.launch();
1 parent 79b7f08 commit 4e48ccc

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

chromium/browser_type.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ func (b *BrowserType) Launch(opts goja.Value) api.Browser {
131131
if b.logger, err = makeLogger(ctx); err != nil {
132132
k6ext.Panic(ctx, "setting up logger: %w", err)
133133
}
134-
135134
launchOpts := common.NewLaunchOptions(k6ext.OnCloud())
136-
if err := launchOpts.Parse(ctx, opts, b.logger); err != nil {
135+
if err := launchOpts.Parse(ctx, b.logger, opts); err != nil {
137136
k6ext.Panic(ctx, "parsing launch options: %w", err)
138137
}
139138
ctx = common.WithLaunchOptions(ctx, launchOpts)

common/browser_options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package common
22

33
import (
44
"context"
5-
"errors"
65
"time"
76

87
"github.com/dop251/goja"
@@ -55,9 +54,10 @@ func NewLaunchOptions(onCloud bool) *LaunchOptions {
5554
}
5655

5756
// Parse parses launch options from a JS object.
58-
func (l *LaunchOptions) Parse(ctx context.Context, opts goja.Value, logger *log.Logger) error { //nolint:cyclop
57+
func (l *LaunchOptions) Parse(ctx context.Context, logger *log.Logger, opts goja.Value) error { //nolint:cyclop
58+
// when opts is nil, we just return the default options without error.
5959
if !gojaValueExists(opts) {
60-
return errors.New("LaunchOptions does not exist in the runtime")
60+
return nil
6161
}
6262
var (
6363
rt = k6ext.Runtime(ctx)

common/browser_options_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func TestBrowserLaunchOptionsParse(t *testing.T) {
253253
vu = k6test.NewVU(t)
254254
lo = NewLaunchOptions(tt.onCloud)
255255
)
256-
err := lo.Parse(vu.Context(), vu.ToGojaValue(tt.opts), log.NewNullLogger())
256+
err := lo.Parse(vu.Context(), log.NewNullLogger(), vu.ToGojaValue(tt.opts))
257257
if tt.err != "" {
258258
require.ErrorContains(t, err, tt.err)
259259
} else {

0 commit comments

Comments
 (0)