From 094feeaafffd60994ff0957c56943adcc5221d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 20 Nov 2024 10:30:17 -0500 Subject: [PATCH] Fix frame evaluates for missing arg --- browser/frame_mapping.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/browser/frame_mapping.go b/browser/frame_mapping.go index d414c7dcb..967b9da61 100644 --- a/browser/frame_mapping.go +++ b/browser/frame_mapping.go @@ -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) {