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

Commit 9cd1e76

Browse files
committed
Fix overriding BrowserType launch defaults
For example, the following now picks the default values: // assuming passed from a JavaScript test script executablePath: "", executablePath: null, executablePath: undefined, Fixes #407
1 parent 2f9a61a commit 9cd1e76

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

common/browser_options.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ func (l *LaunchOptions) Parse(ctx context.Context, opts goja.Value) error { //no
6060
o = opts.ToObject(rt)
6161
)
6262
for _, k := range o.Keys() {
63-
var (
64-
err error
65-
v = o.Get(k)
66-
)
63+
v := o.Get(k)
64+
if v.Export() == nil {
65+
continue // don't override the defaults on `null``
66+
}
67+
var err error
6768
switch k {
6869
case "args":
6970
err = exportOpt(rt, k, v, &l.Args)

common/browser_options_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ func TestBrowserLaunchOptionsParse(t *testing.T) {
3030
}, lo)
3131
},
3232
},
33+
"nulls": { // don't override the defaults on `null`
34+
opts: map[string]any{
35+
"env": nil,
36+
"headless": nil,
37+
"logCategoryFilter": nil,
38+
"timeout": nil,
39+
},
40+
assert: func(tb testing.TB, lo *LaunchOptions) {
41+
tb.Helper()
42+
assert.Equal(tb, &LaunchOptions{
43+
Env: make(map[string]string),
44+
Headless: true,
45+
LogCategoryFilter: ".*",
46+
Timeout: DefaultTimeout,
47+
}, lo)
48+
},
49+
},
3350
"args": {
3451
opts: map[string]any{
3552
"args": []any{"browser-arg1='value1", "browser-arg2=value2", "browser-flag"},

0 commit comments

Comments
 (0)