diff --git a/go.mod b/go.mod index cf8079f1995..dd922cf5f04 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/go-sourcemap/sourcemap v2.1.4+incompatible github.com/golang/protobuf v1.5.4 github.com/gorilla/websocket v1.5.3 - github.com/grafana/xk6-browser v1.9.2-0.20241118153201-d741e4540a3a + github.com/grafana/xk6-browser v1.10.0 github.com/grafana/xk6-dashboard v0.7.5 github.com/grafana/xk6-output-opentelemetry v0.3.0 github.com/grafana/xk6-output-prometheus-remote v0.5.0 diff --git a/go.sum b/go.sum index b1ea1252cbc..1fa6ae22efc 100644 --- a/go.sum +++ b/go.sum @@ -87,8 +87,8 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grafana/sobek v0.0.0-20241024150027-d91f02b05e9b h1:hzfIt1lf19Zx1jIYdeHvuWS266W+jL+7dxbpvH2PZMQ= github.com/grafana/sobek v0.0.0-20241024150027-d91f02b05e9b/go.mod h1:FmcutBFPLiGgroH42I4/HBahv7GxVjODcVWFTw1ISes= -github.com/grafana/xk6-browser v1.9.2-0.20241118153201-d741e4540a3a h1:nZXZ/QAXQEv3N66ExeAWEx0TVYof/qjbnm7ug3A7gNk= -github.com/grafana/xk6-browser v1.9.2-0.20241118153201-d741e4540a3a/go.mod h1:Kvysy3onM6dsyh8Vi7Sqnzwolp4tSL11NN1ckNa0emU= +github.com/grafana/xk6-browser v1.10.0 h1:nj7CdQRtfEnBC8UpiFJVqfoXeWktMO+v5FV1ST44aFw= +github.com/grafana/xk6-browser v1.10.0/go.mod h1:fCdTCgN4x154XOj5bRajxsCjvMA3dShkGQa59Br34xI= github.com/grafana/xk6-dashboard v0.7.5 h1:TcILyffT/Ea/XD7xG1jMA5lwtusOPRbEQsQDHmO30Mk= github.com/grafana/xk6-dashboard v0.7.5/go.mod h1:Y75F8xmgCraKT+pBzFH6me9AyH5PkXD+Bxo1dm6Il/M= github.com/grafana/xk6-output-opentelemetry v0.3.0 h1:dmclGBFtFVRJijqLncpu2dKVIIvx1GS3y6sQGg4Khl8= diff --git a/vendor/github.com/grafana/xk6-browser/browser/browser_context_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/browser_context_mapping.go index 46efd2e3031..f4b9abd3646 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/browser_context_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/browser_context_mapping.go @@ -14,7 +14,7 @@ import ( ) // mapBrowserContext to the JS module. -func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolint:funlen,gocognit,cyclop +func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolint:funlen,gocognit rt := vu.Runtime() return mapping{ "addCookies": func(cookies []*common.Cookie) *sobek.Promise { diff --git a/vendor/github.com/grafana/xk6-browser/browser/browser_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/browser_mapping.go index 4d28d396e59..10051209565 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/browser_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/browser_mapping.go @@ -10,7 +10,7 @@ import ( ) // mapBrowser to the JS module. -func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop,gocognit +func mapBrowser(vu moduleVU) mapping { //nolint:funlen,gocognit return mapping{ "context": func() (mapping, error) { b, err := vu.browser() diff --git a/vendor/github.com/grafana/xk6-browser/browser/element_handle_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/element_handle_mapping.go index e38a78bef87..2ce19d416f8 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/element_handle_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/element_handle_mapping.go @@ -10,7 +10,7 @@ import ( ) // mapElementHandle to the JS module. -func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint:gocognit,cyclop,funlen +func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint:gocognit,funlen rt := vu.Runtime() maps := mapping{ "boundingBox": func() *sobek.Promise { diff --git a/vendor/github.com/grafana/xk6-browser/browser/file_persister.go b/vendor/github.com/grafana/xk6-browser/browser/file_persister.go index f244f2f1544..93df6609dae 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/file_persister.go +++ b/vendor/github.com/grafana/xk6-browser/browser/file_persister.go @@ -37,7 +37,7 @@ func newScreenshotPersister(envLookup env.LookupFunc) (filePersister, error) { // url=https://127.0.0.1/,basePath=/screenshots,header.1=a,header.2=b // and return them. // -//nolint:cyclop + func parsePresignedURLEnvVar(envVarValue string) (presignedURLConfig, error) { ss := strings.Split(envVarValue, ",") diff --git a/vendor/github.com/grafana/xk6-browser/browser/frame_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/frame_mapping.go index d414c7dcb17..1bb7293cc0b 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/frame_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/frame_mapping.go @@ -11,8 +11,8 @@ import ( // mapFrame to the JS module. // -//nolint:funlen -func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop +//nolint:funlen,gocognit +func mapFrame(vu moduleVU, f *common.Frame) mapping { maps := mapping{ "check": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { @@ -59,19 +59,25 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return nil, f.DispatchEvent(selector, typ, exportArg(eventInit), popts) //nolint:wrapcheck }), nil }, - "evaluate": func(pageFunction sobek.Value, gargs ...sobek.Value) *sobek.Promise { + "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + if sobekEmptyString(pageFunc) { + return nil, fmt.Errorf("evaluate requires a page function") + } return k6ext.Promise(vu.Context(), func() (any, error) { - return f.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck - }) + return f.Evaluate(pageFunc.String(), exportArgs(gargs)...) + }), nil }, - "evaluateHandle": func(pageFunction sobek.Value, gargs ...sobek.Value) *sobek.Promise { + "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + if sobekEmptyString(pageFunc) { + return nil, fmt.Errorf("evaluateHandle requires a page function") + } return k6ext.Promise(vu.Context(), func() (any, error) { - jsh, err := f.EvaluateHandle(pageFunction.String(), exportArgs(gargs)...) + jsh, err := f.EvaluateHandle(pageFunc.String(), exportArgs(gargs)...) if err != nil { return nil, err //nolint:wrapcheck } return mapJSHandle(vu, jsh), nil - }) + }), nil }, "fill": func(selector, value string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { diff --git a/vendor/github.com/grafana/xk6-browser/browser/helpers.go b/vendor/github.com/grafana/xk6-browser/browser/helpers.go index 10b80473eac..4b79e14ba43 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/helpers.go +++ b/vendor/github.com/grafana/xk6-browser/browser/helpers.go @@ -3,6 +3,7 @@ package browser import ( "context" "errors" + "strings" "github.com/grafana/sobek" @@ -61,3 +62,8 @@ func exportArgs(gargs []sobek.Value) []any { func sobekValueExists(v sobek.Value) bool { return v != nil && !sobek.IsUndefined(v) && !sobek.IsNull(v) } + +// sobekEmptyString returns true if a given value is not nil or an empty string. +func sobekEmptyString(v sobek.Value) bool { + return !sobekValueExists(v) || strings.TrimSpace(v.String()) == "" +} diff --git a/vendor/github.com/grafana/xk6-browser/browser/js_handle_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/js_handle_mapping.go index db300a6d5a6..ad32bee8de7 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/js_handle_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/js_handle_mapping.go @@ -1,6 +1,8 @@ package browser import ( + "fmt" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" @@ -15,26 +17,32 @@ func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { }, "dispose": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { - return nil, jsh.Dispose() //nolint:wrapcheck + return nil, jsh.Dispose() }) }, - "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) *sobek.Promise { + "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + if sobekEmptyString(pageFunc) { + return nil, fmt.Errorf("evaluate requires a page function") + } return k6ext.Promise(vu.Context(), func() (any, error) { args := make([]any, 0, len(gargs)) for _, a := range gargs { args = append(args, exportArg(a)) } - return jsh.Evaluate(pageFunc.String(), args...) //nolint:wrapcheck - }) + return jsh.Evaluate(pageFunc.String(), args...) + }), nil }, - "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) *sobek.Promise { + "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + if sobekEmptyString(pageFunc) { + return nil, fmt.Errorf("evaluateHandle requires a page function") + } return k6ext.Promise(vu.Context(), func() (any, error) { h, err := jsh.EvaluateHandle(pageFunc.String(), exportArgs(gargs)...) if err != nil { return nil, err //nolint:wrapcheck } return mapJSHandle(vu, h), nil - }) + }), nil }, "getProperties": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { diff --git a/vendor/github.com/grafana/xk6-browser/browser/page_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/page_mapping.go index 7c4650d6d6d..ce0e82fe723 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/page_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/page_mapping.go @@ -80,19 +80,25 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.EmulateVisionDeficiency(typ) //nolint:wrapcheck }) }, - "evaluate": func(pageFunction sobek.Value, gargs ...sobek.Value) *sobek.Promise { + "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + if sobekEmptyString(pageFunc) { + return nil, fmt.Errorf("evaluate requires a page function") + } return k6ext.Promise(vu.Context(), func() (any, error) { - return p.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck - }) + return p.Evaluate(pageFunc.String(), exportArgs(gargs)...) + }), nil }, - "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) *sobek.Promise { + "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) (*sobek.Promise, error) { + if sobekEmptyString(pageFunc) { + return nil, fmt.Errorf("evaluateHandle requires a page function") + } return k6ext.Promise(vu.Context(), func() (any, error) { jsh, err := p.EvaluateHandle(pageFunc.String(), exportArgs(gargs)...) if err != nil { return nil, err //nolint:wrapcheck } return mapJSHandle(vu, jsh), nil - }) + }), nil }, "fill": func(selector string, value string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { diff --git a/vendor/github.com/grafana/xk6-browser/browser/registry.go b/vendor/github.com/grafana/xk6-browser/browser/registry.go index 0872a61db5b..b0f37a95428 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/registry.go +++ b/vendor/github.com/grafana/xk6-browser/browser/registry.go @@ -253,7 +253,7 @@ func newBrowserRegistry( return r } -func (r *browserRegistry) handleIterEvents( //nolint:funlen +func (r *browserRegistry) handleIterEvents( ctx context.Context, eventsCh <-chan *k6event.Event, unsubscribeFn func(), ) { var ( @@ -291,7 +291,7 @@ func (r *browserRegistry) handleIterEvents( //nolint:funlen continue } - switch e.Type { //nolint:exhaustive + switch e.Type { case k6event.IterStart: // Because VU.State is nil when browser registry is initialized, // we have to initialize traces registry on the first VU iteration @@ -454,7 +454,7 @@ func (r *tracesRegistry) startIterationTrace(ctx context.Context, data k6event.I spanCtx, span := r.tracer.Start(ctx, "iteration", oteltrace.WithAttributes( attribute.Int64("test.iteration.number", data.Iteration), - attribute.Int64("test.vu", int64(data.VUID)), + attribute.Int64("test.vu", int64(data.VUID)), //nolint:gosec attribute.String("test.scenario", data.ScenarioName), )) diff --git a/vendor/github.com/grafana/xk6-browser/browser/response_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/response_mapping.go index 6bc43756516..cd74675a15f 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/response_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/response_mapping.go @@ -8,7 +8,7 @@ import ( ) // mapResponse to the JS module. -func mapResponse(vu moduleVU, r *common.Response) mapping { //nolint:funlen +func mapResponse(vu moduleVU, r *common.Response) mapping { if r == nil { return nil } diff --git a/vendor/github.com/grafana/xk6-browser/browser/sync_browser_context_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/sync_browser_context_mapping.go index 8873c40deeb..7a737c9f1b6 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/sync_browser_context_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/sync_browser_context_mapping.go @@ -12,7 +12,7 @@ import ( ) // syncMapBrowserContext is like mapBrowserContext but returns synchronous functions. -func syncMapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolint:funlen,gocognit,cyclop +func syncMapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolint:funlen,gocognit rt := vu.Runtime() return mapping{ "addCookies": bc.AddCookies, diff --git a/vendor/github.com/grafana/xk6-browser/browser/sync_browser_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/sync_browser_mapping.go index d9c8fd1e284..3205043b576 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/sync_browser_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/sync_browser_mapping.go @@ -7,7 +7,7 @@ import ( ) // syncMapBrowser is like mapBrowser but returns synchronous functions. -func syncMapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop +func syncMapBrowser(vu moduleVU) mapping { //nolint:funlen rt := vu.Runtime() return mapping{ "context": func() (mapping, error) { diff --git a/vendor/github.com/grafana/xk6-browser/browser/sync_element_handle_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/sync_element_handle_mapping.go index e9375f10011..924ae372942 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/sync_element_handle_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/sync_element_handle_mapping.go @@ -10,7 +10,7 @@ import ( ) // syncMapElementHandle is like mapElementHandle but returns synchronous functions. -func syncMapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint:gocognit,cyclop,funlen +func syncMapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint:gocognit,funlen rt := vu.Runtime() maps := mapping{ "boundingBox": eh.BoundingBox, diff --git a/vendor/github.com/grafana/xk6-browser/browser/sync_frame_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/sync_frame_mapping.go index 0cde428594c..d2a70227242 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/sync_frame_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/sync_frame_mapping.go @@ -10,7 +10,7 @@ import ( ) // syncMapFrame is like mapFrame but returns synchronous functions. -func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop,funlen +func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,funlen rt := vu.Runtime() maps := mapping{ "check": f.Check, diff --git a/vendor/github.com/grafana/xk6-browser/browser/sync_locator_mapping.go b/vendor/github.com/grafana/xk6-browser/browser/sync_locator_mapping.go index fa15bf502dc..309f4758208 100644 --- a/vendor/github.com/grafana/xk6-browser/browser/sync_locator_mapping.go +++ b/vendor/github.com/grafana/xk6-browser/browser/sync_locator_mapping.go @@ -10,7 +10,7 @@ import ( ) // syncMapLocator is like mapLocator but returns synchronous functions. -func syncMapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen +func syncMapLocator(vu moduleVU, lo *common.Locator) mapping { return mapping{ "clear": func(opts sobek.Value) error { ctx := vu.Context() diff --git a/vendor/github.com/grafana/xk6-browser/common/browser.go b/vendor/github.com/grafana/xk6-browser/common/browser.go index 902fc5d450d..c8335e60166 100644 --- a/vendor/github.com/grafana/xk6-browser/common/browser.go +++ b/vendor/github.com/grafana/xk6-browser/common/browser.go @@ -126,7 +126,7 @@ func newBrowser( browserCancelFn: cancelFn, vuCtx: vuCtx, vuCtxCancelFn: vuCtxCancelFn, - state: int64(BrowserStateOpen), + state: BrowserStateOpen, browserProc: browserProc, browserOpts: browserOpts, pages: make(map[target.ID]*Page), @@ -201,7 +201,7 @@ func (b *Browser) getPages() []*Page { return pages } -func (b *Browser) initEvents() error { //nolint:cyclop +func (b *Browser) initEvents() error { chHandler := make(chan Event) // Using the internal context here. Using vuCtx would close the connection/subprocess @@ -469,10 +469,10 @@ func (b *Browser) newPageInContext(id cdp.BrowserContextID) (*Page, error) { tid := <-targetID b.logger.Debugf("Browser:newPageInContext:createWaitForEventHandler", - "tid:%v ptid:%v bctxid:%v", tid, e.(*Page).targetID, id) + "tid:%v ptid:%v bctxid:%v", tid, e.(*Page).targetID, id) //nolint:forcetypeassert // we are only interested in the new page. - return e.(*Page).targetID == tid + return e.(*Page).targetID == tid //nolint:forcetypeassert }, ) defer removeEventHandler() diff --git a/vendor/github.com/grafana/xk6-browser/common/browser_context.go b/vendor/github.com/grafana/xk6-browser/common/browser_context.go index a1e2bccf817..400c268e832 100644 --- a/vendor/github.com/grafana/xk6-browser/common/browser_context.go +++ b/vendor/github.com/grafana/xk6-browser/common/browser_context.go @@ -101,7 +101,7 @@ func (b *BrowserContext) setDownloadsPath(path string) error { b.DownloadsPath = path return nil } - dir, err := os.MkdirTemp(os.TempDir(), artifactsDirectory+"*") + dir, err := os.MkdirTemp(os.TempDir(), artifactsDirectory+"*") //nolint:forbidigo if err != nil { return fmt.Errorf("creating temporary directory for downloads: %w", err) } diff --git a/vendor/github.com/grafana/xk6-browser/common/browser_options.go b/vendor/github.com/grafana/xk6-browser/common/browser_options.go index 2a0c26282aa..0d9a226a2bb 100644 --- a/vendor/github.com/grafana/xk6-browser/common/browser_options.go +++ b/vendor/github.com/grafana/xk6-browser/common/browser_options.go @@ -55,7 +55,7 @@ func NewRemoteBrowserOptions() *BrowserOptions { } // Parse parses browser options from a JS object. -func (bo *BrowserOptions) Parse( //nolint:cyclop +func (bo *BrowserOptions) Parse( ctx context.Context, logger *log.Logger, opts map[string]any, envLookup env.LookupFunc, ) error { // Parse opts diff --git a/vendor/github.com/grafana/xk6-browser/common/browser_process.go b/vendor/github.com/grafana/xk6-browser/common/browser_process.go index 0a82bb566e1..a28bf672949 100644 --- a/vendor/github.com/grafana/xk6-browser/common/browser_process.go +++ b/vendor/github.com/grafana/xk6-browser/common/browser_process.go @@ -169,7 +169,7 @@ func execute( // We must start the cmd before calling cmd.Wait, as otherwise the two // can run into a data race. err = cmd.Start() - if os.IsNotExist(err) { + if os.IsNotExist(err) { //nolint:forbidigo return command{}, fmt.Errorf("file does not exist: %s", path) } if err != nil { diff --git a/vendor/github.com/grafana/xk6-browser/common/browser_process_meta.go b/vendor/github.com/grafana/xk6-browser/common/browser_process_meta.go index 9124a75021e..ce5c499f684 100644 --- a/vendor/github.com/grafana/xk6-browser/common/browser_process_meta.go +++ b/vendor/github.com/grafana/xk6-browser/common/browser_process_meta.go @@ -21,14 +21,14 @@ type browserProcessMeta interface { // localBrowserProcessMeta holds the metadata for local // browser process. type localBrowserProcessMeta struct { - process *os.Process + process *os.Process //nolint:forbidigo userDataDir *storage.Dir } // newLocalBrowserProcessMeta returns a new BrowserProcessMeta // for the given OS process and storage directory. func newLocalBrowserProcessMeta( - process *os.Process, userDataDir *storage.Dir, + process *os.Process, userDataDir *storage.Dir, //nolint:forbidigo ) *localBrowserProcessMeta { return &localBrowserProcessMeta{ process, diff --git a/vendor/github.com/grafana/xk6-browser/common/connection.go b/vendor/github.com/grafana/xk6-browser/common/connection.go index b28c6e4ba72..f6eca67016f 100644 --- a/vendor/github.com/grafana/xk6-browser/common/connection.go +++ b/vendor/github.com/grafana/xk6-browser/common/connection.go @@ -157,7 +157,12 @@ func NewConnection( ctx, cancelCtx := context.WithCancel(ctx) - conn, _, connErr := wsd.DialContext(ctx, wsURL, header) + conn, response, connErr := wsd.DialContext(ctx, wsURL, header) + if response != nil { + defer func() { + _ = response.Body.Close() + }() + } if connErr != nil { cancelCtx() return nil, connErr @@ -251,18 +256,21 @@ func (c *Connection) closeAllSessions() { } func (c *Connection) createSession(info *target.Info) (*Session, error) { - c.logger.Debugf("Connection:createSession", "tid:%v bctxid:%v type:%s", info.TargetID, info.BrowserContextID, info.Type) + c.logger.Debugf("Connection:createSession", "tid:%v bctxid:%v type:%s", + info.TargetID, info.BrowserContextID, info.Type) var sessionID target.SessionID var err error action := target.AttachToTarget(info.TargetID).WithFlatten(true) if sessionID, err = action.Do(cdp.WithExecutor(c.ctx, c)); err != nil { - c.logger.Debugf("Connection:createSession", "tid:%v bctxid:%v type:%s err:%v", info.TargetID, info.BrowserContextID, info.Type, err) + c.logger.Debugf("Connection:createSession", "tid:%v bctxid:%v type:%s err:%v", + info.TargetID, info.BrowserContextID, info.Type, err) return nil, err } sess := c.getSession(sessionID) if sess == nil { - c.logger.Warnf("Connection:createSession", "tid:%v bctxid:%v type:%s sid:%v, session is nil", info.TargetID, info.BrowserContextID, info.Type, sessionID) + c.logger.Warnf("Connection:createSession", "tid:%v bctxid:%v type:%s sid:%v, session is nil", + info.TargetID, info.BrowserContextID, info.Type, sessionID) } return sess, nil } @@ -317,6 +325,7 @@ func (c *Connection) findTargetIDForLog(id target.SessionID) target.ID { return s.targetID } +//nolint:funlen,gocognit,cyclop func (c *Connection) recvLoop() { c.logger.Debugf("Connection:recvLoop", "wsURL:%q", c.wsURL) for { @@ -343,13 +352,14 @@ func (c *Connection) recvLoop() { // Handle attachment and detachment from targets, // creating and deleting sessions as necessary. + //nolint:nestif if msg.Method == cdproto.EventTargetAttachedToTarget { ev, err := cdproto.UnmarshalMessage(&msg) if err != nil { c.logger.Errorf("cdp", "%s", err) continue } - eva := ev.(*target.EventAttachedToTarget) + eva := ev.(*target.EventAttachedToTarget) //nolint:forcetypeassert sid, tid := eva.SessionID, eva.TargetInfo.TargetID if c.onTargetAttachedToTarget != nil { @@ -373,7 +383,7 @@ func (c *Connection) recvLoop() { c.logger.Errorf("cdp", "%s", err) continue } - evt := ev.(*target.EventDetachedFromTarget) + evt := ev.(*target.EventDetachedFromTarget) //nolint:forcetypeassert sid := evt.SessionID tid := c.findTargetIDForLog(sid) ok := c.closeSession(sid, tid) @@ -396,7 +406,8 @@ func (c *Connection) recvLoop() { continue } if msg.Error != nil && msg.Error.Message == "No session with given id" { - c.logger.Debugf("Connection:recvLoop", "sid:%v tid:%v wsURL:%q, closeSession #2", session.id, session.targetID, c.wsURL) + c.logger.Debugf("Connection:recvLoop", "sid:%v tid:%v wsURL:%q, closeSession #2", + session.id, session.targetID, c.wsURL) c.closeSession(session.id, session.targetID) continue } @@ -404,10 +415,12 @@ func (c *Connection) recvLoop() { select { case session.readCh <- &msg: case code := <-c.closeCh: - c.logger.Debugf("Connection:recvLoop:<-c.closeCh", "sid:%v tid:%v wsURL:%v crashed:%t", session.id, session.targetID, c.wsURL, session.crashed) + c.logger.Debugf("Connection:recvLoop:<-c.closeCh", "sid:%v tid:%v wsURL:%v crashed:%t", + session.id, session.targetID, c.wsURL, session.crashed) _ = c.close(code) case <-c.done: - c.logger.Debugf("Connection:recvLoop:<-c.done", "sid:%v tid:%v wsURL:%v crashed:%t", session.id, session.targetID, c.wsURL, session.crashed) + c.logger.Debugf("Connection:recvLoop:<-c.done", "sid:%v tid:%v wsURL:%v crashed:%t", + session.id, session.targetID, c.wsURL, session.crashed) return } @@ -425,7 +438,8 @@ func (c *Connection) recvLoop() { c.emit("", &msg) default: - c.logger.Errorf("cdp", "ignoring malformed incoming message (missing id or method): %#v (message: %s)", msg, msg.Error.Message) + c.logger.Errorf("cdp", "ignoring malformed incoming message (missing id or method): %#v (message: %s)", + msg, msg.Error.Message) } } } @@ -455,7 +469,9 @@ func (c *Connection) stopWaitingForDebugger(sid target.SessionID) { } } -func (c *Connection) send(ctx context.Context, msg *cdproto.Message, recvCh chan *cdproto.Message, res easyjson.Unmarshaler) error { +func (c *Connection) send( + ctx context.Context, msg *cdproto.Message, recvCh chan *cdproto.Message, res easyjson.Unmarshaler, +) error { select { case c.sendCh <- msg: case err := <-c.errorCh: @@ -500,16 +516,19 @@ func (c *Connection) send(ctx context.Context, msg *cdproto.Message, recvCh chan c.logger.Debugf("Connection:send:<-c.errorCh #2", "sid:%v tid:%v wsURL:%q, err:%v", msg.SessionID, tid, c.wsURL, err) return err case code := <-c.closeCh: - c.logger.Debugf("Connection:send:<-c.closeCh #2", "sid:%v tid:%v wsURL:%q, websocket code:%v", msg.SessionID, tid, c.wsURL, code) + c.logger.Debugf("Connection:send:<-c.closeCh #2", "sid:%v tid:%v wsURL:%q, websocket code:%v", + msg.SessionID, tid, c.wsURL, code) _ = c.close(code) return &websocket.CloseError{Code: code} case <-c.done: c.logger.Debugf("Connection:send:<-c.done #2", "sid:%v tid:%v wsURL:%q", msg.SessionID, tid, c.wsURL) case <-ctx.Done(): - c.logger.Debugf("Connection:send:<-ctx.Done()", "sid:%v tid:%v wsURL:%q err:%v", msg.SessionID, tid, c.wsURL, c.ctx.Err()) + c.logger.Debugf("Connection:send:<-ctx.Done()", "sid:%v tid:%v wsURL:%q err:%v", + msg.SessionID, tid, c.wsURL, c.ctx.Err()) return ctx.Err() case <-c.ctx.Done(): - c.logger.Debugf("Connection:send:<-c.ctx.Done()", "sid:%v tid:%v wsURL:%q err:%v", msg.SessionID, tid, c.wsURL, c.ctx.Err()) + c.logger.Debugf("Connection:send:<-c.ctx.Done()", "sid:%v tid:%v wsURL:%q err:%v", + msg.SessionID, tid, c.wsURL, c.ctx.Err()) return c.ctx.Err() } return nil @@ -574,7 +593,9 @@ func (c *Connection) Close() { } // Execute implements cdproto.Executor and performs a synchronous send and receive. -func (c *Connection) Execute(ctx context.Context, method string, params easyjson.Marshaler, res easyjson.Unmarshaler) error { +func (c *Connection) Execute( + ctx context.Context, method string, params easyjson.Marshaler, res easyjson.Unmarshaler, +) error { c.logger.Debugf("connection:Execute", "wsURL:%q method:%q", c.wsURL, method) id := c.msgIDGen.newID() diff --git a/vendor/github.com/grafana/xk6-browser/common/context.go b/vendor/github.com/grafana/xk6-browser/common/context.go index 0dc76ab3c48..f5cdc9bf097 100644 --- a/vendor/github.com/grafana/xk6-browser/common/context.go +++ b/vendor/github.com/grafana/xk6-browser/common/context.go @@ -22,7 +22,7 @@ func GetHooks(ctx context.Context) *Hooks { if v == nil { return nil } - return v.(*Hooks) + return v.(*Hooks) //nolint:forcetypeassert } // WithIterationID adds an identifier for the current iteration to the context. diff --git a/vendor/github.com/grafana/xk6-browser/common/device.go b/vendor/github.com/grafana/xk6-browser/common/device.go index 9021197299e..fbd3aca272a 100644 --- a/vendor/github.com/grafana/xk6-browser/common/device.go +++ b/vendor/github.com/grafana/xk6-browser/common/device.go @@ -11,6 +11,8 @@ type Device struct { } // GetDevices returns predefined emulation settings for many end-user devices. +// +//nolint:lll,funlen func GetDevices() map[string]Device { return map[string]Device{ "Blackberry PlayBook": { diff --git a/vendor/github.com/grafana/xk6-browser/common/element_handle.go b/vendor/github.com/grafana/xk6-browser/common/element_handle.go index e612920e5bf..faf31404741 100644 --- a/vendor/github.com/grafana/xk6-browser/common/element_handle.go +++ b/vendor/github.com/grafana/xk6-browser/common/element_handle.go @@ -17,6 +17,8 @@ import ( "github.com/grafana/xk6-browser/common/js" "github.com/grafana/xk6-browser/k6ext" + + k6common "go.k6.io/k6/js/common" ) const ( @@ -356,6 +358,7 @@ func (h *ElementHandle) innerText(apiCtx context.Context) (any, error) { } func (h *ElementHandle) inputValue(apiCtx context.Context) (any, error) { + //nolint:lll js := ` (element) => { if (element.nodeType !== Node.ELEMENT_NODE || (element.nodeName !== 'INPUT' && element.nodeName !== 'TEXTAREA' && element.nodeName !== 'SELECT')) { @@ -476,10 +479,10 @@ func (h *ElementHandle) press(apiCtx context.Context, key string, opts KeyboardO return nil } -//nolint:funlen,gocognit,cyclop +//nolint:funlen,gocognit func (h *ElementHandle) selectOption(apiCtx context.Context, values sobek.Value) (any, error) { convertSelectOptionValues := func(values sobek.Value) ([]any, error) { - if sobek.IsNull(values) || sobek.IsUndefined(values) { + if k6common.IsNullish(values) { return nil, nil } @@ -489,40 +492,43 @@ func (h *ElementHandle) selectOption(apiCtx context.Context, values sobek.Value) rt = h.execCtx.vu.Runtime() ) switch values.ExportType().Kind() { - case reflect.Map: - s := reflect.ValueOf(t) - for i := 0; i < s.Len(); i++ { - item := s.Index(i) - switch item.Kind() { - case reflect.TypeOf(nil).Kind(): - return nil, fmt.Errorf("options[%d]: expected object, got null", i) - case reflect.TypeOf(&ElementHandle{}).Kind(): - opts = append(opts, t.(*ElementHandle)) - case reflect.TypeOf(sobek.Object{}).Kind(): - obj := values.ToObject(rt) - opt := SelectOption{} - for _, k := range obj.Keys() { - switch k { - case "value": - opt.Value = new(string) - *opt.Value = obj.Get(k).String() - case "label": - opt.Label = new(string) - *opt.Label = obj.Get(k).String() - case "index": - opt.Index = new(int64) - *opt.Index = obj.Get(k).ToInteger() - } - } - opts = append(opts, &opt) - case reflect.String: + case reflect.Slice: + var sl []interface{} + if err := rt.ExportTo(values, &sl); err != nil { + return nil, fmt.Errorf("options: expected array, got %T", values) + } + + for _, item := range sl { + switch item := item.(type) { + case string: opt := SelectOption{Value: new(string)} - *opt.Value = item.String() + *opt.Value = item opts = append(opts, &opt) + case map[string]interface{}: + opt, err := extractSelectOptionFromMap(item) + if err != nil { + return nil, err + } + + opts = append(opts, opt) + default: + return nil, fmt.Errorf("options: expected string or object, got %T", item) } } + case reflect.Map: + var raw map[string]interface{} + if err := rt.ExportTo(values, &raw); err != nil { + return nil, fmt.Errorf("options: expected object, got %T", values) + } + + opt, err := extractSelectOptionFromMap(raw) + if err != nil { + return nil, err + } + + opts = append(opts, opt) case reflect.TypeOf(&ElementHandle{}).Kind(): - opts = append(opts, t.(*ElementHandle)) + opts = append(opts, t.(*ElementHandle)) //nolint:forcetypeassert case reflect.TypeOf(sobek.Object{}).Kind(): obj := values.ToObject(rt) opt := SelectOption{} @@ -542,8 +548,10 @@ func (h *ElementHandle) selectOption(apiCtx context.Context, values sobek.Value) opts = append(opts, &opt) case reflect.String: opt := SelectOption{Value: new(string)} - *opt.Value = t.(string) + *opt.Value = t.(string) //nolint:forcetypeassert opts = append(opts, &opt) + default: + return nil, fmt.Errorf("options: unsupported type %T", values) } return opts, nil @@ -562,12 +570,12 @@ func (h *ElementHandle) selectOption(apiCtx context.Context, values sobek.Value) forceCallable: true, returnByValue: false, } - result, err := h.evalWithScript(apiCtx, opts, fn, convValues) + result, err := h.evalWithScript(apiCtx, opts, fn, convValues) //nolint:asasalint if err != nil { return nil, err } - switch result := result.(type) { - case string: // An error happened (returned as "error:..." from JS) + if result, ok := result.(string); ok { + // An error happened (returned as "error:..." from JS) if result != resultDone { return nil, errorFromDOMError(result) } @@ -575,6 +583,44 @@ func (h *ElementHandle) selectOption(apiCtx context.Context, values sobek.Value) return result, nil } +func extractSelectOptionFromMap(v map[string]interface{}) (*SelectOption, error) { + opt := &SelectOption{} + for k, raw := range v { + switch k { + case "value": + opt.Value = new(string) + + v, ok := raw.(string) + if !ok { + return nil, fmt.Errorf("options[%v]: expected string, got %T", k, raw) + } + + *opt.Value = v + case "label": + opt.Label = new(string) + + v, ok := raw.(string) + if !ok { + return nil, fmt.Errorf("options[%v]: expected string, got %T", k, raw) + } + *opt.Label = v + case "index": + opt.Index = new(int64) + + switch raw := raw.(type) { + case int: + *opt.Index = int64(raw) + case int64: + *opt.Index = raw + default: + return nil, fmt.Errorf("options[%v]: expected int, got %T", k, raw) + } + } + } + + return opt, nil +} + func (h *ElementHandle) selectText(apiCtx context.Context) error { fn := ` (node, injected) => { @@ -589,8 +635,7 @@ func (h *ElementHandle) selectText(apiCtx context.Context) error { if err != nil { return err } - switch result := result.(type) { - case string: // Either we're done or an error happened (returned as "error:..." from JS) + if result, ok := result.(string); ok { if result != resultDone { return errorFromDOMError(result) } @@ -676,7 +721,9 @@ func (h *ElementHandle) waitForElementState( "waiting for states %v of element %q", states, reflect.TypeOf(result)) } -func (h *ElementHandle) waitForSelector(apiCtx context.Context, selector string, opts *FrameWaitForSelectorOptions) (*ElementHandle, error) { +func (h *ElementHandle) waitForSelector( + apiCtx context.Context, selector string, opts *FrameWaitForSelectorOptions, +) (*ElementHandle, error) { parsedSelector, err := NewSelector(selector) if err != nil { return nil, err @@ -702,7 +749,7 @@ func (h *ElementHandle) waitForSelector(apiCtx context.Context, selector string, case *ElementHandle: return r, nil default: - return nil, nil + return nil, nil //nolint:nilnil } } @@ -1270,7 +1317,7 @@ func (h *ElementHandle) Screenshot( span.SetAttributes(attribute.String("screenshot.path", opts.Path)) - s := newScreenshotter(spanCtx, sp) + s := newScreenshotter(spanCtx, sp, h.logger) buf, err := s.screenshotElement(h, opts) if err != nil { err := fmt.Errorf("taking screenshot of elementHandle: %w", err) @@ -1571,7 +1618,7 @@ func (h *ElementHandle) newAction( } } -//nolint:funlen,gocognit,cyclop +//nolint:funlen,gocognit func (h *ElementHandle) newPointerAction( fn elementHandlePointerActionFunc, opts *ElementHandleBasePointerOptions, ) func(apiCtx context.Context, resultCh chan any, errCh chan error) { diff --git a/vendor/github.com/grafana/xk6-browser/common/element_handle_options.go b/vendor/github.com/grafana/xk6-browser/common/element_handle_options.go index 91417fe7cb7..fa1ef179a3b 100644 --- a/vendor/github.com/grafana/xk6-browser/common/element_handle_options.go +++ b/vendor/github.com/grafana/xk6-browser/common/element_handle_options.go @@ -152,7 +152,7 @@ func (o *ElementHandleBaseOptions) Parse(ctx context.Context, opts sobek.Value) switch k { case "force": o.Force = gopts.Get(k).ToBoolean() - case "noWaitAfter": //nolint:goconst + case "noWaitAfter": o.NoWaitAfter = gopts.Get(k).ToBoolean() case "timeout": o.Timeout = time.Duration(gopts.Get(k).ToInteger()) * time.Millisecond @@ -220,7 +220,7 @@ func (f *Files) addFile(ctx context.Context, file sobek.Value) error { } rt := k6ext.Runtime(ctx) fileType := file.ExportType() - switch fileType.Kind() { //nolint:exhaustive + switch fileType.Kind() { case reflect.Map: // file descriptor object var parsedFile File if err := rt.ExportTo(file, &parsedFile); err != nil { @@ -242,7 +242,7 @@ func (f *Files) Parse(ctx context.Context, files sobek.Value) error { } optsType := files.ExportType() - switch optsType.Kind() { //nolint:exhaustive + switch optsType.Kind() { case reflect.Slice: // array of filePaths or array of file descriptor objects gopts := files.ToObject(rt) for _, k := range gopts.Keys() { @@ -376,8 +376,7 @@ func (o *ElementHandleHoverOptions) Parse(ctx context.Context, opts sobek.Value) if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { - switch k { - case "modifiers": + if k == "modifiers" { var m []string if err := rt.ExportTo(opts.Get(k), &m); err != nil { return err @@ -435,7 +434,7 @@ func NewElementHandleScreenshotOptions(defaultTimeout time.Duration) *ElementHan } // Parse parses the ElementHandleScreenshotOptions from the given opts. -func (o *ElementHandleScreenshotOptions) Parse(ctx context.Context, opts sobek.Value) error { //nolint:cyclop +func (o *ElementHandleScreenshotOptions) Parse(ctx context.Context, opts sobek.Value) error { if !sobekValueExists(opts) { return nil } @@ -489,8 +488,7 @@ func (o *ElementHandleSetCheckedOptions) Parse(ctx context.Context, opts sobek.V if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { - switch k { - case "strict": + if k == "strict" { o.Strict = opts.Get(k).ToBoolean() } } @@ -514,8 +512,7 @@ func (o *ElementHandleTapOptions) Parse(ctx context.Context, opts sobek.Value) e if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { - switch k { - case "modifiers": + if k == "modifiers" { var m []string if err := rt.ExportTo(opts.Get(k), &m); err != nil { return err @@ -574,8 +571,7 @@ func (o *ElementHandleWaitForElementStateOptions) Parse(ctx context.Context, opt if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { - switch k { - case "timeout": + if k == "timeout" { o.Timeout = time.Duration(opts.Get(k).ToInteger()) * time.Millisecond } } diff --git a/vendor/github.com/grafana/xk6-browser/common/errors.go b/vendor/github.com/grafana/xk6-browser/common/errors.go index cfcc6491b43..988a3ac0022 100644 --- a/vendor/github.com/grafana/xk6-browser/common/errors.go +++ b/vendor/github.com/grafana/xk6-browser/common/errors.go @@ -37,11 +37,8 @@ func (e BigIntParseError) Error() string { // Is satisfies the builtin error Is interface. func (e BigIntParseError) Is(target error) bool { - switch target.(type) { - case BigIntParseError: - return true - } - return false + _, ok := target.(BigIntParseError) + return ok } // Unwrap satisfies the builtin error Unwrap interface. diff --git a/vendor/github.com/grafana/xk6-browser/common/execution_context.go b/vendor/github.com/grafana/xk6-browser/common/execution_context.go index 749897e8b87..6e0f9b5f728 100644 --- a/vendor/github.com/grafana/xk6-browser/common/execution_context.go +++ b/vendor/github.com/grafana/xk6-browser/common/execution_context.go @@ -154,6 +154,8 @@ func (e *ExecutionContext) adoptElementHandle(eh *ElementHandle) (*ElementHandle // eval evaluates the provided JavaScript within this execution context and // returns a value or handle. +// +//nolint:funlen func (e *ExecutionContext) eval( apiCtx context.Context, opts evalOptions, js string, args ...any, ) (any, error) { @@ -307,9 +309,7 @@ func (e *ExecutionContext) Eval(apiCtx context.Context, js string, args ...any) returnByValue: true, } evalArgs := make([]any, 0, len(args)) - for _, a := range args { - evalArgs = append(evalArgs, a) - } + evalArgs = append(evalArgs, args...) return e.eval(apiCtx, opts, js, evalArgs...) } @@ -325,9 +325,7 @@ func (e *ExecutionContext) EvalHandle(apiCtx context.Context, js string, args .. returnByValue: false, } evalArgs := make([]any, 0, len(args)) - for _, a := range args { - evalArgs = append(evalArgs, a) - } + evalArgs = append(evalArgs, args...) res, err := e.eval(apiCtx, opts, js, evalArgs...) if err != nil { return nil, err diff --git a/vendor/github.com/grafana/xk6-browser/common/frame.go b/vendor/github.com/grafana/xk6-browser/common/frame.go index 7f35757f62b..a627794a26c 100644 --- a/vendor/github.com/grafana/xk6-browser/common/frame.go +++ b/vendor/github.com/grafana/xk6-browser/common/frame.go @@ -182,25 +182,6 @@ func (f *Frame) deleteRequest(id network.RequestID) { delete(f.inflightRequests, id) } -func (f *Frame) inflightRequestsLen() int { - f.inflightRequestsMu.RLock() - defer f.inflightRequestsMu.RUnlock() - - return len(f.inflightRequests) -} - -func (f *Frame) cloneInflightRequests() map[network.RequestID]bool { - f.inflightRequestsMu.RLock() - defer f.inflightRequestsMu.RUnlock() - - ifr := make(map[network.RequestID]bool) - for k, v := range f.inflightRequests { - ifr[k] = v - } - - return ifr -} - func (f *Frame) clearLifecycle() { f.log.Debugf("Frame:clearLifecycle", "fid:%s furl:%q", f.ID(), f.URL()) @@ -411,37 +392,6 @@ func (f *Frame) removeChildFrame(child *Frame) { delete(f.childFrames, child) } -func (f *Frame) requestByID(reqID network.RequestID) (*Request, bool) { - frameSession := f.page.getFrameSession(cdp.FrameID(f.ID())) - if frameSession != nil { - if frameSession.networkManager == nil { - f.log.Warnf("Frame:requestByID:nil:frameSession.networkManager", "fid:%s furl:%q rid:%s", - f.ID(), f.URL(), reqID) - } - return frameSession.networkManager.requestFromID(reqID) - } - - f.log.Debugf("Frame:requestByID:nil:frameSession", "fid:%s furl:%q rid:%s", - f.ID(), f.URL(), reqID) - - // For unknown reasons mainFrameSession or mainFrameSession.networkManager - // (it's unknown exactly which one) are nil, which has caused NPDs. We're - // now logging to see what components are nil to try and work out what is - // causing the NPD. - - if f.page.mainFrameSession == nil { - f.log.Warnf("Frame:requestByID:nil:mainFrameSession", "fid:%s furl:%q rid:%s", - f.ID(), f.URL(), reqID) - } - - if f.page.mainFrameSession.networkManager == nil { - f.log.Warnf("Frame:requestByID:nil:mainFrameSession.networkManager", "fid:%s furl:%q rid:%s", - f.ID(), f.URL(), reqID) - } - - return frameSession.networkManager.requestFromID(reqID) -} - func (f *Frame) setContext(world executionWorld, execCtx frameExecutionContext) { f.executionContextMu.Lock() defer f.executionContextMu.Unlock() @@ -565,7 +515,9 @@ func (f *Frame) waitForSelector(selector string, opts *FrameWaitForSelectorOptio return handle, nil } -func (f *Frame) waitFor(selector string, opts *FrameWaitForSelectorOptions, retryCount int) (_ *ElementHandle, rerr error) { +func (f *Frame) waitFor( + selector string, opts *FrameWaitForSelectorOptions, retryCount int, +) (_ *ElementHandle, rerr error) { f.log.Debugf("Frame:waitFor", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) retryCount-- @@ -1823,7 +1775,7 @@ func (f *Frame) WaitForFunction(js string, opts *FrameWaitForFunctionOptions, js // prevent passing a non-nil interface to the upper layers. if result == nil { - return nil, nil + return nil, nil //nolint:nilnil } return result, err @@ -1880,7 +1832,7 @@ func (f *Frame) waitForFunction( } // prevent passing a non-nil interface to the upper layers. if result == nil { - return nil, nil + return nil, nil //nolint:nilnil } return result, nil @@ -1934,7 +1886,7 @@ func (f *Frame) WaitForLoadState(state string, opts sobek.Value) error { // WaitForNavigation waits for the given navigation lifecycle event to happen. // -//nolint:funlen,cyclop +//nolint:funlen func (f *Frame) WaitForNavigation(opts *FrameWaitForNavigationOptions) (*Response, error) { f.log.Debugf("Frame:WaitForNavigation", "fid:%s furl:%s", f.ID(), f.URL()) @@ -2014,7 +1966,7 @@ func (f *Frame) WaitForNavigation(opts *FrameWaitForNavigationOptions) (*Respons // Since response will be in an interface, it will never be nil, // so we need to return nil explicitly. if resp == nil { - return nil, nil + return nil, nil //nolint:nilnil } return resp, nil diff --git a/vendor/github.com/grafana/xk6-browser/common/frame_manager.go b/vendor/github.com/grafana/xk6-browser/common/frame_manager.go index 0a675b6664a..9397839c3d5 100644 --- a/vendor/github.com/grafana/xk6-browser/common/frame_manager.go +++ b/vendor/github.com/grafana/xk6-browser/common/frame_manager.go @@ -44,7 +44,7 @@ type FrameManager struct { } // frameManagerID is used for giving a unique ID to a frame manager. -var frameManagerID int64 +var frameManagerID int64 //nolint:gochecknoglobals // TODO(@mstoykov): move it to the module instance // NewFrameManager creates a new HTML document frame manager. func NewFrameManager( @@ -233,7 +233,10 @@ func (m *FrameManager) frameLoadingStopped(frameID cdp.FrameID) { } } -func (m *FrameManager) frameNavigated(frameID cdp.FrameID, parentFrameID cdp.FrameID, documentID string, name string, url string, initial bool) error { +//nolint:funlen +func (m *FrameManager) frameNavigated( + frameID cdp.FrameID, parentFrameID cdp.FrameID, documentID string, name string, url string, initial bool, +) error { m.logger.Debugf("FrameManager:frameNavigated", "fmid:%d fid:%v pfid:%v docid:%s fname:%s furl:%s initial:%t", m.ID(), frameID, parentFrameID, documentID, name, url, initial) @@ -389,7 +392,10 @@ func (m *FrameManager) frameRequestedNavigation(frameID cdp.FrameID, url string, m.logger.Debugf("FrameManager:frameRequestedNavigation:nilFrame:return", "fmid:%d fid:%v url:%s docid:%s", m.ID(), frameID, url, documentID) - return fmt.Errorf("no frame exists with ID %s", frameID) + // If a frame doesn't exist then the call to this method (which + // originates from a EventFrameRequestedNavigation CDP event) is on a + // stale frame that no longer exists in memory. + return nil } m.barriersMu.RLock() @@ -599,7 +605,7 @@ func (m *FrameManager) MainFrameURL() string { // NavigateFrame will navigate specified frame to specified URL. // -//nolint:funlen,cyclop +//nolint:funlen func (m *FrameManager) NavigateFrame(frame *Frame, url string, parsedOpts *FrameGotoOptions) (*Response, error) { var ( fmid = m.ID() @@ -672,7 +678,7 @@ func (m *FrameManager) NavigateFrame(frame *Frame, url string, parsedOpts *Frame // It's a navigation within the same document (e.g. via anchor links or // the History API), so don't wait for a response nor any lifecycle // events. - return nil, nil + return nil, nil //nolint:nilnil } // unblock the waiter goroutine diff --git a/vendor/github.com/grafana/xk6-browser/common/frame_options.go b/vendor/github.com/grafana/xk6-browser/common/frame_options.go index f0e4dced802..d1069151c35 100644 --- a/vendor/github.com/grafana/xk6-browser/common/frame_options.go +++ b/vendor/github.com/grafana/xk6-browser/common/frame_options.go @@ -626,7 +626,7 @@ func (o *FrameWaitForFunctionOptions) Parse(ctx context.Context, opts sobek.Valu case "timeout": o.Timeout = time.Duration(v.ToInteger()) * time.Millisecond case "polling": - switch v.ExportType().Kind() { //nolint: exhaustive + switch v.ExportType().Kind() { case reflect.Int64: o.Polling = PollingInterval o.Interval = v.ToInteger() @@ -658,8 +658,7 @@ func (o *FrameWaitForLoadStateOptions) Parse(ctx context.Context, opts sobek.Val if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { - switch k { - case "timeout": + if k == "timeout" { o.Timeout = time.Duration(opts.Get(k).ToInteger()) * time.Millisecond } } diff --git a/vendor/github.com/grafana/xk6-browser/common/frame_session.go b/vendor/github.com/grafana/xk6-browser/common/frame_session.go index fbdd85903d6..c4df0a6ff65 100644 --- a/vendor/github.com/grafana/xk6-browser/common/frame_session.go +++ b/vendor/github.com/grafana/xk6-browser/common/frame_session.go @@ -64,6 +64,7 @@ type FrameSession struct { // To understand the concepts of Isolated Worlds, Contexts and Frames and // the relationship betwween them have a look at the following doc: + //nolint:lll // https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/bindings/core/v8/V8BindingDesign.md contextIDToContextMu sync.Mutex contextIDToContext map[cdpruntime.ExecutionContextID]*ExecutionContext @@ -224,6 +225,7 @@ func (fs *FrameSession) initDomains() error { return nil } +//nolint:funlen,cyclop func (fs *FrameSession) initEvents() { fs.logger.Debugf("NewFrameSession:initEvents", "sid:%v tid:%v", fs.session.ID(), fs.targetID) @@ -269,7 +271,7 @@ func (fs *FrameSession) initEvents() { case event := <-fs.eventCh: switch ev := event.data.(type) { case *inspector.EventTargetCrashed: - fs.onTargetCrashed(ev) + fs.onTargetCrashed() case *cdplog.EventEntryAdded: fs.onLogEntryAdded(ev) case *cdppage.EventFrameAttached: @@ -552,18 +554,10 @@ func (fs *FrameSession) initOptions() error { if err := fs.updateHTTPCredentials(true); err != nil { return err } - if err := fs.updateEmulateMedia(true); err != nil { + if err := fs.updateEmulateMedia(); err != nil { return err } - // if (screencastOptions) - // promises.push(this._startVideoRecording(screencastOptions)); - - /*for (const source of this._crPage._browserContext._evaluateOnNewDocumentSources) - promises.push(this._evaluateOnNewDocument(source, 'main')); - for (const source of this._crPage._page._evaluateOnNewDocumentSources) - promises.push(this._evaluateOnNewDocument(source, 'main'));*/ - for _, action := range optActions { if err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil { return fmt.Errorf("internal error while initializing frame %T: %w", action, err) @@ -644,11 +638,11 @@ func (fs *FrameSession) onConsoleAPICalled(event *cdpruntime.EventConsoleAPICall WithField("source", "browser"). WithField("browser_source", "console-api") - /* accessing the state Group while not on the eventloop is racy - if s := fs.vu.State(); s.Group.Path != "" { - l = l.WithField("group", s.Group.Path) - } - */ + /* accessing the state Group while not on the eventloop is racy + if s := fs.vu.State(); s.Group.Path != "" { + l = l.WithField("group", s.Group.Path) + } + */ parsedObjects := make([]string, 0, len(event.Args)) for _, robj := range event.Args { @@ -661,18 +655,9 @@ func (fs *FrameSession) onConsoleAPICalled(event *cdpruntime.EventConsoleAPICall msg := strings.Join(parsedObjects, " ") - switch event.Type { - case "log", "info": - l.Info(msg) - case "warning": - l.Warn(msg) - case "error": - l.Error(msg) - default: - // this is where debug & other console.* apis will default to (such as - // console.table). - l.Debug(msg) - } + // this is where debug & other console.* apis will default to (such as + // console.table). + l.Debug(msg) } func (fs *FrameSession) onExceptionThrown(event *cdpruntime.EventExceptionThrown) { @@ -894,21 +879,14 @@ func (fs *FrameSession) onLogEntryAdded(event *cdplog.EventEntryAdded) { WithField("url", event.Entry.URL). WithField("browser_source", event.Entry.Source.String()). WithField("line_number", event.Entry.LineNumber) - /* accessing the state Group while not on the eventloop is racy - if s := fs.vu.State(); s.Group.Path != "" { - l = l.WithField("group", s.Group.Path) - } - */ - switch event.Entry.Level { - case "info": - l.Info(event.Entry.Text) - case "warning": - l.Warn(event.Entry.Text) - case "error": - l.WithField("stacktrace", event.Entry.StackTrace).Error(event.Entry.Text) - default: - l.Debug(event.Entry.Text) + + /* accessing the state Group while not on the eventloop is racy + if s := fs.vu.State(); s.Group.Path != "" { + l = l.WithField("group", s.Group.Path) } + */ + + l.Debug(event.Entry.Text) } func (fs *FrameSession) onPageLifecycle(event *cdppage.EventLifecycleEvent) { @@ -1029,7 +1007,12 @@ func (fs *FrameSession) attachIFrameToTarget(ti *target.Info, sid target.Session return nil } // Remove all children of the previously attached frame. - fs.manager.removeChildFramesRecursively(fr) + err := fs.manager.removeChildFramesRecursively(fr) + if err != nil { + fs.logger.Debugf("FrameSession:attachIFrameToTarget:return", + "sid:%v tid:%v esid:%v etid:%v ebctxid:%v type:%q, can't remove child frames recursively: %q", + fs.session.ID(), fs.targetID, sid, ti.TargetID, ti.BrowserContextID, ti.Type, err) + } nfs, err := NewFrameSession( fs.ctx, @@ -1066,7 +1049,7 @@ func (fs *FrameSession) onDetachedFromTarget(event *target.EventDetachedFromTarg fs.page.closeWorker(event.SessionID) } -func (fs *FrameSession) onTargetCrashed(event *inspector.EventTargetCrashed) { +func (fs *FrameSession) onTargetCrashed() { fs.logger.Debugf("FrameSession:onTargetCrashed", "sid:%v tid:%v", fs.session.ID(), fs.targetID) // TODO:? @@ -1078,7 +1061,7 @@ func (fs *FrameSession) onTargetCrashed(event *inspector.EventTargetCrashed) { fs.page.didCrash() } -func (fs *FrameSession) updateEmulateMedia(initial bool) error { +func (fs *FrameSession) updateEmulateMedia() error { fs.logger.Debugf("NewFrameSession:updateEmulateMedia", "sid:%v tid:%v", fs.session.ID(), fs.targetID) features := make([]*emulation.MediaFeature, 0) diff --git a/vendor/github.com/grafana/xk6-browser/common/helpers.go b/vendor/github.com/grafana/xk6-browser/common/helpers.go index 64eb1e32866..0b2f2ee3a6b 100644 --- a/vendor/github.com/grafana/xk6-browser/common/helpers.go +++ b/vendor/github.com/grafana/xk6-browser/common/helpers.go @@ -14,7 +14,9 @@ import ( "github.com/grafana/xk6-browser/k6ext" ) -func convertBaseJSHandleTypes(ctx context.Context, execCtx *ExecutionContext, objHandle *BaseJSHandle) (*cdpruntime.CallArgument, error) { +func convertBaseJSHandleTypes( + _ context.Context, execCtx *ExecutionContext, objHandle *BaseJSHandle, +) (*cdpruntime.CallArgument, error) { if objHandle.execCtx != execCtx { return nil, ErrWrongExecutionContext } @@ -32,7 +34,6 @@ func convertBaseJSHandleTypes(ctx context.Context, execCtx *ExecutionContext, ob return &cdpruntime.CallArgument{ObjectID: objHandle.remoteObject.ObjectID}, nil } -// nolint: cyclop func convertArgument( ctx context.Context, execCtx *ExecutionContext, arg any, ) (*cdpruntime.CallArgument, error) { @@ -59,7 +60,7 @@ func convertArgument( unserVal = "-Infinity" default: if math.IsNaN(a) { - unserVal = "NaN" //nolint: goconst + unserVal = "NaN" } } @@ -124,6 +125,7 @@ func stringSliceContains(s []string, e string) bool { return false } +//nolint:gocognit func createWaitForEventHandler( ctx context.Context, emitter EventEmitter, events []string, @@ -212,6 +214,8 @@ func createWaitForEventPredicateHandler( } // panicOrSlowMo panics if err is not nil, otherwise applies slow motion. +// +//nolint:unused func panicOrSlowMo(ctx context.Context, err error) { if err != nil { k6ext.Panic(ctx, "%w", err) diff --git a/vendor/github.com/grafana/xk6-browser/common/js_handle.go b/vendor/github.com/grafana/xk6-browser/common/js_handle.go index a33cf054faa..3b51b33593e 100644 --- a/vendor/github.com/grafana/xk6-browser/common/js_handle.go +++ b/vendor/github.com/grafana/xk6-browser/common/js_handle.go @@ -10,7 +10,6 @@ import ( "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/runtime" - cdpruntime "github.com/chromedp/cdproto/runtime" ) // JSHandleAPI is the interface of an in-page JS object. @@ -25,7 +24,7 @@ type JSHandleAPI interface { EvaluateHandle(pageFunc string, args ...any) (JSHandleAPI, error) GetProperties() (map[string]JSHandleAPI, error) JSONValue() (string, error) - ObjectID() cdpruntime.RemoteObjectID + ObjectID() runtime.RemoteObjectID } type jsHandle interface { diff --git a/vendor/github.com/grafana/xk6-browser/common/mouse_options.go b/vendor/github.com/grafana/xk6-browser/common/mouse_options.go index f2ae7ffb0b1..94a6a494fa8 100644 --- a/vendor/github.com/grafana/xk6-browser/common/mouse_options.go +++ b/vendor/github.com/grafana/xk6-browser/common/mouse_options.go @@ -131,8 +131,7 @@ func (o *MouseMoveOptions) Parse(ctx context.Context, opts sobek.Value) error { if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { - switch k { - case "steps": + if k == "steps" { o.Steps = opts.Get(k).ToInteger() } } diff --git a/vendor/github.com/grafana/xk6-browser/common/network_manager.go b/vendor/github.com/grafana/xk6-browser/common/network_manager.go index d796804a257..6508c753b93 100644 --- a/vendor/github.com/grafana/xk6-browser/common/network_manager.go +++ b/vendor/github.com/grafana/xk6-browser/common/network_manager.go @@ -291,7 +291,9 @@ func handleURLTag(mi metricInterceptor, url string, method string, tags *k6metri return tags } -func (m *NetworkManager) handleRequestRedirect(req *Request, redirectResponse *network.Response, timestamp *cdp.MonotonicTime) { +func (m *NetworkManager) handleRequestRedirect( + req *Request, redirectResponse *network.Response, timestamp *cdp.MonotonicTime, +) { resp := NewHTTPResponse(m.ctx, req, redirectResponse, timestamp) req.responseMu.Lock() req.response = resp @@ -509,7 +511,7 @@ func (m *NetworkManager) onRequest(event *network.EventRequestWillBeSent, interc m.frameManager.requestStarted(req) } -func (m *NetworkManager) onRequestPaused(event *fetch.EventRequestPaused) { //nolint:funlen +func (m *NetworkManager) onRequestPaused(event *fetch.EventRequestPaused) { m.logger.Debugf("NetworkManager:onRequestPaused", "sid:%s url:%v", m.session.ID(), event.Request.URL) defer m.logger.Debugf("NetworkManager:onRequestPaused:return", diff --git a/vendor/github.com/grafana/xk6-browser/common/page.go b/vendor/github.com/grafana/xk6-browser/common/page.go index d21ac0819d4..3442a115830 100644 --- a/vendor/github.com/grafana/xk6-browser/common/page.go +++ b/vendor/github.com/grafana/xk6-browser/common/page.go @@ -16,9 +16,7 @@ import ( "github.com/chromedp/cdproto/dom" "github.com/chromedp/cdproto/emulation" "github.com/chromedp/cdproto/page" - cdppage "github.com/chromedp/cdproto/page" "github.com/chromedp/cdproto/runtime" - cdpruntime "github.com/chromedp/cdproto/runtime" "github.com/chromedp/cdproto/target" "github.com/grafana/sobek" "go.opentelemetry.io/otel/attribute" @@ -341,7 +339,7 @@ func (p *Page) initEvents() { "sid:%v tid:%v", p.session.ID(), p.targetID) return case event := <-p.eventCh: - if ev, ok := event.data.(*cdpruntime.EventConsoleAPICalled); ok { + if ev, ok := event.data.(*runtime.EventConsoleAPICalled); ok { p.onConsoleAPICalled(ev) } } @@ -490,7 +488,7 @@ func (p *Page) urlTagName(url string, method string) (string, bool) { return newTagName, urlMatched } -func (p *Page) onConsoleAPICalled(event *cdpruntime.EventConsoleAPICalled) { +func (p *Page) onConsoleAPICalled(event *runtime.EventConsoleAPICalled) { if !hasPageOnHandler(p, EventPageConsoleAPICalled) { return } @@ -514,7 +512,7 @@ func (p *Page) onConsoleAPICalled(event *cdpruntime.EventConsoleAPICalled) { } } -func (p *Page) consoleMsgFromConsoleEvent(e *cdpruntime.EventConsoleAPICalled) (*ConsoleMessage, error) { +func (p *Page) consoleMsgFromConsoleEvent(e *runtime.EventConsoleAPICalled) (*ConsoleMessage, error) { execCtx, err := p.executionContextForID(e.ExecutionContextID) if err != nil { return nil, err @@ -607,7 +605,7 @@ func (p *Page) getFrameElement(f *Frame) (handle *ElementHandle, _ error) { parentSession := p.getFrameSession(cdp.FrameID(rootFrame.ID())) action := dom.GetFrameOwner(cdp.FrameID(f.ID())) - backendNodeId, _, err := action.Do(cdp.WithExecutor(p.ctx, parentSession.session)) + backendNodeID, _, err := action.Do(cdp.WithExecutor(p.ctx, parentSession.session)) if err != nil { if strings.Contains(err.Error(), "frame with the given id was not found") { return nil, errors.New("frame has been detached") @@ -619,7 +617,7 @@ func (p *Page) getFrameElement(f *Frame) (handle *ElementHandle, _ error) { if parent == nil { return nil, errors.New("frame has been detached 2") } - return parent.adoptBackendNodeID(mainWorld, backendNodeId) + return parent.adoptBackendNodeID(mainWorld, backendNodeID) } func (p *Page) getOwnerFrame(apiCtx context.Context, h *ElementHandle) (cdp.FrameID, error) { @@ -644,13 +642,13 @@ func (p *Page) getOwnerFrame(apiCtx context.Context, h *ElementHandle) (cdp.Fram p.logger.Debugf("Page:getOwnerFrame:return", "sid:%v err:%v", p.sessionID(), err) return "", nil } - switch result.(type) { + switch result.(type) { //nolint:gocritic case nil: p.logger.Debugf("Page:getOwnerFrame:return", "sid:%v result:nil", p.sessionID()) return "", nil } - documentElement := result.(*ElementHandle) + documentElement := result.(*ElementHandle) //nolint:forcetypeassert if documentElement == nil { p.logger.Debugf("Page:getOwnerFrame:return", "sid:%v docel:nil", p.sessionID()) return "", nil @@ -806,7 +804,7 @@ func (p *Page) viewportSize() Size { func (p *Page) BringToFront() error { p.logger.Debugf("Page:BringToFront", "sid:%v", p.sessionID()) - action := cdppage.BringToFront() + action := page.BringToFront() if err := action.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil { return fmt.Errorf("bringing page to front: %w", err) } @@ -937,7 +935,7 @@ func (p *Page) EmulateMedia(opts sobek.Value) error { p.frameSessionsMu.RLock() for _, fs := range p.frameSessions { - if err := fs.updateEmulateMedia(false); err != nil { + if err := fs.updateEmulateMedia(); err != nil { p.frameSessionsMu.RUnlock() return fmt.Errorf("emulating media: %w", err) } @@ -1220,7 +1218,7 @@ func (p *Page) QueryAll(selector string) ([]*ElementHandle, error) { } // Reload will reload the current page. -func (p *Page) Reload(opts sobek.Value) (*Response, error) { //nolint:funlen,cyclop +func (p *Page) Reload(opts sobek.Value) (*Response, error) { //nolint:funlen p.logger.Debugf("Page:Reload", "sid:%v", p.sessionID()) _, span := TraceAPICall(p.ctx, p.targetID.String(), "page.reload") defer span.End() @@ -1258,7 +1256,7 @@ func (p *Page) Reload(opts sobek.Value) (*Response, error) { //nolint:funlen,cyc }) defer cancelWaitingForLifecycleEvent() - reloadAction := cdppage.Reload() + reloadAction := page.Reload() if err := reloadAction.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil { err := fmt.Errorf("reloading page: %w", err) spanRecordError(span, err) @@ -1329,7 +1327,7 @@ func (p *Page) Screenshot(opts *PageScreenshotOptions, sp ScreenshotPersister) ( span.SetAttributes(attribute.String("screenshot.path", opts.Path)) - s := newScreenshotter(spanCtx, sp) + s := newScreenshotter(spanCtx, sp, p.logger) buf, err := s.screenshotPage(p, opts) if err != nil { err := fmt.Errorf("taking screenshot of page: %w", err) @@ -1571,7 +1569,7 @@ func (p *Page) TargetID() string { // executionContextForID returns the page ExecutionContext for the given ID. func (p *Page) executionContextForID( - executionContextID cdpruntime.ExecutionContextID, + executionContextID runtime.ExecutionContextID, ) (*ExecutionContext, error) { p.frameSessionsMu.RLock() defer p.frameSessionsMu.RUnlock() @@ -1596,7 +1594,7 @@ func (p *Page) sessionID() (sid target.SessionID) { // textForConsoleEvent generates the text representation for a consoleAPICalled event // mimicking Playwright's behavior. -func textForConsoleEvent(e *cdpruntime.EventConsoleAPICalled, args []string) string { +func textForConsoleEvent(e *runtime.EventConsoleAPICalled, args []string) string { if e.Type.String() == "dir" || e.Type.String() == "dirxml" || e.Type.String() == "table" { if len(e.Args) > 0 { diff --git a/vendor/github.com/grafana/xk6-browser/common/page_options.go b/vendor/github.com/grafana/xk6-browser/common/page_options.go index d1a2f643ff4..d34865abc71 100644 --- a/vendor/github.com/grafana/xk6-browser/common/page_options.go +++ b/vendor/github.com/grafana/xk6-browser/common/page_options.go @@ -32,7 +32,9 @@ type PageScreenshotOptions struct { Quality int64 `json:"quality"` } -func NewPageEmulateMediaOptions(defaultMedia MediaType, defaultColorScheme ColorScheme, defaultReducedMotion ReducedMotion) *PageEmulateMediaOptions { +func NewPageEmulateMediaOptions( + defaultMedia MediaType, defaultColorScheme ColorScheme, defaultReducedMotion ReducedMotion, +) *PageEmulateMediaOptions { return &PageEmulateMediaOptions{ ColorScheme: defaultColorScheme, Media: defaultMedia, @@ -100,7 +102,7 @@ func NewPageScreenshotOptions() *PageScreenshotOptions { } // Parse parses the page screenshot options. -func (o *PageScreenshotOptions) Parse(ctx context.Context, opts sobek.Value) error { //nolint:cyclop +func (o *PageScreenshotOptions) Parse(ctx context.Context, opts sobek.Value) error { if !sobekValueExists(opts) { return nil } diff --git a/vendor/github.com/grafana/xk6-browser/common/remote_object.go b/vendor/github.com/grafana/xk6-browser/common/remote_object.go index 19bb6f16124..5767c6e5713 100644 --- a/vendor/github.com/grafana/xk6-browser/common/remote_object.go +++ b/vendor/github.com/grafana/xk6-browser/common/remote_object.go @@ -13,7 +13,6 @@ import ( "github.com/grafana/xk6-browser/log" "github.com/chromedp/cdproto/runtime" - cdpruntime "github.com/chromedp/cdproto/runtime" ) var bigIntRegex = regexp.MustCompile("^[0-9]*n$") @@ -59,7 +58,7 @@ func (e *remoteObjectParseError) Unwrap() error { return e.error } -func parseRemoteObjectPreview(op *cdpruntime.ObjectPreview) (map[string]any, error) { +func parseRemoteObjectPreview(op *runtime.ObjectPreview) (map[string]any, error) { obj := make(map[string]any) var result []error if op.Overflow { @@ -78,28 +77,27 @@ func parseRemoteObjectPreview(op *cdpruntime.ObjectPreview) (map[string]any, err return obj, errors.Join(result...) } -//nolint:cyclop func parseRemoteObjectValue( - t cdpruntime.Type, st cdpruntime.Subtype, val string, op *cdpruntime.ObjectPreview, + t runtime.Type, st runtime.Subtype, val string, op *runtime.ObjectPreview, ) (any, error) { - switch t { - case cdpruntime.TypeAccessor: + switch t { //nolint:exhaustive + case runtime.TypeAccessor: return "accessor", nil - case cdpruntime.TypeBigint: - n, err := strconv.ParseInt(strings.Replace(val, "n", "", -1), 10, 64) + case runtime.TypeBigint: + n, err := strconv.ParseInt(strings.ReplaceAll(val, "n", ""), 10, 64) if err != nil { return nil, BigIntParseError{err} } return n, nil - case cdpruntime.TypeFunction: + case runtime.TypeFunction: return "function()", nil - case cdpruntime.TypeString: + case runtime.TypeString: if !strings.HasPrefix(val, `"`) { return val, nil } - case cdpruntime.TypeSymbol: + case runtime.TypeSymbol: return val, nil - case cdpruntime.TypeObject: + case runtime.TypeObject: if op != nil { return parseRemoteObjectPreview(op) } @@ -109,7 +107,7 @@ func parseRemoteObjectValue( if st == runtime.SubtypeNull { return nil, nil //nolint:nilnil } - case cdpruntime.TypeUndefined: + case runtime.TypeUndefined: return "undefined", nil } @@ -126,7 +124,7 @@ func parseRemoteObjectValue( return v, nil } -func parseExceptionDetails(exc *cdpruntime.ExceptionDetails) string { +func parseExceptionDetails(exc *runtime.ExceptionDetails) string { if exc == nil { return "" } @@ -144,7 +142,7 @@ func parseExceptionDetails(exc *cdpruntime.ExceptionDetails) string { // parseRemoteObject is to be used by callers that require the string value // to be parsed to a Go type. -func parseRemoteObject(obj *cdpruntime.RemoteObject) (any, error) { +func parseRemoteObject(obj *runtime.RemoteObject) (any, error) { uv := obj.UnserializableValue if uv == "" { @@ -176,7 +174,7 @@ func parseRemoteObject(obj *cdpruntime.RemoteObject) (any, error) { return nil, UnserializableValueError{uv} } -func valueFromRemoteObject(_ context.Context, robj *cdpruntime.RemoteObject) (any, error) { +func valueFromRemoteObject(_ context.Context, robj *runtime.RemoteObject) (any, error) { val, err := parseRemoteObject(robj) if val == "undefined" { return nil, err @@ -184,10 +182,10 @@ func valueFromRemoteObject(_ context.Context, robj *cdpruntime.RemoteObject) (an return val, err } -func parseConsoleRemoteObjectPreview(logger *log.Logger, op *cdpruntime.ObjectPreview) (string, error) { +func parseConsoleRemoteObjectPreview(logger *log.Logger, op *runtime.ObjectPreview) (string, error) { obj := make(map[string]string) if op.Overflow { - logger.Infof("parseConsoleRemoteObjectPreview", "object is too large and will be parsed partially") + logger.Debugf("parseConsoleRemoteObjectPreview", "object is too large and will be parsed partially") } for _, p := range op.Properties { @@ -206,10 +204,10 @@ func parseConsoleRemoteObjectPreview(logger *log.Logger, op *cdpruntime.ObjectPr return string(bb), nil } -func parseConsoleRemoteArrayPreview(logger *log.Logger, op *cdpruntime.ObjectPreview) (string, error) { +func parseConsoleRemoteArrayPreview(logger *log.Logger, op *runtime.ObjectPreview) (string, error) { arr := make([]any, 0, len(op.Properties)) if op.Overflow { - logger.Infof("parseConsoleRemoteArrayPreview", "array is too large and will be parsed partially") + logger.Debugf("parseConsoleRemoteArrayPreview", "array is too large and will be parsed partially") } for _, p := range op.Properties { @@ -228,25 +226,24 @@ func parseConsoleRemoteArrayPreview(logger *log.Logger, op *cdpruntime.ObjectPre return string(bb), nil } -//nolint:cyclop func parseConsoleRemoteObjectValue( logger *log.Logger, - t cdpruntime.Type, - st cdpruntime.Subtype, + t runtime.Type, + st runtime.Subtype, val string, - op *cdpruntime.ObjectPreview, + op *runtime.ObjectPreview, ) (string, error) { switch t { - case cdpruntime.TypeAccessor: + case runtime.TypeAccessor: return "accessor", nil - case cdpruntime.TypeFunction: + case runtime.TypeFunction: return "function()", nil - case cdpruntime.TypeString: + case runtime.TypeString: if strings.HasPrefix(val, `"`) { val = strings.TrimPrefix(val, `"`) val = strings.TrimSuffix(val, `"`) } - case cdpruntime.TypeObject: + case runtime.TypeObject: if op != nil { if st == "array" { return parseConsoleRemoteArrayPreview(logger, op) @@ -259,14 +256,14 @@ func parseConsoleRemoteObjectValue( if st == "null" { return "null", nil } - case cdpruntime.TypeUndefined: + case runtime.TypeUndefined: return "undefined", nil // The following cases are here to clarify that all cases have been // considered, but that the result will return val without processing it. - case cdpruntime.TypeNumber: - case cdpruntime.TypeBoolean: - case cdpruntime.TypeSymbol: - case cdpruntime.TypeBigint: + case runtime.TypeNumber: + case runtime.TypeBoolean: + case runtime.TypeSymbol: + case runtime.TypeBigint: } return val, nil @@ -275,7 +272,7 @@ func parseConsoleRemoteObjectValue( // parseConsoleRemoteObject is to be used by callers that are working with // console messages that are written to Chrome's console by the website under // test. -func parseConsoleRemoteObject(logger *log.Logger, obj *cdpruntime.RemoteObject) (string, error) { +func parseConsoleRemoteObject(logger *log.Logger, obj *runtime.RemoteObject) (string, error) { if obj.UnserializableValue != "" { return obj.UnserializableValue.String(), nil } diff --git a/vendor/github.com/grafana/xk6-browser/common/screenshotter.go b/vendor/github.com/grafana/xk6-browser/common/screenshotter.go index 4b4002146d2..035c17e2966 100644 --- a/vendor/github.com/grafana/xk6-browser/common/screenshotter.go +++ b/vendor/github.com/grafana/xk6-browser/common/screenshotter.go @@ -13,6 +13,7 @@ import ( "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/emulation" cdppage "github.com/chromedp/cdproto/page" + "github.com/grafana/xk6-browser/log" ) // ScreenshotPersister is the type that all file persisters must implement. It's job is @@ -67,10 +68,15 @@ func (f *ImageFormat) UnmarshalJSON(b []byte) error { type screenshotter struct { ctx context.Context persister ScreenshotPersister + logger *log.Logger } -func newScreenshotter(ctx context.Context, sp ScreenshotPersister) *screenshotter { - return &screenshotter{ctx, sp} +func newScreenshotter( + ctx context.Context, + sp ScreenshotPersister, + logger *log.Logger, +) *screenshotter { + return &screenshotter{ctx, sp, logger} } func (s *screenshotter) fullPageSize(p *Page) (*Size, error) { @@ -144,7 +150,6 @@ func (s *screenshotter) restoreViewport(p *Page, originalViewport *Size) error { return p.resetViewport() } -//nolint:funlen,cyclop func (s *screenshotter) screenshot( sess session, doc, viewport *Rect, format ImageFormat, omitBackground bool, quality int64, path string, ) ([]byte, error) { @@ -165,7 +170,6 @@ func (s *screenshotter) screenshot( // Add common options capture.WithQuality(quality) - // nolint:exhaustive switch format { case ImageFormatJPEG: capture.WithFormat(cdppage.CaptureScreenshotFormatJpeg) @@ -173,21 +177,19 @@ func (s *screenshotter) screenshot( capture.WithFormat(cdppage.CaptureScreenshotFormatPng) } - // Add clip region - //nolint:dogsled - _, visualViewport, _, _, _, _, err := cdppage.GetLayoutMetrics().Do(cdp.WithExecutor(s.ctx, sess)) + visualViewportScale, visualViewportPageX, visualViewportPageY, err := getViewPortDimensions(s.ctx, sess, s.logger) if err != nil { - return nil, fmt.Errorf("getting layout metrics for screenshot: %w", err) + return nil, err } if doc == nil { s := Size{ - Width: viewport.Width / visualViewport.Scale, - Height: viewport.Height / visualViewport.Scale, + Width: viewport.Width / visualViewportScale, + Height: viewport.Height / visualViewportScale, }.enclosingIntSize() doc = &Rect{ - X: visualViewport.PageX + viewport.X, - Y: visualViewport.PageY + viewport.Y, + X: visualViewportPageX + viewport.X, + Y: visualViewportPageY + viewport.Y, Width: s.Width, Height: s.Height, } @@ -195,7 +197,7 @@ func (s *screenshotter) screenshot( scale := 1.0 if viewport != nil { - scale = visualViewport.Scale + scale = visualViewportScale } clip = &cdppage.Viewport{ X: doc.X, @@ -231,7 +233,43 @@ func (s *screenshotter) screenshot( return buf, nil } -//nolint:funlen,cyclop +func getViewPortDimensions(ctx context.Context, sess session, logger *log.Logger) (float64, float64, float64, error) { + visualViewportScale := 1.0 + visualViewportPageX, visualViewportPageY := 0.0, 0.0 + + // Add clip region + //nolint:dogsled + _, visualViewport, _, _, cssVisualViewport, _, err := cdppage.GetLayoutMetrics().Do(cdp.WithExecutor(ctx, sess)) + if err != nil { + return 0, 0, 0, fmt.Errorf("getting layout metrics for screenshot: %w", err) + } + + // we had a null pointer panic cases, when visualViewport is nil + // instead of the erroring out, we fallback to defaults and still try to do a screenshot + switch { + case cssVisualViewport != nil: + visualViewportScale = cssVisualViewport.Scale + visualViewportPageX = cssVisualViewport.PageX + visualViewportPageY = cssVisualViewport.PageY + case visualViewport != nil: + visualViewportScale = visualViewport.Scale + visualViewportPageX = visualViewport.PageX + visualViewportPageY = visualViewport.PageY + default: + logger.Warnf( + "Screenshotter::screenshot", + "chrome browser returned nil on page.getLayoutMetrics, falling back to defaults for visualViewport "+ + "(scale: %v, pageX: %v, pageY: %v)."+ + "This is non-standard behavior, if possible please report this issue (with reproducible script) "+ + "to the https://github.com/grafana/xk6-browser/issues/1502.", + visualViewportScale, visualViewportPageX, visualViewportPageY, + ) + } + + return visualViewportScale, visualViewportPageX, visualViewportPageY, nil +} + +//nolint:funlen func (s *screenshotter) screenshotElement(h *ElementHandle, opts *ElementHandleScreenshotOptions) ([]byte, error) { format := opts.Format viewportSize, originalViewportSize, err := s.originalViewportSize(h.frame.page) @@ -257,7 +295,7 @@ func (s *screenshotter) screenshotElement(h *ElementHandle, opts *ElementHandleS var overriddenViewportSize *Size fitsViewport := bbox.Width <= viewportSize.Width && bbox.Height <= viewportSize.Height - if !fitsViewport { + if !fitsViewport { //nolint:nestif overriddenViewportSize = Size{ Width: math.Max(viewportSize.Width, bbox.Width), Height: math.Max(viewportSize.Height, bbox.Height), @@ -317,7 +355,6 @@ func (s *screenshotter) screenshotElement(h *ElementHandle, opts *ElementHandleS return buf, nil } -//nolint:funlen,cyclop,gocognit func (s *screenshotter) screenshotPage(p *Page, opts *PageScreenshotOptions) ([]byte, error) { format := opts.Format @@ -333,7 +370,7 @@ func (s *screenshotter) screenshotPage(p *Page, opts *PageScreenshotOptions) ([] return nil, fmt.Errorf("getting original viewport size: %w", err) } - if opts.FullPage { + if opts.FullPage { //nolint:nestif fullPageSize, err := s.fullPageSize(p) if err != nil { return nil, fmt.Errorf("getting full page size: %w", err) diff --git a/vendor/github.com/grafana/xk6-browser/common/selectors.go b/vendor/github.com/grafana/xk6-browser/common/selectors.go index a198b9c491a..7eefa5ef806 100644 --- a/vendor/github.com/grafana/xk6-browser/common/selectors.go +++ b/vendor/github.com/grafana/xk6-browser/common/selectors.go @@ -65,28 +65,30 @@ func (s *Selector) appendPart(p *SelectorPart, capture bool) error { return nil } +//nolint:cyclop func (s *Selector) parse() error { parsePart := func(selector string, start, index int) (*SelectorPart, bool) { part := strings.TrimSpace(selector[start:index]) eqIndex := strings.Index(part, "=") var name, body string - if eqIndex != -1 && reQueryEngine.Match([]byte(strings.TrimSpace(part[0:eqIndex]))) { + switch { + case eqIndex != -1 && reQueryEngine.Match([]byte(strings.TrimSpace(part[0:eqIndex]))): name = strings.TrimSpace(part[0:eqIndex]) body = part[eqIndex+1:] - } else if len(part) > 1 && part[0] == '"' && part[len(part)-1] == '"' { + case len(part) > 1 && part[0] == '"' && part[len(part)-1] == '"': name = "text" body = part - } else if len(part) > 1 && part[0] == '\'' && part[len(part)-1] == '\'' { + case len(part) > 1 && part[0] == '\'' && part[len(part)-1] == '\'': name = "text" body = part - } else if reXPathSelector.Match([]byte(part)) || strings.HasPrefix(part, "..") { + case reXPathSelector.Match([]byte(part)) || strings.HasPrefix(part, ".."): // If selector starts with '//' or '//' prefixed with multiple opening // parenthesis, consider xpath. @see https://github.com/microsoft/playwright/issues/817 // If selector starts with '..', consider xpath as well. name = "xpath" body = part - } else { + default: name = "css" body = part } @@ -115,15 +117,16 @@ func (s *Selector) parse() error { for index < len(s.Selector) { c := s.Selector[index] - if c == '\\' && index+1 < len(s.Selector) { + switch { + case c == '\\' && index+1 < len(s.Selector): index += 2 - } else if c == quote { + case c == quote: quote = byte(0) index++ - } else if quote == 0 && (c == '"' || c == '\'' || c == '`') { + case quote == 0 && (c == '"' || c == '\'' || c == '`'): quote = c index++ - } else if quote == 0 && c == '>' && s.Selector[index+1] == '>' { + case quote == 0 && c == '>' && s.Selector[index+1] == '>': part, capture := parsePart(s.Selector, start, index) err := s.appendPart(part, capture) if err != nil { @@ -131,7 +134,7 @@ func (s *Selector) parse() error { } index += 2 start = index - } else { + default: index++ } } diff --git a/vendor/github.com/grafana/xk6-browser/common/session.go b/vendor/github.com/grafana/xk6-browser/common/session.go index 50326aafe82..caaa659b06d 100644 --- a/vendor/github.com/grafana/xk6-browser/common/session.go +++ b/vendor/github.com/grafana/xk6-browser/common/session.go @@ -107,7 +107,9 @@ func (s *Session) readLoop() { } // Execute implements the cdp.Executor interface. -func (s *Session) Execute(ctx context.Context, method string, params easyjson.Marshaler, res easyjson.Unmarshaler) error { +func (s *Session) Execute( + ctx context.Context, method string, params easyjson.Marshaler, res easyjson.Unmarshaler, +) error { s.logger.Debugf("Session:Execute", "sid:%v tid:%v method:%q", s.id, s.targetID, method) if s.crashed { s.logger.Debugf("Session:Execute:return", "sid:%v tid:%v method:%q crashed", s.id, s.targetID, method) @@ -124,13 +126,15 @@ func (s *Session) Execute(ctx context.Context, method string, params easyjson.Ma for { select { case <-evCancelCtx.Done(): - s.logger.Debugf("Session:Execute:<-evCancelCtx.Done():return", "sid:%v tid:%v method:%q", s.id, s.targetID, method) + s.logger.Debugf("Session:Execute:<-evCancelCtx.Done():return", "sid:%v tid:%v method:%q", + s.id, s.targetID, method) return case ev := <-chEvHandler: if msg, ok := ev.data.(*cdproto.Message); ok && msg.ID == id { select { case <-evCancelCtx.Done(): - s.logger.Debugf("Session:Execute:<-evCancelCtx.Done():2:return", "sid:%v tid:%v method:%q", s.id, s.targetID, method) + s.logger.Debugf("Session:Execute:<-evCancelCtx.Done():2:return", "sid:%v tid:%v method:%q", + s.id, s.targetID, method) case ch <- msg: // We expect only one response with the matching message ID, // then remove event handler by cancelling context and stopping goroutine. @@ -163,10 +167,13 @@ func (s *Session) Execute(ctx context.Context, method string, params easyjson.Ma return s.conn.send(contextWithDoneChan(ctx, s.done), msg, ch, res) } -func (s *Session) ExecuteWithoutExpectationOnReply(ctx context.Context, method string, params easyjson.Marshaler, res easyjson.Unmarshaler) error { +func (s *Session) ExecuteWithoutExpectationOnReply( + ctx context.Context, method string, params easyjson.Marshaler, res easyjson.Unmarshaler, +) error { s.logger.Debugf("Session:ExecuteWithoutExpectationOnReply", "sid:%v tid:%v method:%q", s.id, s.targetID, method) if s.crashed { - s.logger.Debugf("Session:ExecuteWithoutExpectationOnReply", "sid:%v tid:%v method:%q, ErrTargetCrashed", s.id, s.targetID, method) + s.logger.Debugf("Session:ExecuteWithoutExpectationOnReply", "sid:%v tid:%v method:%q, ErrTargetCrashed", + s.id, s.targetID, method) return ErrTargetCrashed } @@ -177,7 +184,8 @@ func (s *Session) ExecuteWithoutExpectationOnReply(ctx context.Context, method s var err error buf, err = easyjson.Marshal(params) if err != nil { - s.logger.Debugf("Session:ExecuteWithoutExpectationOnReply:Marshal", "sid:%v tid:%v method:%q err=%v", s.id, s.targetID, method, err) + s.logger.Debugf("Session:ExecuteWithoutExpectationOnReply:Marshal", "sid:%v tid:%v method:%q err=%v", + s.id, s.targetID, method, err) return err } } diff --git a/vendor/github.com/grafana/xk6-browser/env/env.go b/vendor/github.com/grafana/xk6-browser/env/env.go index 401673dfbcf..7bc394151bd 100644 --- a/vendor/github.com/grafana/xk6-browser/env/env.go +++ b/vendor/github.com/grafana/xk6-browser/env/env.go @@ -95,7 +95,7 @@ type LookupFunc func(key string) (string, bool) func EmptyLookup(_ string) (string, bool) { return "", false } // Lookup is a LookupFunc that uses os.LookupEnv. -func Lookup(key string) (string, bool) { return os.LookupEnv(key) } +func Lookup(key string) (string, bool) { return os.LookupEnv(key) } //nolint:forbidigo // ConstLookup is a LookupFunc that always returns the given value and true // if the key matches the given key. Otherwise it returns EmptyLookup diff --git a/vendor/github.com/grafana/xk6-browser/k6ext/metrics.go b/vendor/github.com/grafana/xk6-browser/k6ext/metrics.go index a2991b5586f..2c6b7ad20df 100644 --- a/vendor/github.com/grafana/xk6-browser/k6ext/metrics.go +++ b/vendor/github.com/grafana/xk6-browser/k6ext/metrics.go @@ -59,7 +59,6 @@ func RegisterCustomMetrics(registry *k6metrics.Registry) *CustomMetrics { webVitals[k] = registry.MustNewMetric(v, k6metrics.Trend, t) } - //nolint:lll return &CustomMetrics{ WebVitals: webVitals, BrowserDataSent: registry.MustNewMetric(browserDataSentName, k6metrics.Counter, k6metrics.Data), diff --git a/vendor/github.com/grafana/xk6-browser/k6ext/panic.go b/vendor/github.com/grafana/xk6-browser/k6ext/panic.go index 78056802626..3528bdbf6dd 100644 --- a/vendor/github.com/grafana/xk6-browser/k6ext/panic.go +++ b/vendor/github.com/grafana/xk6-browser/k6ext/panic.go @@ -64,7 +64,7 @@ func sharedPanic(ctx context.Context, failFunc func(rt *sobek.Runtime, a ...any) return } for _, pid := range pidder.Pids() { - p, err := os.FindProcess(pid) + p, err := os.FindProcess(pid) //nolint:forbidigo if err != nil { // optimistically skip and don't kill the process continue diff --git a/vendor/github.com/grafana/xk6-browser/keyboardlayout/us.go b/vendor/github.com/grafana/xk6-browser/keyboardlayout/us.go index 9a6dd366a82..4df9b0c501d 100644 --- a/vendor/github.com/grafana/xk6-browser/keyboardlayout/us.go +++ b/vendor/github.com/grafana/xk6-browser/keyboardlayout/us.go @@ -1,5 +1,6 @@ package keyboardlayout +//nolint:funlen func initUS() { validKeys := map[KeyInput]bool{ "0": true, diff --git a/vendor/github.com/grafana/xk6-browser/log/logger.go b/vendor/github.com/grafana/xk6-browser/log/logger.go index d86deb655eb..8bca24328d2 100644 --- a/vendor/github.com/grafana/xk6-browser/log/logger.go +++ b/vendor/github.com/grafana/xk6-browser/log/logger.go @@ -13,7 +13,7 @@ import ( ) type Logger struct { - *logrus.Logger + *logrus.Logger //nolint:forbidigo mu sync.Mutex lastLogCall int64 iterID string @@ -37,7 +37,7 @@ func New(logger logrus.FieldLogger, iterID string) *Logger { if logger == nil { ll.Warnf("Logger", "no logger supplied, using default") - } else if l, ok := logger.(*logrus.Logger); !ok { + } else if l, ok := logger.(*logrus.Logger); !ok { //nolint:forbidigo ll.Warnf("Logger", "invalid logger type %T, using default", logger) } else { ll.Logger = l diff --git a/vendor/github.com/grafana/xk6-browser/storage/file_persister.go b/vendor/github.com/grafana/xk6-browser/storage/file_persister.go index 038f8f624a8..91cb3cc4be1 100644 --- a/vendor/github.com/grafana/xk6-browser/storage/file_persister.go +++ b/vendor/github.com/grafana/xk6-browser/storage/file_persister.go @@ -25,11 +25,11 @@ func (l *LocalFilePersister) Persist(_ context.Context, path string, data io.Rea cp := filepath.Clean(path) dir := filepath.Dir(cp) - if err = os.MkdirAll(dir, 0o755); err != nil { + if err = os.MkdirAll(dir, 0o755); err != nil { //nolint:forbidigo,gosec return fmt.Errorf("creating a local directory %q: %w", dir, err) } - f, err := os.OpenFile(cp, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600) + f, err := os.OpenFile(cp, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600) //nolint:forbidigo if err != nil { return fmt.Errorf("creating a local file %q: %w", cp, err) } diff --git a/vendor/github.com/grafana/xk6-browser/storage/storage.go b/vendor/github.com/grafana/xk6-browser/storage/storage.go index 5f4cb9bffd7..9d09d2f0110 100644 --- a/vendor/github.com/grafana/xk6-browser/storage/storage.go +++ b/vendor/github.com/grafana/xk6-browser/storage/storage.go @@ -39,7 +39,7 @@ func (d *Dir) Make(tmpDir string, dir any) error { // create a temporary dir because the provided dir is empty. if d.fsMkdirTemp == nil { - d.fsMkdirTemp = os.MkdirTemp + d.fsMkdirTemp = os.MkdirTemp //nolint:forbidigo } var err error if d.Dir, err = d.fsMkdirTemp(tmpDir, k6BrowserDataDirPattern); err != nil { @@ -72,7 +72,7 @@ func (d *Dir) Cleanup() error { } if d.fsRemoveAll == nil { - d.fsRemoveAll = os.RemoveAll + d.fsRemoveAll = os.RemoveAll //nolint:forbidigo } return d.fsRemoveAll(d.Dir) diff --git a/vendor/github.com/grafana/xk6-browser/trace/trace.go b/vendor/github.com/grafana/xk6-browser/trace/trace.go index 448748995b6..ebfb120b91d 100644 --- a/vendor/github.com/grafana/xk6-browser/trace/trace.go +++ b/vendor/github.com/grafana/xk6-browser/trace/trace.go @@ -8,6 +8,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" + "go.opentelemetry.io/otel/trace/noop" k6lib "go.k6.io/k6/lib" ) @@ -189,4 +190,4 @@ func (NoopSpan) AddEvent(string, ...trace.EventOption) {} func (NoopSpan) SetName(string) {} // TracerProvider returns a noop tracer provider. -func (NoopSpan) TracerProvider() trace.TracerProvider { return trace.NewNoopTracerProvider() } +func (NoopSpan) TracerProvider() trace.TracerProvider { return noop.NewTracerProvider() } diff --git a/vendor/modules.txt b/vendor/modules.txt index 54387b3eee1..5cf5fb9dd06 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -179,7 +179,7 @@ github.com/grafana/sobek/ftoa/internal/fast github.com/grafana/sobek/parser github.com/grafana/sobek/token github.com/grafana/sobek/unistring -# github.com/grafana/xk6-browser v1.9.2-0.20241118153201-d741e4540a3a +# github.com/grafana/xk6-browser v1.10.0 ## explicit; go 1.21 github.com/grafana/xk6-browser/browser github.com/grafana/xk6-browser/chromium