diff --git a/browser/browser_mapping.go b/browser/browser_mapping.go index f2cfc7640..e36c8ebff 100644 --- a/browser/browser_mapping.go +++ b/browser/browser_mapping.go @@ -56,7 +56,7 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop if err != nil { return "", err } - return b.UserAgent(), nil + return b.UserAgent() //nolint:wrapcheck }, "version": func() (string, error) { b, err := vu.browser() diff --git a/browser/mapping_test.go b/browser/mapping_test.go index 316b825b9..827b708aa 100644 --- a/browser/mapping_test.go +++ b/browser/mapping_test.go @@ -255,7 +255,7 @@ type browserAPI interface { NewContext(opts goja.Value) (*common.BrowserContext, error) NewPage(opts goja.Value) (*common.Page, error) On(string) (bool, error) - UserAgent() string + UserAgent() (string, error) Version() string } diff --git a/common/browser.go b/common/browser.go index 79bfa438a..fed6d241a 100644 --- a/common/browser.go +++ b/common/browser.go @@ -628,13 +628,13 @@ func (b *Browser) On(event string) (bool, error) { } // UserAgent returns the controlled browser's user agent string. -func (b *Browser) UserAgent() string { +func (b *Browser) UserAgent() (string, error) { action := cdpbrowser.GetVersion() - _, _, _, ua, _, err := action.Do(cdp.WithExecutor(b.ctx, b.conn)) + _, _, _, ua, _, err := action.Do(cdp.WithExecutor(b.ctx, b.conn)) //nolint:dogsled if err != nil { - k6ext.Panic(b.ctx, "getting browser user agent: %w", err) + return "", fmt.Errorf("getting browser user agent: %w", err) } - return ua + return ua, nil } // Version returns the controlled browser's version. diff --git a/tests/browser_test.go b/tests/browser_test.go index 8f3f150e0..fa13504be 100644 --- a/tests/browser_test.go +++ b/tests/browser_test.go @@ -210,7 +210,8 @@ func TestBrowserUserAgent(t *testing.T) { // testBrowserVersion() tests the version already // just look for "Headless" in UserAgent - ua := b.UserAgent() + ua, err := b.UserAgent() + require.NoError(t, err) if prefix := "Mozilla/5.0"; !strings.HasPrefix(ua, prefix) { t.Errorf("UserAgent should start with %q, but got: %q", prefix, ua) }