diff --git a/browser/browser_context_mapping.go b/browser/browser_context_mapping.go index e45d994de..f4d14fc29 100644 --- a/browser/browser_context_mapping.go +++ b/browser/browser_context_mapping.go @@ -4,7 +4,7 @@ import ( "fmt" "reflect" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6error" @@ -15,14 +15,14 @@ import ( func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolint:funlen,gocognit,cyclop rt := vu.Runtime() return mapping{ - "addCookies": func(cookies []*common.Cookie) *goja.Promise { + "addCookies": func(cookies []*common.Cookie) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, bc.AddCookies(cookies) //nolint:wrapcheck }) }, - "addInitScript": func(script goja.Value) *goja.Promise { + "addInitScript": func(script sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { - if !gojaValueExists(script) { + if !sobekValueExists(script) { return nil, nil } @@ -30,7 +30,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin switch script.ExportType() { case reflect.TypeOf(string("")): source = script.String() - case reflect.TypeOf(goja.Object{}): + case reflect.TypeOf(sobek.Object{}): opts := script.ToObject(rt) for _, k := range opts.Keys() { if k == "content" { @@ -38,7 +38,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin } } default: - _, isCallable := goja.AssertFunction(script) + _, isCallable := sobek.AssertFunction(script) if !isCallable { source = fmt.Sprintf("(%s);", script.ToString().String()) } else { @@ -53,27 +53,27 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin // the browser is grabbed from VU. return mapBrowser(vu) }, - "clearCookies": func() *goja.Promise { + "clearCookies": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, bc.ClearCookies() //nolint:wrapcheck }) }, - "clearPermissions": func() *goja.Promise { + "clearPermissions": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, bc.ClearPermissions() //nolint:wrapcheck }) }, - "close": func() *goja.Promise { + "close": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, bc.Close() //nolint:wrapcheck }) }, - "cookies": func(urls ...string) *goja.Promise { + "cookies": func(urls ...string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return bc.Cookies(urls...) //nolint:wrapcheck }) }, - "grantPermissions": func(permissions []string, opts goja.Value) *goja.Promise { + "grantPermissions": func(permissions []string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { popts := common.NewGrantPermissionsOptions() popts.Parse(vu.Context(), opts) @@ -83,22 +83,22 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin }, "setDefaultNavigationTimeout": bc.SetDefaultNavigationTimeout, "setDefaultTimeout": bc.SetDefaultTimeout, - "setGeolocation": func(geolocation goja.Value) *goja.Promise { + "setGeolocation": func(geolocation sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, bc.SetGeolocation(geolocation) //nolint:wrapcheck }) }, - "setHTTPCredentials": func(httpCredentials goja.Value) *goja.Promise { + "setHTTPCredentials": func(httpCredentials sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, bc.SetHTTPCredentials(httpCredentials) //nolint:staticcheck,wrapcheck }) }, - "setOffline": func(offline bool) *goja.Promise { + "setOffline": func(offline bool) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, bc.SetOffline(offline) //nolint:wrapcheck }) }, - "waitForEvent": func(event string, optsOrPredicate goja.Value) (*goja.Promise, error) { + "waitForEvent": func(event string, optsOrPredicate sobek.Value) (*sobek.Promise, error) { ctx := vu.Context() popts := common.NewWaitForEventOptions( bc.Timeout(), @@ -120,7 +120,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin // before returning the result to the caller. c := make(chan bool) tq.Queue(func() error { - var resp goja.Value + var resp sobek.Value resp, err = popts.PredicateFn(vu.Runtime().ToValue(p)) rtn = resp.ToBoolean() close(c) @@ -145,7 +145,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin return mapPage(vu, p), nil }), nil }, - "pages": func() *goja.Object { + "pages": func() *sobek.Object { var ( mpages []mapping pages = bc.Pages() @@ -160,7 +160,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin return rt.ToValue(mpages).ToObject(rt) }, - "newPage": func() *goja.Promise { + "newPage": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { page, err := bc.NewPage() if err != nil { diff --git a/browser/browser_mapping.go b/browser/browser_mapping.go index 3ebeccc4a..bfab5190b 100644 --- a/browser/browser_mapping.go +++ b/browser/browser_mapping.go @@ -3,7 +3,7 @@ package browser import ( "fmt" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -19,7 +19,7 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop } return mapBrowserContext(vu, b.Context()), nil }, - "closeContext": func() *goja.Promise { + "closeContext": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { b, err := vu.browser() if err != nil { @@ -35,7 +35,7 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop } return b.IsConnected(), nil }, - "newContext": func(opts goja.Value) (*goja.Promise, error) { + "newContext": func(opts sobek.Value) (*sobek.Promise, error) { return k6ext.Promise(vu.Context(), func() (any, error) { b, err := vu.browser() if err != nil { @@ -69,7 +69,7 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop } return b.Version(), nil }, - "newPage": func(opts goja.Value) *goja.Promise { + "newPage": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { b, err := vu.browser() if err != nil { diff --git a/browser/console_message_mapping.go b/browser/console_message_mapping.go index 2a5f2a88b..226baaa68 100644 --- a/browser/console_message_mapping.go +++ b/browser/console_message_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" ) @@ -10,7 +10,7 @@ import ( func mapConsoleMessage(vu moduleVU, cm *common.ConsoleMessage) mapping { rt := vu.Runtime() return mapping{ - "args": func() *goja.Object { + "args": func() *sobek.Object { var ( margs []mapping args = cm.Args @@ -24,14 +24,14 @@ func mapConsoleMessage(vu moduleVU, cm *common.ConsoleMessage) mapping { }, // page(), text() and type() are defined as // functions in order to match Playwright's API - "page": func() *goja.Object { + "page": func() *sobek.Object { mp := mapPage(vu, cm.Page) return rt.ToValue(mp).ToObject(rt) }, - "text": func() *goja.Object { + "text": func() *sobek.Object { return rt.ToValue(cm.Text).ToObject(rt) }, - "type": func() *goja.Object { + "type": func() *sobek.Object { return rt.ToValue(cm.Type).ToObject(rt) }, } diff --git a/browser/element_handle_mapping.go b/browser/element_handle_mapping.go index a17391f35..c598ce739 100644 --- a/browser/element_handle_mapping.go +++ b/browser/element_handle_mapping.go @@ -3,7 +3,7 @@ package browser import ( "fmt" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -13,17 +13,17 @@ import ( func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint:gocognit,cyclop,funlen rt := vu.Runtime() maps := mapping{ - "boundingBox": func() *goja.Promise { + "boundingBox": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.BoundingBox(), nil }) }, - "check": func(opts goja.Value) *goja.Promise { + "check": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.Check(opts) //nolint:wrapcheck }) }, - "click": func(opts goja.Value) (*goja.Promise, error) { + "click": func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewElementHandleClickOptions(eh.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing element click options: %w", err) @@ -34,7 +34,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return nil, err //nolint:wrapcheck }), nil }, - "contentFrame": func() *goja.Promise { + "contentFrame": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { f, err := eh.ContentFrame() if err != nil { @@ -43,27 +43,27 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return mapFrame(vu, f), nil }) }, - "dblclick": func(opts goja.Value) *goja.Promise { + "dblclick": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.Dblclick(opts) //nolint:wrapcheck }) }, - "dispatchEvent": func(typ string, eventInit goja.Value) *goja.Promise { + "dispatchEvent": func(typ string, eventInit sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.DispatchEvent(typ, exportArg(eventInit)) //nolint:wrapcheck }) }, - "fill": func(value string, opts goja.Value) *goja.Promise { + "fill": func(value string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.Fill(value, opts) //nolint:wrapcheck }) }, - "focus": func() *goja.Promise { + "focus": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.Focus() //nolint:wrapcheck }) }, - "getAttribute": func(name string) *goja.Promise { + "getAttribute": func(name string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { s, ok, err := eh.GetAttribute(name) if err != nil { @@ -75,57 +75,57 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return s, nil }) }, - "hover": func(opts goja.Value) *goja.Promise { + "hover": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.Hover(opts) //nolint:wrapcheck }) }, - "innerHTML": func() *goja.Promise { + "innerHTML": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.InnerHTML() //nolint:wrapcheck }) }, - "innerText": func() *goja.Promise { + "innerText": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.InnerText() //nolint:wrapcheck }) }, - "inputValue": func(opts goja.Value) *goja.Promise { + "inputValue": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.InputValue(opts) //nolint:wrapcheck }) }, - "isChecked": func() *goja.Promise { + "isChecked": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.IsChecked() //nolint:wrapcheck }) }, - "isDisabled": func() *goja.Promise { + "isDisabled": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.IsDisabled() //nolint:wrapcheck }) }, - "isEditable": func() *goja.Promise { + "isEditable": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.IsEditable() //nolint:wrapcheck }) }, - "isEnabled": func() *goja.Promise { + "isEnabled": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.IsEnabled() //nolint:wrapcheck }) }, - "isHidden": func() *goja.Promise { + "isHidden": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.IsHidden() //nolint:wrapcheck }) }, - "isVisible": func() *goja.Promise { + "isVisible": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.IsVisible() //nolint:wrapcheck }) }, - "ownerFrame": func() *goja.Promise { + "ownerFrame": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { f, err := eh.OwnerFrame() if err != nil { @@ -134,12 +134,12 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return mapFrame(vu, f), nil }) }, - "press": func(key string, opts goja.Value) *goja.Promise { + "press": func(key string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.Press(key, opts) //nolint:wrapcheck }) }, - "screenshot": func(opts goja.Value) (*goja.Promise, error) { + "screenshot": func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewElementHandleScreenshotOptions(eh.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing element handle screenshot options: %w", err) @@ -156,27 +156,27 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return &ab, nil }), nil }, - "scrollIntoViewIfNeeded": func(opts goja.Value) *goja.Promise { + "scrollIntoViewIfNeeded": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.ScrollIntoViewIfNeeded(opts) //nolint:wrapcheck }) }, - "selectOption": func(values goja.Value, opts goja.Value) *goja.Promise { + "selectOption": func(values sobek.Value, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return eh.SelectOption(values, opts) //nolint:wrapcheck }) }, - "selectText": func(opts goja.Value) *goja.Promise { + "selectText": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.SelectText(opts) //nolint:wrapcheck }) }, - "setInputFiles": func(files goja.Value, opts goja.Value) *goja.Promise { + "setInputFiles": func(files sobek.Value, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.SetInputFiles(files, opts) //nolint:wrapcheck }) }, - "tap": func(opts goja.Value) (*goja.Promise, error) { + "tap": func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewElementHandleTapOptions(eh.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing element tap options: %w", err) @@ -185,7 +185,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return nil, eh.Tap(popts) //nolint:wrapcheck }), nil }, - "textContent": func() *goja.Promise { + "textContent": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { s, ok, err := eh.TextContent() if err != nil { @@ -197,22 +197,22 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return s, nil }) }, - "type": func(text string, opts goja.Value) *goja.Promise { + "type": func(text string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.Type(text, opts) //nolint:wrapcheck }) }, - "uncheck": func(opts goja.Value) *goja.Promise { + "uncheck": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.Uncheck(opts) //nolint:wrapcheck }) }, - "waitForElementState": func(state string, opts goja.Value) *goja.Promise { + "waitForElementState": func(state string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, eh.WaitForElementState(state, opts) //nolint:wrapcheck }) }, - "waitForSelector": func(selector string, opts goja.Value) *goja.Promise { + "waitForSelector": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { eh, err := eh.WaitForSelector(selector, opts) if err != nil { @@ -222,7 +222,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: }) }, } - maps["$"] = func(selector string) *goja.Promise { + maps["$"] = func(selector string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { eh, err := eh.Query(selector, common.StrictModeOff) if err != nil { @@ -239,7 +239,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return ehm, nil }) } - maps["$$"] = func(selector string) *goja.Promise { + maps["$$"] = func(selector string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { ehs, err := eh.QueryAll(selector) if err != nil { diff --git a/browser/frame_mapping.go b/browser/frame_mapping.go index 3f200b683..4d1aaf3a6 100644 --- a/browser/frame_mapping.go +++ b/browser/frame_mapping.go @@ -3,7 +3,7 @@ package browser import ( "fmt" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -14,7 +14,7 @@ import ( //nolint:funlen func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop maps := mapping{ - "check": func(selector string, opts goja.Value) *goja.Promise { + "check": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.Check(selector, opts) //nolint:wrapcheck }) @@ -29,7 +29,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop } return mcfs }, - "click": func(selector string, opts goja.Value) (*goja.Promise, error) { + "click": func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameClickOptions(vu.Context(), opts, f.Timeout()) if err != nil { return nil, err @@ -40,17 +40,17 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return nil, err //nolint:wrapcheck }), nil }, - "content": func() *goja.Promise { + "content": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.Content() //nolint:wrapcheck }) }, - "dblclick": func(selector string, opts goja.Value) *goja.Promise { + "dblclick": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.Dblclick(selector, opts) //nolint:wrapcheck }) }, - "dispatchEvent": func(selector, typ string, eventInit, opts goja.Value) (*goja.Promise, error) { + "dispatchEvent": func(selector, typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameDispatchEventOptions(f.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing frame dispatch event options: %w", err) @@ -59,12 +59,12 @@ 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 goja.Value, gargs ...goja.Value) *goja.Promise { + "evaluate": func(pageFunction sobek.Value, gargs ...sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck }) }, - "evaluateHandle": func(pageFunction goja.Value, gargs ...goja.Value) *goja.Promise { + "evaluateHandle": func(pageFunction sobek.Value, gargs ...sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { jsh, err := f.EvaluateHandle(pageFunction.String(), exportArgs(gargs)...) if err != nil { @@ -73,17 +73,17 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return mapJSHandle(vu, jsh), nil }) }, - "fill": func(selector, value string, opts goja.Value) *goja.Promise { + "fill": func(selector, value string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.Fill(selector, value, opts) //nolint:wrapcheck }) }, - "focus": func(selector string, opts goja.Value) *goja.Promise { + "focus": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.Focus(selector, opts) //nolint:wrapcheck }) }, - "frameElement": func() *goja.Promise { + "frameElement": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { fe, err := f.FrameElement() if err != nil { @@ -92,7 +92,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return mapElementHandle(vu, fe), nil }) }, - "getAttribute": func(selector, name string, opts goja.Value) *goja.Promise { + "getAttribute": func(selector, name string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { s, ok, err := f.GetAttribute(selector, name, opts) if err != nil { @@ -104,7 +104,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return s, nil }) }, - "goto": func(url string, opts goja.Value) (*goja.Promise, error) { + "goto": func(url string, opts sobek.Value) (*sobek.Promise, error) { gopts := common.NewFrameGotoOptions( f.Referrer(), f.NavigationTimeout(), @@ -121,58 +121,58 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return mapResponse(vu, resp), nil }), nil }, - "hover": func(selector string, opts goja.Value) *goja.Promise { + "hover": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.Hover(selector, opts) //nolint:wrapcheck }) }, - "innerHTML": func(selector string, opts goja.Value) *goja.Promise { + "innerHTML": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.InnerHTML(selector, opts) //nolint:wrapcheck }) }, - "innerText": func(selector string, opts goja.Value) *goja.Promise { + "innerText": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.InnerText(selector, opts) //nolint:wrapcheck }) }, - "inputValue": func(selector string, opts goja.Value) *goja.Promise { + "inputValue": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.InputValue(selector, opts) //nolint:wrapcheck }) }, - "isChecked": func(selector string, opts goja.Value) *goja.Promise { + "isChecked": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.IsChecked(selector, opts) //nolint:wrapcheck }) }, "isDetached": f.IsDetached, - "isDisabled": func(selector string, opts goja.Value) *goja.Promise { + "isDisabled": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.IsDisabled(selector, opts) //nolint:wrapcheck }) }, - "isEditable": func(selector string, opts goja.Value) *goja.Promise { + "isEditable": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.IsEditable(selector, opts) //nolint:wrapcheck }) }, - "isEnabled": func(selector string, opts goja.Value) *goja.Promise { + "isEnabled": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.IsEnabled(selector, opts) //nolint:wrapcheck }) }, - "isHidden": func(selector string, opts goja.Value) *goja.Promise { + "isHidden": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.IsHidden(selector, opts) //nolint:wrapcheck }) }, - "isVisible": func(selector string, opts goja.Value) *goja.Promise { + "isVisible": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.IsVisible(selector, opts) //nolint:wrapcheck }) }, - "locator": func(selector string, opts goja.Value) mapping { + "locator": func(selector string, opts sobek.Value) mapping { return mapLocator(vu, f.Locator(selector, opts)) }, "name": f.Name, @@ -182,27 +182,27 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop "parentFrame": func() mapping { return mapFrame(vu, f.ParentFrame()) }, - "press": func(selector, key string, opts goja.Value) *goja.Promise { + "press": func(selector, key string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.Press(selector, key, opts) //nolint:wrapcheck }) }, - "selectOption": func(selector string, values goja.Value, opts goja.Value) *goja.Promise { + "selectOption": func(selector string, values sobek.Value, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.SelectOption(selector, values, opts) //nolint:wrapcheck }) }, - "setContent": func(html string, opts goja.Value) *goja.Promise { + "setContent": func(html string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.SetContent(html, opts) //nolint:wrapcheck }) }, - "setInputFiles": func(selector string, files goja.Value, opts goja.Value) *goja.Promise { + "setInputFiles": func(selector string, files sobek.Value, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.SetInputFiles(selector, files, opts) //nolint:wrapcheck }) }, - "tap": func(selector string, opts goja.Value) (*goja.Promise, error) { + "tap": func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameTapOptions(f.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing frame tap options: %w", err) @@ -211,7 +211,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return nil, f.Tap(selector, popts) //nolint:wrapcheck }), nil }, - "textContent": func(selector string, opts goja.Value) *goja.Promise { + "textContent": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { s, ok, err := f.TextContent(selector, opts) if err != nil { @@ -223,23 +223,23 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return s, nil }) }, - "title": func() *goja.Promise { + "title": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return f.Title(), nil }) }, - "type": func(selector, text string, opts goja.Value) *goja.Promise { + "type": func(selector, text string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.Type(selector, text, opts) //nolint:wrapcheck }) }, - "uncheck": func(selector string, opts goja.Value) *goja.Promise { + "uncheck": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.Uncheck(selector, opts) //nolint:wrapcheck }) }, "url": f.URL, - "waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) { + "waitForFunction": func(pageFunc, opts sobek.Value, args ...sobek.Value) (*sobek.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( vu.Context(), f.Timeout(), pageFunc, opts, args..., ) @@ -251,12 +251,12 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return f.WaitForFunction(js, popts, pargs...) //nolint:wrapcheck }), nil }, - "waitForLoadState": func(state string, opts goja.Value) *goja.Promise { + "waitForLoadState": func(state string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, f.WaitForLoadState(state, opts) //nolint:wrapcheck }) }, - "waitForNavigation": func(opts goja.Value) (*goja.Promise, error) { + "waitForNavigation": func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameWaitForNavigationOptions(f.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing frame wait for navigation options: %w", err) @@ -270,7 +270,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return mapResponse(vu, resp), nil }), nil }, - "waitForSelector": func(selector string, opts goja.Value) *goja.Promise { + "waitForSelector": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { eh, err := f.WaitForSelector(selector, opts) if err != nil { @@ -279,14 +279,14 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return mapElementHandle(vu, eh), nil }) }, - "waitForTimeout": func(timeout int64) *goja.Promise { + "waitForTimeout": func(timeout int64) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { f.WaitForTimeout(timeout) return nil, nil }) }, } - maps["$"] = func(selector string) *goja.Promise { + maps["$"] = func(selector string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { eh, err := f.Query(selector, common.StrictModeOff) if err != nil { @@ -303,7 +303,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return ehm, nil }) } - maps["$$"] = func(selector string) *goja.Promise { + maps["$$"] = func(selector string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { ehs, err := f.QueryAll(selector) if err != nil { diff --git a/browser/helpers.go b/browser/helpers.go index 47375281f..ba93f28f5 100644 --- a/browser/helpers.go +++ b/browser/helpers.go @@ -4,7 +4,7 @@ import ( "context" "errors" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/k6error" "github.com/grafana/xk6-browser/k6ext" @@ -18,15 +18,15 @@ func panicIfFatalError(ctx context.Context, err error) { // exportArg exports the value and returns it. // It returns nil if the value is undefined or null. -func exportArg(gv goja.Value) any { - if !gojaValueExists(gv) { +func exportArg(gv sobek.Value) any { + if !sobekValueExists(gv) { return nil } return gv.Export() } -// exportArgs returns a slice of exported Goja values. -func exportArgs(gargs []goja.Value) []any { +// exportArgs returns a slice of exported sobek values. +func exportArgs(gargs []sobek.Value) []any { args := make([]any, 0, len(gargs)) for _, garg := range gargs { // leaves a nil garg in the array since users might want to @@ -36,8 +36,8 @@ func exportArgs(gargs []goja.Value) []any { return args } -// gojaValueExists returns true if a given value is not nil and exists -// (defined and not null) in the goja runtime. -func gojaValueExists(v goja.Value) bool { - return v != nil && !goja.IsUndefined(v) && !goja.IsNull(v) +// sobekValueExists returns true if a given value is not nil and exists +// (defined and not null) in the sobek runtime. +func sobekValueExists(v sobek.Value) bool { + return v != nil && !sobek.IsUndefined(v) && !sobek.IsNull(v) } diff --git a/browser/js_handle_mapping.go b/browser/js_handle_mapping.go index af13b58b0..db300a6d5 100644 --- a/browser/js_handle_mapping.go +++ b/browser/js_handle_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -13,12 +13,12 @@ func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { "asElement": func() mapping { return mapElementHandle(vu, jsh.AsElement()) }, - "dispose": func() *goja.Promise { + "dispose": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, jsh.Dispose() //nolint:wrapcheck }) }, - "evaluate": func(pageFunc goja.Value, gargs ...goja.Value) *goja.Promise { + "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { args := make([]any, 0, len(gargs)) for _, a := range gargs { @@ -27,7 +27,7 @@ func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { return jsh.Evaluate(pageFunc.String(), args...) //nolint:wrapcheck }) }, - "evaluateHandle": func(pageFunc goja.Value, gargs ...goja.Value) *goja.Promise { + "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { h, err := jsh.EvaluateHandle(pageFunc.String(), exportArgs(gargs)...) if err != nil { @@ -36,7 +36,7 @@ func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { return mapJSHandle(vu, h), nil }) }, - "getProperties": func() *goja.Promise { + "getProperties": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { props, err := jsh.GetProperties() if err != nil { @@ -50,7 +50,7 @@ func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { return dst, nil }) }, - "jsonValue": func() *goja.Promise { + "jsonValue": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return jsh.JSONValue() //nolint:wrapcheck }) diff --git a/browser/keyboard_mapping.go b/browser/keyboard_mapping.go index e2a14d77d..0fe9cc8ff 100644 --- a/browser/keyboard_mapping.go +++ b/browser/keyboard_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -9,27 +9,27 @@ import ( func mapKeyboard(vu moduleVU, kb *common.Keyboard) mapping { return mapping{ - "down": func(key string) *goja.Promise { + "down": func(key string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, kb.Down(key) //nolint:wrapcheck }) }, - "up": func(key string) *goja.Promise { + "up": func(key string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, kb.Up(key) //nolint:wrapcheck }) }, - "press": func(key string, opts goja.Value) *goja.Promise { + "press": func(key string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, kb.Press(key, opts) //nolint:wrapcheck }) }, - "type": func(text string, opts goja.Value) *goja.Promise { + "type": func(text string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, kb.Type(text, opts) //nolint:wrapcheck }) }, - "insertText": func(text string) *goja.Promise { + "insertText": func(text string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, kb.InsertText(text) //nolint:wrapcheck }) diff --git a/browser/locator_mapping.go b/browser/locator_mapping.go index a0c1d1839..1df2f73ec 100644 --- a/browser/locator_mapping.go +++ b/browser/locator_mapping.go @@ -3,7 +3,7 @@ package browser import ( "fmt" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -12,7 +12,7 @@ import ( // mapLocator API to the JS module. func mapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen return mapping{ - "clear": func(opts goja.Value) (*goja.Promise, error) { + "clear": func(opts sobek.Value) (*sobek.Promise, error) { copts := common.NewFrameFillOptions(lo.Timeout()) if err := copts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing clear options: %w", err) @@ -21,7 +21,7 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen return nil, lo.Clear(copts) //nolint:wrapcheck }), nil }, - "click": func(opts goja.Value) (*goja.Promise, error) { + "click": func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameClickOptions(vu.Context(), opts, lo.Timeout()) if err != nil { return nil, err @@ -31,62 +31,62 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen return nil, lo.Click(popts) //nolint:wrapcheck }), nil }, - "dblclick": func(opts goja.Value) *goja.Promise { + "dblclick": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, lo.Dblclick(opts) //nolint:wrapcheck }) }, - "check": func(opts goja.Value) *goja.Promise { + "check": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, lo.Check(opts) //nolint:wrapcheck }) }, - "uncheck": func(opts goja.Value) *goja.Promise { + "uncheck": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, lo.Uncheck(opts) //nolint:wrapcheck }) }, - "isChecked": func(opts goja.Value) *goja.Promise { + "isChecked": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return lo.IsChecked(opts) //nolint:wrapcheck }) }, - "isEditable": func(opts goja.Value) *goja.Promise { + "isEditable": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return lo.IsEditable(opts) //nolint:wrapcheck }) }, - "isEnabled": func(opts goja.Value) *goja.Promise { + "isEnabled": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return lo.IsEnabled(opts) //nolint:wrapcheck }) }, - "isDisabled": func(opts goja.Value) *goja.Promise { + "isDisabled": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return lo.IsDisabled(opts) //nolint:wrapcheck }) }, - "isVisible": func() *goja.Promise { + "isVisible": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return lo.IsVisible() //nolint:wrapcheck }) }, - "isHidden": func() *goja.Promise { + "isHidden": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return lo.IsHidden() //nolint:wrapcheck }) }, - "fill": func(value string, opts goja.Value) *goja.Promise { + "fill": func(value string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, lo.Fill(value, opts) //nolint:wrapcheck }) }, - "focus": func(opts goja.Value) *goja.Promise { + "focus": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, lo.Focus(opts) //nolint:wrapcheck }) }, - "getAttribute": func(name string, opts goja.Value) *goja.Promise { + "getAttribute": func(name string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { s, ok, err := lo.GetAttribute(name, opts) if err != nil { @@ -98,17 +98,17 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen return s, nil }) }, - "innerHTML": func(opts goja.Value) *goja.Promise { + "innerHTML": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return lo.InnerHTML(opts) //nolint:wrapcheck }) }, - "innerText": func(opts goja.Value) *goja.Promise { + "innerText": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return lo.InnerText(opts) //nolint:wrapcheck }) }, - "textContent": func(opts goja.Value) *goja.Promise { + "textContent": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { s, ok, err := lo.TextContent(opts) if err != nil { @@ -120,32 +120,32 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen return s, nil }) }, - "inputValue": func(opts goja.Value) *goja.Promise { + "inputValue": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return lo.InputValue(opts) //nolint:wrapcheck }) }, - "selectOption": func(values goja.Value, opts goja.Value) *goja.Promise { + "selectOption": func(values sobek.Value, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return lo.SelectOption(values, opts) //nolint:wrapcheck }) }, - "press": func(key string, opts goja.Value) *goja.Promise { + "press": func(key string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, lo.Press(key, opts) //nolint:wrapcheck }) }, - "type": func(text string, opts goja.Value) *goja.Promise { + "type": func(text string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, lo.Type(text, opts) //nolint:wrapcheck }) }, - "hover": func(opts goja.Value) *goja.Promise { + "hover": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, lo.Hover(opts) //nolint:wrapcheck }) }, - "tap": func(opts goja.Value) (*goja.Promise, error) { + "tap": func(opts sobek.Value) (*sobek.Promise, error) { copts := common.NewFrameTapOptions(lo.DefaultTimeout()) if err := copts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing locator tap options: %w", err) @@ -154,7 +154,7 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen return nil, lo.Tap(copts) //nolint:wrapcheck }), nil }, - "dispatchEvent": func(typ string, eventInit, opts goja.Value) (*goja.Promise, error) { + "dispatchEvent": func(typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameDispatchEventOptions(lo.DefaultTimeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing locator dispatch event options: %w", err) @@ -163,7 +163,7 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen return nil, lo.DispatchEvent(typ, exportArg(eventInit), popts) //nolint:wrapcheck }), nil }, - "waitFor": func(opts goja.Value) *goja.Promise { + "waitFor": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, lo.WaitFor(opts) //nolint:wrapcheck }) diff --git a/browser/mapping.go b/browser/mapping.go index c96cb73ab..80cc7cbfa 100644 --- a/browser/mapping.go +++ b/browser/mapping.go @@ -5,23 +5,23 @@ import ( "fmt" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" k6common "go.k6.io/k6/js/common" ) -// mapping is a type for mapping our module API to Goja. +// mapping is a type for mapping our module API to sobek. // It acts like a bridge and allows adding wildcard methods // and customization over our API. type mapping = map[string]any -// mapBrowserToGoja maps the browser API to the JS module. +// mapBrowserToSobek maps the browser API to the JS module. // The motivation of this mapping was to support $ and $$ wildcard // methods. // See issue #661 for more details. -func mapBrowserToGoja(vu moduleVU) *goja.Object { +func mapBrowserToSobek(vu moduleVU) *sobek.Object { var ( rt = vu.Runtime() obj = rt.NewObject() @@ -37,7 +37,7 @@ func mapBrowserToGoja(vu moduleVU) *goja.Object { } func parseFrameClickOptions( - ctx context.Context, opts goja.Value, defaultTimeout time.Duration, + ctx context.Context, opts sobek.Value, defaultTimeout time.Duration, ) (*common.FrameClickOptions, error) { copts := common.NewFrameClickOptions(defaultTimeout) if err := copts.Parse(ctx, opts); err != nil { diff --git a/browser/mapping_test.go b/browser/mapping_test.go index 75ce7e8b5..ccea1f55c 100644 --- a/browser/mapping_test.go +++ b/browser/mapping_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/stretchr/testify/require" "github.com/grafana/xk6-browser/common" @@ -61,7 +61,7 @@ func TestMappings(t *testing.T) { var ( vu = &k6modulestest.VU{ - RuntimeField: goja.New(), + RuntimeField: sobek.New(), InitEnvField: &k6common.InitEnvironment{ TestPreInitState: &k6lib.TestPreInitState{ Registry: k6metrics.NewRegistry(), @@ -86,7 +86,7 @@ func TestMappings(t *testing.T) { method := typ.Method(i) require.NotNil(t, method) - // goja uses methods that starts with lowercase. + // sobek uses methods that starts with lowercase. // so we need to convert the first letter to lowercase. m := toFirstLetterLower(method.Name) @@ -264,8 +264,8 @@ type browserAPI interface { Context() *common.BrowserContext CloseContext() IsConnected() bool - NewContext(opts goja.Value) (*common.BrowserContext, error) - NewPage(opts goja.Value) (*common.Page, error) + NewContext(opts sobek.Value) (*common.BrowserContext, error) + NewPage(opts sobek.Value) (*common.Page, error) On(string) (bool, error) UserAgent() string Version() string @@ -274,85 +274,85 @@ type browserAPI interface { // browserContextAPI is the public interface of a CDP browser context. type browserContextAPI interface { AddCookies(cookies []*common.Cookie) error - AddInitScript(script goja.Value, arg goja.Value) error + AddInitScript(script sobek.Value, arg sobek.Value) error Browser() *common.Browser ClearCookies() error ClearPermissions() error Close() error Cookies(urls ...string) ([]*common.Cookie, error) - GrantPermissions(permissions []string, opts goja.Value) error + GrantPermissions(permissions []string, opts sobek.Value) error NewPage() (*common.Page, error) Pages() []*common.Page SetDefaultNavigationTimeout(timeout int64) SetDefaultTimeout(timeout int64) - SetGeolocation(geolocation goja.Value) error - SetHTTPCredentials(httpCredentials goja.Value) error + SetGeolocation(geolocation sobek.Value) error + SetHTTPCredentials(httpCredentials sobek.Value) error SetOffline(offline bool) error - WaitForEvent(event string, optsOrPredicate goja.Value) (any, error) + WaitForEvent(event string, optsOrPredicate sobek.Value) (any, error) } // pageAPI is the interface of a single browser tab. type pageAPI interface { BringToFront() error - Check(selector string, opts goja.Value) error - Click(selector string, opts goja.Value) error - Close(opts goja.Value) error + Check(selector string, opts sobek.Value) error + Click(selector string, opts sobek.Value) error + Close(opts sobek.Value) error Content() (string, error) Context() *common.BrowserContext - Dblclick(selector string, opts goja.Value) error - DispatchEvent(selector string, typ string, eventInit goja.Value, opts goja.Value) - EmulateMedia(opts goja.Value) error + Dblclick(selector string, opts sobek.Value) error + DispatchEvent(selector string, typ string, eventInit sobek.Value, opts sobek.Value) + EmulateMedia(opts sobek.Value) error EmulateVisionDeficiency(typ string) error - Evaluate(pageFunc goja.Value, arg ...goja.Value) (any, error) - EvaluateHandle(pageFunc goja.Value, arg ...goja.Value) (common.JSHandleAPI, error) - Fill(selector string, value string, opts goja.Value) error - Focus(selector string, opts goja.Value) error + Evaluate(pageFunc sobek.Value, arg ...sobek.Value) (any, error) + EvaluateHandle(pageFunc sobek.Value, arg ...sobek.Value) (common.JSHandleAPI, error) + Fill(selector string, value string, opts sobek.Value) error + Focus(selector string, opts sobek.Value) error Frames() []*common.Frame - GetAttribute(selector string, name string, opts goja.Value) (string, bool, error) + GetAttribute(selector string, name string, opts sobek.Value) (string, bool, error) GetKeyboard() *common.Keyboard GetMouse() *common.Mouse GetTouchscreen() *common.Touchscreen - Goto(url string, opts goja.Value) (*common.Response, error) - Hover(selector string, opts goja.Value) error - InnerHTML(selector string, opts goja.Value) (string, error) - InnerText(selector string, opts goja.Value) (string, error) - InputValue(selector string, opts goja.Value) (string, error) - IsChecked(selector string, opts goja.Value) (bool, error) + Goto(url string, opts sobek.Value) (*common.Response, error) + Hover(selector string, opts sobek.Value) error + InnerHTML(selector string, opts sobek.Value) (string, error) + InnerText(selector string, opts sobek.Value) (string, error) + InputValue(selector string, opts sobek.Value) (string, error) + IsChecked(selector string, opts sobek.Value) (bool, error) IsClosed() bool - IsDisabled(selector string, opts goja.Value) (bool, error) - IsEditable(selector string, opts goja.Value) (bool, error) - IsEnabled(selector string, opts goja.Value) (bool, error) - IsHidden(selector string, opts goja.Value) (bool, error) - IsVisible(selector string, opts goja.Value) (bool, error) - Locator(selector string, opts goja.Value) *common.Locator + IsDisabled(selector string, opts sobek.Value) (bool, error) + IsEditable(selector string, opts sobek.Value) (bool, error) + IsEnabled(selector string, opts sobek.Value) (bool, error) + IsHidden(selector string, opts sobek.Value) (bool, error) + IsVisible(selector string, opts sobek.Value) (bool, error) + Locator(selector string, opts sobek.Value) *common.Locator MainFrame() *common.Frame On(event string, handler func(*common.ConsoleMessage) error) error Opener() pageAPI - Press(selector string, key string, opts goja.Value) error + Press(selector string, key string, opts sobek.Value) error Query(selector string) (*common.ElementHandle, error) QueryAll(selector string) ([]*common.ElementHandle, error) - Reload(opts goja.Value) *common.Response - Screenshot(opts goja.Value) ([]byte, error) - SelectOption(selector string, values goja.Value, opts goja.Value) ([]string, error) - SetContent(html string, opts goja.Value) error + Reload(opts sobek.Value) *common.Response + Screenshot(opts sobek.Value) ([]byte, error) + SelectOption(selector string, values sobek.Value, opts sobek.Value) ([]string, error) + SetContent(html string, opts sobek.Value) error SetDefaultNavigationTimeout(timeout int64) SetDefaultTimeout(timeout int64) SetExtraHTTPHeaders(headers map[string]string) error - SetInputFiles(selector string, files goja.Value, opts goja.Value) error - SetViewportSize(viewportSize goja.Value) error - Tap(selector string, opts goja.Value) error - TextContent(selector string, opts goja.Value) (string, bool, error) + SetInputFiles(selector string, files sobek.Value, opts sobek.Value) error + SetViewportSize(viewportSize sobek.Value) error + Tap(selector string, opts sobek.Value) error + TextContent(selector string, opts sobek.Value) (string, bool, error) ThrottleCPU(common.CPUProfile) error ThrottleNetwork(common.NetworkProfile) error Title() (string, error) - Type(selector string, text string, opts goja.Value) error - Uncheck(selector string, opts goja.Value) error + Type(selector string, text string, opts sobek.Value) error + Uncheck(selector string, opts sobek.Value) error URL() (string, error) ViewportSize() map[string]float64 - WaitForFunction(fn, opts goja.Value, args ...goja.Value) (any, error) - WaitForLoadState(state string, opts goja.Value) error - WaitForNavigation(opts goja.Value) (*common.Response, error) - WaitForSelector(selector string, opts goja.Value) (*common.ElementHandle, error) + WaitForFunction(fn, opts sobek.Value, args ...sobek.Value) (any, error) + WaitForLoadState(state string, opts sobek.Value) error + WaitForNavigation(opts sobek.Value) (*common.Response, error) + WaitForSelector(selector string, opts sobek.Value) (*common.ElementHandle, error) WaitForTimeout(timeout int64) Workers() []*common.Worker } @@ -367,54 +367,54 @@ type consoleMessageAPI interface { // frameAPI is the interface of a CDP target frame. type frameAPI interface { - Check(selector string, opts goja.Value) error + Check(selector string, opts sobek.Value) error ChildFrames() []*common.Frame - Click(selector string, opts goja.Value) error + Click(selector string, opts sobek.Value) error Content() (string, error) - Dblclick(selector string, opts goja.Value) error - DispatchEvent(selector string, typ string, eventInit goja.Value, opts goja.Value) error + Dblclick(selector string, opts sobek.Value) error + DispatchEvent(selector string, typ string, eventInit sobek.Value, opts sobek.Value) error // EvaluateWithContext for internal use only - EvaluateWithContext(ctx context.Context, pageFunc goja.Value, args ...goja.Value) (any, error) - Evaluate(pageFunc goja.Value, args ...goja.Value) (any, error) - EvaluateHandle(pageFunc goja.Value, args ...goja.Value) (common.JSHandleAPI, error) - Fill(selector string, value string, opts goja.Value) error - Focus(selector string, opts goja.Value) error + EvaluateWithContext(ctx context.Context, pageFunc sobek.Value, args ...sobek.Value) (any, error) + Evaluate(pageFunc sobek.Value, args ...sobek.Value) (any, error) + EvaluateHandle(pageFunc sobek.Value, args ...sobek.Value) (common.JSHandleAPI, error) + Fill(selector string, value string, opts sobek.Value) error + Focus(selector string, opts sobek.Value) error FrameElement() (*common.ElementHandle, error) - GetAttribute(selector string, name string, opts goja.Value) (string, bool, error) - Goto(url string, opts goja.Value) (*common.Response, error) - Hover(selector string, opts goja.Value) error - InnerHTML(selector string, opts goja.Value) (string, error) - InnerText(selector string, opts goja.Value) (string, error) - InputValue(selector string, opts goja.Value) (string, error) - IsChecked(selector string, opts goja.Value) (bool, error) + GetAttribute(selector string, name string, opts sobek.Value) (string, bool, error) + Goto(url string, opts sobek.Value) (*common.Response, error) + Hover(selector string, opts sobek.Value) error + InnerHTML(selector string, opts sobek.Value) (string, error) + InnerText(selector string, opts sobek.Value) (string, error) + InputValue(selector string, opts sobek.Value) (string, error) + IsChecked(selector string, opts sobek.Value) (bool, error) IsDetached() bool - IsDisabled(selector string, opts goja.Value) (bool, error) - IsEditable(selector string, opts goja.Value) (bool, error) - IsEnabled(selector string, opts goja.Value) (bool, error) - IsHidden(selector string, opts goja.Value) (bool, error) - IsVisible(selector string, opts goja.Value) (bool, error) + IsDisabled(selector string, opts sobek.Value) (bool, error) + IsEditable(selector string, opts sobek.Value) (bool, error) + IsEnabled(selector string, opts sobek.Value) (bool, error) + IsHidden(selector string, opts sobek.Value) (bool, error) + IsVisible(selector string, opts sobek.Value) (bool, error) ID() string LoaderID() string - Locator(selector string, opts goja.Value) *common.Locator + Locator(selector string, opts sobek.Value) *common.Locator Name() string Query(selector string) (*common.ElementHandle, error) QueryAll(selector string) ([]*common.ElementHandle, error) Page() *common.Page ParentFrame() *common.Frame - Press(selector string, key string, opts goja.Value) error - SelectOption(selector string, values goja.Value, opts goja.Value) ([]string, error) - SetContent(html string, opts goja.Value) error - SetInputFiles(selector string, files goja.Value, opts goja.Value) - Tap(selector string, opts goja.Value) error - TextContent(selector string, opts goja.Value) (string, bool, error) + Press(selector string, key string, opts sobek.Value) error + SelectOption(selector string, values sobek.Value, opts sobek.Value) ([]string, error) + SetContent(html string, opts sobek.Value) error + SetInputFiles(selector string, files sobek.Value, opts sobek.Value) + Tap(selector string, opts sobek.Value) error + TextContent(selector string, opts sobek.Value) (string, bool, error) Title() string - Type(selector string, text string, opts goja.Value) error - Uncheck(selector string, opts goja.Value) error + Type(selector string, text string, opts sobek.Value) error + Uncheck(selector string, opts sobek.Value) error URL() string - WaitForFunction(pageFunc, opts goja.Value, args ...goja.Value) (any, error) - WaitForLoadState(state string, opts goja.Value) error - WaitForNavigation(opts goja.Value) (*common.Response, error) - WaitForSelector(selector string, opts goja.Value) (*common.ElementHandle, error) + WaitForFunction(pageFunc, opts sobek.Value, args ...sobek.Value) (any, error) + WaitForLoadState(state string, opts sobek.Value) error + WaitForNavigation(opts sobek.Value) (*common.Response, error) + WaitForSelector(selector string, opts sobek.Value) (*common.ElementHandle, error) WaitForTimeout(timeout int64) } @@ -423,18 +423,18 @@ type elementHandleAPI interface { common.JSHandleAPI BoundingBox() (*common.Rect, error) - Check(opts goja.Value) error - Click(opts goja.Value) error + Check(opts sobek.Value) error + Click(opts sobek.Value) error ContentFrame() (*common.Frame, error) - Dblclick(opts goja.Value) error - DispatchEvent(typ string, props goja.Value) error - Fill(value string, opts goja.Value) error + Dblclick(opts sobek.Value) error + DispatchEvent(typ string, props sobek.Value) error + Fill(value string, opts sobek.Value) error Focus() error GetAttribute(name string) (string, bool, error) - Hover(opts goja.Value) error + Hover(opts sobek.Value) error InnerHTML() (string, error) InnerText() (string, error) - InputValue(opts goja.Value) (string, error) + InputValue(opts sobek.Value) (string, error) IsChecked() (bool, error) IsDisabled() (bool, error) IsEditable() (bool, error) @@ -442,37 +442,37 @@ type elementHandleAPI interface { IsHidden() (bool, error) IsVisible() (bool, error) OwnerFrame() (*common.Frame, error) - Press(key string, opts goja.Value) error + Press(key string, opts sobek.Value) error Query(selector string) (*common.ElementHandle, error) QueryAll(selector string) ([]*common.ElementHandle, error) - Screenshot(opts goja.Value) (goja.ArrayBuffer, error) - ScrollIntoViewIfNeeded(opts goja.Value) error - SelectOption(values goja.Value, opts goja.Value) ([]string, error) - SelectText(opts goja.Value) error - SetInputFiles(files goja.Value, opts goja.Value) error - Tap(opts goja.Value) error + Screenshot(opts sobek.Value) (sobek.ArrayBuffer, error) + ScrollIntoViewIfNeeded(opts sobek.Value) error + SelectOption(values sobek.Value, opts sobek.Value) ([]string, error) + SelectText(opts sobek.Value) error + SetInputFiles(files sobek.Value, opts sobek.Value) error + Tap(opts sobek.Value) error TextContent() (string, bool, error) - Type(text string, opts goja.Value) error - Uncheck(opts goja.Value) error - WaitForElementState(state string, opts goja.Value) error - WaitForSelector(selector string, opts goja.Value) (*common.ElementHandle, error) + Type(text string, opts sobek.Value) error + Uncheck(opts sobek.Value) error + WaitForElementState(state string, opts sobek.Value) error + WaitForSelector(selector string, opts sobek.Value) (*common.ElementHandle, error) } // requestAPI is the interface of an HTTP request. type requestAPI interface { AllHeaders() map[string]string Frame() *common.Frame - HeaderValue(string) goja.Value + HeaderValue(string) sobek.Value Headers() map[string]string HeadersArray() []common.HTTPHeader IsNavigationRequest() bool Method() string PostData() string - PostDataBuffer() goja.ArrayBuffer + PostDataBuffer() sobek.ArrayBuffer ResourceType() string Response() *common.Response Size() common.HTTPMessageSize - Timing() goja.Value + Timing() sobek.Value URL() string } @@ -500,30 +500,30 @@ type responseAPI interface { // locatorAPI represents a way to find element(s) on a page at any moment. type locatorAPI interface { Clear(opts *common.FrameFillOptions) error - Click(opts goja.Value) error - Dblclick(opts goja.Value) error - Check(opts goja.Value) error - Uncheck(opts goja.Value) error - IsChecked(opts goja.Value) (bool, error) - IsEditable(opts goja.Value) (bool, error) - IsEnabled(opts goja.Value) (bool, error) - IsDisabled(opts goja.Value) (bool, error) - IsVisible(opts goja.Value) (bool, error) - IsHidden(opts goja.Value) (bool, error) - Fill(value string, opts goja.Value) error - Focus(opts goja.Value) error - GetAttribute(name string, opts goja.Value) (string, bool, error) - InnerHTML(opts goja.Value) (string, error) - InnerText(opts goja.Value) (string, error) - TextContent(opts goja.Value) (string, bool, error) - InputValue(opts goja.Value) (string, error) - SelectOption(values goja.Value, opts goja.Value) ([]string, error) - Press(key string, opts goja.Value) error - Type(text string, opts goja.Value) error - Hover(opts goja.Value) error - Tap(opts goja.Value) error - DispatchEvent(typ string, eventInit, opts goja.Value) - WaitFor(opts goja.Value) error + Click(opts sobek.Value) error + Dblclick(opts sobek.Value) error + Check(opts sobek.Value) error + Uncheck(opts sobek.Value) error + IsChecked(opts sobek.Value) (bool, error) + IsEditable(opts sobek.Value) (bool, error) + IsEnabled(opts sobek.Value) (bool, error) + IsDisabled(opts sobek.Value) (bool, error) + IsVisible(opts sobek.Value) (bool, error) + IsHidden(opts sobek.Value) (bool, error) + Fill(value string, opts sobek.Value) error + Focus(opts sobek.Value) error + GetAttribute(name string, opts sobek.Value) (string, bool, error) + InnerHTML(opts sobek.Value) (string, error) + InnerText(opts sobek.Value) (string, error) + TextContent(opts sobek.Value) (string, bool, error) + InputValue(opts sobek.Value) (string, error) + SelectOption(values sobek.Value, opts sobek.Value) ([]string, error) + Press(key string, opts sobek.Value) error + Type(text string, opts sobek.Value) error + Hover(opts sobek.Value) error + Tap(opts sobek.Value) error + DispatchEvent(typ string, eventInit, opts sobek.Value) + WaitFor(opts sobek.Value) error } // keyboardAPI is the interface of a keyboard input device. @@ -531,8 +531,8 @@ type keyboardAPI interface { Down(key string) error Up(key string) error InsertText(char string) error - Press(key string, opts goja.Value) error - Type(text string, opts goja.Value) error + Press(key string, opts sobek.Value) error + Type(text string, opts sobek.Value) error } // touchscreenAPI is the interface of a touchscreen. @@ -542,11 +542,11 @@ type touchscreenAPI interface { // mouseAPI is the interface of a mouse input device. type mouseAPI interface { - Click(x float64, y float64, opts goja.Value) error - DblClick(x float64, y float64, opts goja.Value) error - Down(opts goja.Value) error - Up(opts goja.Value) error - Move(x float64, y float64, opts goja.Value) error + Click(x float64, y float64, opts sobek.Value) error + DblClick(x float64, y float64, opts sobek.Value) error + Down(opts sobek.Value) error + Up(opts sobek.Value) error + Move(x float64, y float64, opts sobek.Value) error } // workerAPI is the interface of a web worker. diff --git a/browser/module.go b/browser/module.go index aa761a6e8..57bc62c34 100644 --- a/browser/module.go +++ b/browser/module.go @@ -1,6 +1,6 @@ // Package browser is the browser module's entry point, and // initializer of various global types, and a translation layer -// between Goja and the internal business logic. +// between sobek and the internal business logic. // // It initializes and drives the downstream components by passing // the necessary concrete dependencies. @@ -14,7 +14,7 @@ import ( _ "net/http/pprof" //nolint:gosec "sync" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/env" @@ -44,7 +44,7 @@ type ( // JSModule exposes the properties available to the JS script. JSModule struct { - Browser *goja.Object + Browser *sobek.Object Devices map[string]common.Device NetworkProfiles map[string]common.NetworkProfile `js:"networkProfiles"` } @@ -93,9 +93,9 @@ func (m *RootModule) NewModuleInstance(vu k6modules.VU) k6modules.Instance { // decide whether to map the browser module to the async JS API or // the sync one. - mapper := mapBrowserToGoja + mapper := mapBrowserToSobek if m.isSync { - mapper = syncMapBrowserToGoja + mapper = syncMapBrowserToSobek } return &ModuleInstance{ diff --git a/browser/mouse_mapping.go b/browser/mouse_mapping.go index e92c3d835..ee5f61b4d 100644 --- a/browser/mouse_mapping.go +++ b/browser/mouse_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -9,27 +9,27 @@ import ( func mapMouse(vu moduleVU, m *common.Mouse) mapping { return mapping{ - "click": func(x float64, y float64, opts goja.Value) *goja.Promise { + "click": func(x float64, y float64, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, m.Click(x, y, opts) //nolint:wrapcheck }) }, - "dblClick": func(x float64, y float64, opts goja.Value) *goja.Promise { + "dblClick": func(x float64, y float64, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, m.DblClick(x, y, opts) //nolint:wrapcheck }) }, - "down": func(opts goja.Value) *goja.Promise { + "down": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, m.Down(opts) //nolint:wrapcheck }) }, - "up": func(opts goja.Value) *goja.Promise { + "up": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, m.Up(opts) //nolint:wrapcheck }) }, - "move": func(x float64, y float64, opts goja.Value) *goja.Promise { + "move": func(x float64, y float64, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, m.Move(x, y, opts) //nolint:wrapcheck }) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 45c8a895d..5fadac700 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -17,17 +17,17 @@ import ( func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop rt := vu.Runtime() maps := mapping{ - "bringToFront": func() *goja.Promise { + "bringToFront": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.BringToFront() //nolint:wrapcheck }) }, - "check": func(selector string, opts goja.Value) *goja.Promise { + "check": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.Check(selector, opts) //nolint:wrapcheck }) }, - "click": func(selector string, opts goja.Value) (*goja.Promise, error) { + "click": func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameClickOptions(vu.Context(), opts, p.Timeout()) if err != nil { return nil, err @@ -38,13 +38,13 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, err //nolint:wrapcheck }), nil }, - "close": func(opts goja.Value) *goja.Promise { + "close": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { vu.taskQueueRegistry.close(p.TargetID()) return nil, p.Close(opts) //nolint:wrapcheck }) }, - "content": func() *goja.Promise { + "content": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.Content() //nolint:wrapcheck }) @@ -52,12 +52,12 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop "context": func() mapping { return mapBrowserContext(vu, p.Context()) }, - "dblclick": func(selector string, opts goja.Value) *goja.Promise { + "dblclick": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.Dblclick(selector, opts) //nolint:wrapcheck }) }, - "dispatchEvent": func(selector, typ string, eventInit, opts goja.Value) (*goja.Promise, error) { + "dispatchEvent": func(selector, typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameDispatchEventOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing page dispatch event options: %w", err) @@ -66,22 +66,22 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.DispatchEvent(selector, typ, exportArg(eventInit), popts) //nolint:wrapcheck }), nil }, - "emulateMedia": func(opts goja.Value) *goja.Promise { + "emulateMedia": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.EmulateMedia(opts) //nolint:wrapcheck }) }, - "emulateVisionDeficiency": func(typ string) *goja.Promise { + "emulateVisionDeficiency": func(typ string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.EmulateVisionDeficiency(typ) //nolint:wrapcheck }) }, - "evaluate": func(pageFunction goja.Value, gargs ...goja.Value) *goja.Promise { + "evaluate": func(pageFunction sobek.Value, gargs ...sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck }) }, - "evaluateHandle": func(pageFunc goja.Value, gargs ...goja.Value) *goja.Promise { + "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { jsh, err := p.EvaluateHandle(pageFunc.String(), exportArgs(gargs)...) if err != nil { @@ -90,17 +90,17 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return mapJSHandle(vu, jsh), nil }) }, - "fill": func(selector string, value string, opts goja.Value) *goja.Promise { + "fill": func(selector string, value string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.Fill(selector, value, opts) //nolint:wrapcheck }) }, - "focus": func(selector string, opts goja.Value) *goja.Promise { + "focus": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.Focus(selector, opts) //nolint:wrapcheck }) }, - "frames": func() *goja.Object { + "frames": func() *sobek.Object { var ( mfrs []mapping frs = p.Frames() @@ -110,7 +110,7 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return rt.ToValue(mfrs).ToObject(rt) }, - "getAttribute": func(selector string, name string, opts goja.Value) *goja.Promise { + "getAttribute": func(selector string, name string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { s, ok, err := p.GetAttribute(selector, name, opts) if err != nil { @@ -122,7 +122,7 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return s, nil }) }, - "goto": func(url string, opts goja.Value) (*goja.Promise, error) { + "goto": func(url string, opts sobek.Value) (*sobek.Promise, error) { gopts := common.NewFrameGotoOptions( p.Referrer(), p.NavigationTimeout(), @@ -139,73 +139,73 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return mapResponse(vu, resp), nil }), nil }, - "hover": func(selector string, opts goja.Value) *goja.Promise { + "hover": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.Hover(selector, opts) //nolint:wrapcheck }) }, - "innerHTML": func(selector string, opts goja.Value) *goja.Promise { + "innerHTML": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.InnerHTML(selector, opts) //nolint:wrapcheck }) }, - "innerText": func(selector string, opts goja.Value) *goja.Promise { + "innerText": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.InnerText(selector, opts) //nolint:wrapcheck }) }, - "inputValue": func(selector string, opts goja.Value) *goja.Promise { + "inputValue": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.InputValue(selector, opts) //nolint:wrapcheck }) }, - "isChecked": func(selector string, opts goja.Value) *goja.Promise { + "isChecked": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.IsChecked(selector, opts) //nolint:wrapcheck }) }, "isClosed": p.IsClosed, - "isDisabled": func(selector string, opts goja.Value) *goja.Promise { + "isDisabled": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.IsDisabled(selector, opts) //nolint:wrapcheck }) }, - "isEditable": func(selector string, opts goja.Value) *goja.Promise { + "isEditable": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.IsEditable(selector, opts) //nolint:wrapcheck }) }, - "isEnabled": func(selector string, opts goja.Value) *goja.Promise { + "isEnabled": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.IsEnabled(selector, opts) //nolint:wrapcheck }) }, - "isHidden": func(selector string, opts goja.Value) *goja.Promise { + "isHidden": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.IsHidden(selector, opts) //nolint:wrapcheck }) }, - "isVisible": func(selector string, opts goja.Value) *goja.Promise { + "isVisible": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.IsVisible(selector, opts) //nolint:wrapcheck }) }, "keyboard": mapKeyboard(vu, p.GetKeyboard()), - "locator": func(selector string, opts goja.Value) *goja.Object { + "locator": func(selector string, opts sobek.Value) *sobek.Object { ml := mapLocator(vu, p.Locator(selector, opts)) return rt.ToValue(ml).ToObject(rt) }, - "mainFrame": func() *goja.Object { + "mainFrame": func() *sobek.Object { mf := mapFrame(vu, p.MainFrame()) return rt.ToValue(mf).ToObject(rt) }, "mouse": mapMouse(vu, p.GetMouse()), - "on": func(event string, handler goja.Callable) error { + "on": func(event string, handler sobek.Callable) error { tq := vu.taskQueueRegistry.get(p.TargetID()) mapMsgAndHandleEvent := func(m *common.ConsoleMessage) error { mapping := mapConsoleMessage(vu, m) - _, err := handler(goja.Undefined(), vu.Runtime().ToValue(mapping)) + _, err := handler(sobek.Undefined(), vu.Runtime().ToValue(mapping)) return err } runInTaskQueue := func(m *common.ConsoleMessage) { @@ -219,17 +219,17 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.On(event, runInTaskQueue) //nolint:wrapcheck }, - "opener": func() *goja.Promise { + "opener": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.Opener(), nil }) }, - "press": func(selector string, key string, opts goja.Value) *goja.Promise { + "press": func(selector string, key string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.Press(selector, key, opts) //nolint:wrapcheck }) }, - "reload": func(opts goja.Value) *goja.Promise { + "reload": func(opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { resp, err := p.Reload(opts) if err != nil { @@ -241,7 +241,7 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return rt.ToValue(r).ToObject(rt), nil }) }, - "screenshot": func(opts goja.Value) (*goja.Promise, error) { + "screenshot": func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewPageScreenshotOptions() if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing page screenshot options: %w", err) @@ -258,34 +258,34 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return &ab, nil }), nil }, - "selectOption": func(selector string, values goja.Value, opts goja.Value) *goja.Promise { + "selectOption": func(selector string, values sobek.Value, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.SelectOption(selector, values, opts) //nolint:wrapcheck }) }, - "setContent": func(html string, opts goja.Value) *goja.Promise { + "setContent": func(html string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.SetContent(html, opts) //nolint:wrapcheck }) }, "setDefaultNavigationTimeout": p.SetDefaultNavigationTimeout, "setDefaultTimeout": p.SetDefaultTimeout, - "setExtraHTTPHeaders": func(headers map[string]string) *goja.Promise { + "setExtraHTTPHeaders": func(headers map[string]string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.SetExtraHTTPHeaders(headers) //nolint:wrapcheck }) }, - "setInputFiles": func(selector string, files goja.Value, opts goja.Value) *goja.Promise { + "setInputFiles": func(selector string, files sobek.Value, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.SetInputFiles(selector, files, opts) //nolint:wrapcheck }) }, - "setViewportSize": func(viewportSize goja.Value) *goja.Promise { + "setViewportSize": func(viewportSize sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.SetViewportSize(viewportSize) //nolint:wrapcheck }) }, - "tap": func(selector string, opts goja.Value) (*goja.Promise, error) { + "tap": func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameTapOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing page tap options: %w", err) @@ -294,7 +294,7 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Tap(selector, popts) //nolint:wrapcheck }), nil }, - "textContent": func(selector string, opts goja.Value) *goja.Promise { + "textContent": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { s, ok, err := p.TextContent(selector, opts) if err != nil { @@ -306,35 +306,35 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return s, nil }) }, - "throttleCPU": func(cpuProfile common.CPUProfile) *goja.Promise { + "throttleCPU": func(cpuProfile common.CPUProfile) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.ThrottleCPU(cpuProfile) //nolint:wrapcheck }) }, - "throttleNetwork": func(networkProfile common.NetworkProfile) *goja.Promise { + "throttleNetwork": func(networkProfile common.NetworkProfile) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.ThrottleNetwork(networkProfile) //nolint:wrapcheck }) }, - "title": func() *goja.Promise { + "title": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return p.Title() //nolint:wrapcheck }) }, "touchscreen": mapTouchscreen(vu, p.GetTouchscreen()), - "type": func(selector string, text string, opts goja.Value) *goja.Promise { + "type": func(selector string, text string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.Type(selector, text, opts) //nolint:wrapcheck }) }, - "uncheck": func(selector string, opts goja.Value) *goja.Promise { + "uncheck": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.Uncheck(selector, opts) //nolint:wrapcheck }) }, "url": p.URL, "viewportSize": p.ViewportSize, - "waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) { + "waitForFunction": func(pageFunc, opts sobek.Value, args ...sobek.Value) (*sobek.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( vu.Context(), p.Timeout(), pageFunc, opts, args..., ) @@ -346,12 +346,12 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.WaitForFunction(js, popts, pargs...) //nolint:wrapcheck }), nil }, - "waitForLoadState": func(state string, opts goja.Value) *goja.Promise { + "waitForLoadState": func(state string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return nil, p.WaitForLoadState(state, opts) //nolint:wrapcheck }) }, - "waitForNavigation": func(opts goja.Value) (*goja.Promise, error) { + "waitForNavigation": func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameWaitForNavigationOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing page wait for navigation options: %w", err) @@ -365,7 +365,7 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return mapResponse(vu, resp), nil }), nil }, - "waitForSelector": func(selector string, opts goja.Value) *goja.Promise { + "waitForSelector": func(selector string, opts sobek.Value) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { eh, err := p.WaitForSelector(selector, opts) if err != nil { @@ -374,13 +374,13 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return mapElementHandle(vu, eh), nil }) }, - "waitForTimeout": func(timeout int64) *goja.Promise { + "waitForTimeout": func(timeout int64) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { p.WaitForTimeout(timeout) return nil, nil }) }, - "workers": func() *goja.Object { + "workers": func() *sobek.Object { var mws []mapping for _, w := range p.Workers() { mw := mapWorker(vu, w) @@ -389,7 +389,7 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return rt.ToValue(mws).ToObject(rt) }, } - maps["$"] = func(selector string) *goja.Promise { + maps["$"] = func(selector string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { eh, err := p.Query(selector) if err != nil { @@ -406,7 +406,7 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return ehm, nil }) } - maps["$$"] = func(selector string) *goja.Promise { + maps["$$"] = func(selector string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { ehs, err := p.QueryAll(selector) if err != nil { @@ -425,7 +425,7 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } func parseWaitForFunctionArgs( - ctx context.Context, timeout time.Duration, pageFunc, opts goja.Value, gargs ...goja.Value, + ctx context.Context, timeout time.Duration, pageFunc, opts sobek.Value, gargs ...sobek.Value, ) (string, *common.FrameWaitForFunctionOptions, []any, error) { popts := common.NewFrameWaitForFunctionOptions(timeout) err := popts.Parse(ctx, opts) @@ -434,7 +434,7 @@ func parseWaitForFunctionArgs( } js := pageFunc.ToString().String() - _, isCallable := goja.AssertFunction(pageFunc) + _, isCallable := sobek.AssertFunction(pageFunc) if !isCallable { js = fmt.Sprintf("() => (%s)", js) } diff --git a/browser/request_mapping.go b/browser/request_mapping.go index 942477311..a5d714f4b 100644 --- a/browser/request_mapping.go +++ b/browser/request_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -11,22 +11,22 @@ import ( func mapRequest(vu moduleVU, r *common.Request) mapping { rt := vu.Runtime() maps := mapping{ - "allHeaders": func() *goja.Promise { + "allHeaders": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.AllHeaders(), nil }) }, - "frame": func() *goja.Object { + "frame": func() *sobek.Object { mf := mapFrame(vu, r.Frame()) return rt.ToValue(mf).ToObject(rt) }, - "headerValue": func(name string) *goja.Promise { + "headerValue": func(name string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.HeaderValue(name), nil }) }, "headers": r.Headers, - "headersArray": func() *goja.Promise { + "headersArray": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.HeadersArray(), nil }) @@ -48,7 +48,7 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { return rt.NewArrayBuffer(p) }, "resourceType": r.ResourceType, - "response": func() *goja.Promise { + "response": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { resp := r.Response() if resp == nil { diff --git a/browser/response_mapping.go b/browser/response_mapping.go index dc63a5ba9..6bc437565 100644 --- a/browser/response_mapping.go +++ b/browser/response_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -13,12 +13,12 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { //nolint:funlen return nil } maps := mapping{ - "allHeaders": func() *goja.Promise { + "allHeaders": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.AllHeaders(), nil }) }, - "body": func() *goja.Promise { + "body": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { body, err := r.Body() if err != nil { @@ -31,7 +31,7 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { //nolint:funlen "frame": func() mapping { return mapFrame(vu, r.Frame()) }, - "headerValue": func(name string) *goja.Promise { + "headerValue": func(name string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { v, ok := r.HeaderValue(name) if !ok { @@ -40,18 +40,18 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { //nolint:funlen return v, nil }) }, - "headerValues": func(name string) *goja.Promise { + "headerValues": func(name string) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.HeaderValues(name), nil }) }, "headers": r.Headers, - "headersArray": func() *goja.Promise { + "headersArray": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.HeadersArray(), nil }) }, - "json": func() *goja.Promise { + "json": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.JSON() //nolint: wrapcheck }) @@ -60,17 +60,17 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { //nolint:funlen "request": func() mapping { return mapRequest(vu, r.Request()) }, - "securityDetails": func() *goja.Promise { + "securityDetails": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.SecurityDetails(), nil }) }, - "serverAddr": func() *goja.Promise { + "serverAddr": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.ServerAddr(), nil }) }, - "size": func() *goja.Promise { + "size": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.Size(), nil }) @@ -78,7 +78,7 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { //nolint:funlen "status": r.Status, "statusText": r.StatusText, "url": r.URL, - "text": func() *goja.Promise { + "text": func() *sobek.Promise { return k6ext.Promise(vu.Context(), func() (any, error) { return r.Text() //nolint:wrapcheck }) diff --git a/browser/sync_browser_context_mapping.go b/browser/sync_browser_context_mapping.go index ebecf5568..5e8de66d4 100644 --- a/browser/sync_browser_context_mapping.go +++ b/browser/sync_browser_context_mapping.go @@ -4,7 +4,7 @@ import ( "fmt" "reflect" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6error" @@ -16,8 +16,8 @@ func syncMapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //n rt := vu.Runtime() return mapping{ "addCookies": bc.AddCookies, - "addInitScript": func(script goja.Value) error { - if !gojaValueExists(script) { + "addInitScript": func(script sobek.Value) error { + if !sobekValueExists(script) { return nil } @@ -25,7 +25,7 @@ func syncMapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //n switch script.ExportType() { case reflect.TypeOf(string("")): source = script.String() - case reflect.TypeOf(goja.Object{}): + case reflect.TypeOf(sobek.Object{}): opts := script.ToObject(rt) for _, k := range opts.Keys() { if k == "content" { @@ -33,7 +33,7 @@ func syncMapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //n } } default: - _, isCallable := goja.AssertFunction(script) + _, isCallable := sobek.AssertFunction(script) if !isCallable { source = fmt.Sprintf("(%s);", script.ToString().String()) } else { @@ -48,7 +48,7 @@ func syncMapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //n "clearPermissions": bc.ClearPermissions, "close": bc.Close, "cookies": bc.Cookies, - "grantPermissions": func(permissions []string, opts goja.Value) error { + "grantPermissions": func(permissions []string, opts sobek.Value) error { pOpts := common.NewGrantPermissionsOptions() pOpts.Parse(vu.Context(), opts) @@ -59,7 +59,7 @@ func syncMapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //n "setGeolocation": bc.SetGeolocation, "setHTTPCredentials": bc.SetHTTPCredentials, //nolint:staticcheck "setOffline": bc.SetOffline, - "waitForEvent": func(event string, optsOrPredicate goja.Value) (*goja.Promise, error) { + "waitForEvent": func(event string, optsOrPredicate sobek.Value) (*sobek.Promise, error) { ctx := vu.Context() popts := common.NewWaitForEventOptions( bc.Timeout(), @@ -81,7 +81,7 @@ func syncMapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //n // before returning the result to the caller. c := make(chan bool) tq.Queue(func() error { - var resp goja.Value + var resp sobek.Value resp, err = popts.PredicateFn(vu.Runtime().ToValue(p)) rtn = resp.ToBoolean() close(c) @@ -106,7 +106,7 @@ func syncMapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //n return syncMapPage(vu, p), nil }), nil }, - "pages": func() *goja.Object { + "pages": func() *sobek.Object { var ( mpages []mapping pages = bc.Pages() diff --git a/browser/sync_browser_mapping.go b/browser/sync_browser_mapping.go index 8671022fe..400e31ca6 100644 --- a/browser/sync_browser_mapping.go +++ b/browser/sync_browser_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" ) // syncMapBrowser is like mapBrowser but returns synchronous functions. @@ -29,7 +29,7 @@ func syncMapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop } return b.IsConnected(), nil }, - "newContext": func(opts goja.Value) (*goja.Object, error) { + "newContext": func(opts sobek.Value) (*sobek.Object, error) { b, err := vu.browser() if err != nil { return nil, err @@ -61,7 +61,7 @@ func syncMapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop } return b.Version(), nil }, - "newPage": func(opts goja.Value) (mapping, error) { + "newPage": func(opts sobek.Value) (mapping, error) { b, err := vu.browser() if err != nil { return nil, err diff --git a/browser/sync_console_message_mapping.go b/browser/sync_console_message_mapping.go index 970d441b5..6884c2a08 100644 --- a/browser/sync_console_message_mapping.go +++ b/browser/sync_console_message_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" ) @@ -10,7 +10,7 @@ import ( func syncMapConsoleMessage(vu moduleVU, cm *common.ConsoleMessage) mapping { rt := vu.Runtime() return mapping{ - "args": func() *goja.Object { + "args": func() *sobek.Object { var ( margs []mapping args = cm.Args diff --git a/browser/sync_element_handle_mapping.go b/browser/sync_element_handle_mapping.go index 9ef1dcb45..e9375f100 100644 --- a/browser/sync_element_handle_mapping.go +++ b/browser/sync_element_handle_mapping.go @@ -3,7 +3,7 @@ package browser import ( "fmt" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -15,7 +15,7 @@ func syncMapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nol maps := mapping{ "boundingBox": eh.BoundingBox, "check": eh.Check, - "click": func(opts goja.Value) (*goja.Promise, error) { + "click": func(opts sobek.Value) (*sobek.Promise, error) { ctx := vu.Context() popts := common.NewElementHandleClickOptions(eh.Timeout()) @@ -36,7 +36,7 @@ func syncMapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nol return syncMapFrame(vu, f), nil }, "dblclick": eh.Dblclick, - "dispatchEvent": func(typ string, eventInit goja.Value) error { + "dispatchEvent": func(typ string, eventInit sobek.Value) error { return eh.DispatchEvent(typ, exportArg(eventInit)) //nolint:wrapcheck }, "fill": eh.Fill, @@ -69,7 +69,7 @@ func syncMapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nol return syncMapFrame(vu, f), nil }, "press": eh.Press, - "screenshot": func(opts goja.Value) (*goja.ArrayBuffer, error) { + "screenshot": func(opts sobek.Value) (*sobek.ArrayBuffer, error) { ctx := vu.Context() popts := common.NewElementHandleScreenshotOptions(eh.Timeout()) @@ -90,7 +90,7 @@ func syncMapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nol "selectOption": eh.SelectOption, "selectText": eh.SelectText, "setInputFiles": eh.SetInputFiles, - "tap": func(opts goja.Value) (*goja.Promise, error) { + "tap": func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewElementHandleTapOptions(eh.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing element tap options: %w", err) @@ -112,7 +112,7 @@ func syncMapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nol "type": eh.Type, "uncheck": eh.Uncheck, "waitForElementState": eh.WaitForElementState, - "waitForSelector": func(selector string, opts goja.Value) (mapping, error) { + "waitForSelector": func(selector string, opts sobek.Value) (mapping, error) { eh, err := eh.WaitForSelector(selector, opts) if err != nil { return nil, err //nolint:wrapcheck diff --git a/browser/sync_frame_mapping.go b/browser/sync_frame_mapping.go index 309f4547c..0cde42859 100644 --- a/browser/sync_frame_mapping.go +++ b/browser/sync_frame_mapping.go @@ -3,7 +3,7 @@ package browser import ( "fmt" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -14,7 +14,7 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl rt := vu.Runtime() maps := mapping{ "check": f.Check, - "childFrames": func() *goja.Object { + "childFrames": func() *sobek.Object { var ( mcfs []mapping cfs = f.ChildFrames() @@ -24,7 +24,7 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl } return rt.ToValue(mcfs).ToObject(rt) }, - "click": func(selector string, opts goja.Value) (*goja.Promise, error) { + "click": func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameClickOptions(vu.Context(), opts, f.Timeout()) if err != nil { return nil, err @@ -37,17 +37,17 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl }, "content": f.Content, "dblclick": f.Dblclick, - "dispatchEvent": func(selector, typ string, eventInit, opts goja.Value) error { + "dispatchEvent": func(selector, typ string, eventInit, opts sobek.Value) error { popts := common.NewFrameDispatchEventOptions(f.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return fmt.Errorf("parsing frame dispatch event options: %w", err) } return f.DispatchEvent(selector, typ, exportArg(eventInit), popts) //nolint:wrapcheck }, - "evaluate": func(pageFunction goja.Value, gargs ...goja.Value) (any, error) { + "evaluate": func(pageFunction sobek.Value, gargs ...sobek.Value) (any, error) { return f.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck }, - "evaluateHandle": func(pageFunction goja.Value, gargs ...goja.Value) (mapping, error) { + "evaluateHandle": func(pageFunction sobek.Value, gargs ...sobek.Value) (mapping, error) { jsh, err := f.EvaluateHandle(pageFunction.String(), exportArgs(gargs)...) if err != nil { return nil, err //nolint:wrapcheck @@ -63,7 +63,7 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl } return syncMapElementHandle(vu, fe), nil }, - "getAttribute": func(selector, name string, opts goja.Value) (any, error) { + "getAttribute": func(selector, name string, opts sobek.Value) (any, error) { v, ok, err := f.GetAttribute(selector, name, opts) if err != nil { return nil, err //nolint:wrapcheck @@ -73,7 +73,7 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl } return v, nil }, - "goto": func(url string, opts goja.Value) (*goja.Promise, error) { + "goto": func(url string, opts sobek.Value) (*sobek.Promise, error) { gopts := common.NewFrameGotoOptions( f.Referrer(), f.NavigationTimeout(), @@ -101,16 +101,16 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl "isEnabled": f.IsEnabled, "isHidden": f.IsHidden, "isVisible": f.IsVisible, - "locator": func(selector string, opts goja.Value) *goja.Object { + "locator": func(selector string, opts sobek.Value) *sobek.Object { ml := syncMapLocator(vu, f.Locator(selector, opts)) return rt.ToValue(ml).ToObject(rt) }, "name": f.Name, - "page": func() *goja.Object { + "page": func() *sobek.Object { mp := syncMapPage(vu, f.Page()) return rt.ToValue(mp).ToObject(rt) }, - "parentFrame": func() *goja.Object { + "parentFrame": func() *sobek.Object { mf := syncMapFrame(vu, f.ParentFrame()) return rt.ToValue(mf).ToObject(rt) }, @@ -118,7 +118,7 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl "selectOption": f.SelectOption, "setContent": f.SetContent, "setInputFiles": f.SetInputFiles, - "tap": func(selector string, opts goja.Value) (*goja.Promise, error) { + "tap": func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameTapOptions(f.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing frame tap options: %w", err) @@ -127,7 +127,7 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl return nil, f.Tap(selector, popts) //nolint:wrapcheck }), nil }, - "textContent": func(selector string, opts goja.Value) (any, error) { + "textContent": func(selector string, opts sobek.Value) (any, error) { v, ok, err := f.TextContent(selector, opts) if err != nil { return nil, err //nolint:wrapcheck @@ -141,7 +141,7 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl "type": f.Type, "uncheck": f.Uncheck, "url": f.URL, - "waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) { + "waitForFunction": func(pageFunc, opts sobek.Value, args ...sobek.Value) (*sobek.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( vu.Context(), f.Timeout(), pageFunc, opts, args..., ) @@ -154,7 +154,7 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl }), nil }, "waitForLoadState": f.WaitForLoadState, - "waitForNavigation": func(opts goja.Value) (*goja.Promise, error) { + "waitForNavigation": func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameWaitForNavigationOptions(f.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing frame wait for navigation options: %w", err) @@ -168,7 +168,7 @@ func syncMapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cycl return syncMapResponse(vu, resp), nil }), nil }, - "waitForSelector": func(selector string, opts goja.Value) (mapping, error) { + "waitForSelector": func(selector string, opts sobek.Value) (mapping, error) { eh, err := f.WaitForSelector(selector, opts) if err != nil { return nil, err //nolint:wrapcheck diff --git a/browser/sync_js_handle_mapping.go b/browser/sync_js_handle_mapping.go index 04302776c..dda134547 100644 --- a/browser/sync_js_handle_mapping.go +++ b/browser/sync_js_handle_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" ) @@ -10,19 +10,19 @@ import ( func syncMapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { rt := vu.Runtime() return mapping{ - "asElement": func() *goja.Object { + "asElement": func() *sobek.Object { m := syncMapElementHandle(vu, jsh.AsElement()) return rt.ToValue(m).ToObject(rt) }, "dispose": jsh.Dispose, - "evaluate": func(pageFunc goja.Value, gargs ...goja.Value) (any, error) { + "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) (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 }, - "evaluateHandle": func(pageFunc goja.Value, gargs ...goja.Value) (mapping, error) { + "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) (mapping, error) { h, err := jsh.EvaluateHandle(pageFunc.String(), exportArgs(gargs)...) if err != nil { return nil, err //nolint:wrapcheck diff --git a/browser/sync_locator_mapping.go b/browser/sync_locator_mapping.go index 46c364899..fa15bf502 100644 --- a/browser/sync_locator_mapping.go +++ b/browser/sync_locator_mapping.go @@ -3,7 +3,7 @@ package browser import ( "fmt" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -12,7 +12,7 @@ import ( // syncMapLocator is like mapLocator but returns synchronous functions. func syncMapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen return mapping{ - "clear": func(opts goja.Value) error { + "clear": func(opts sobek.Value) error { ctx := vu.Context() copts := common.NewFrameFillOptions(lo.Timeout()) @@ -22,7 +22,7 @@ func syncMapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen return lo.Clear(copts) //nolint:wrapcheck }, - "click": func(opts goja.Value) (*goja.Promise, error) { + "click": func(opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameClickOptions(vu.Context(), opts, lo.Timeout()) if err != nil { return nil, err @@ -43,7 +43,7 @@ func syncMapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen "isHidden": lo.IsHidden, "fill": lo.Fill, "focus": lo.Focus, - "getAttribute": func(name string, opts goja.Value) (any, error) { + "getAttribute": func(name string, opts sobek.Value) (any, error) { v, ok, err := lo.GetAttribute(name, opts) if err != nil { return nil, err //nolint:wrapcheck @@ -55,7 +55,7 @@ func syncMapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen }, "innerHTML": lo.InnerHTML, "innerText": lo.InnerText, - "textContent": func(opts goja.Value) (any, error) { + "textContent": func(opts sobek.Value) (any, error) { v, ok, err := lo.TextContent(opts) if err != nil { return nil, err //nolint:wrapcheck @@ -70,7 +70,7 @@ func syncMapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen "press": lo.Press, "type": lo.Type, "hover": lo.Hover, - "tap": func(opts goja.Value) (*goja.Promise, error) { + "tap": func(opts sobek.Value) (*sobek.Promise, error) { copts := common.NewFrameTapOptions(lo.DefaultTimeout()) if err := copts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing locator tap options: %w", err) @@ -79,7 +79,7 @@ func syncMapLocator(vu moduleVU, lo *common.Locator) mapping { //nolint:funlen return nil, lo.Tap(copts) //nolint:wrapcheck }), nil }, - "dispatchEvent": func(typ string, eventInit, opts goja.Value) error { + "dispatchEvent": func(typ string, eventInit, opts sobek.Value) error { popts := common.NewFrameDispatchEventOptions(lo.DefaultTimeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return fmt.Errorf("parsing locator dispatch event options: %w", err) diff --git a/browser/sync_mapping.go b/browser/sync_mapping.go index e1ba7abe1..137132be2 100644 --- a/browser/sync_mapping.go +++ b/browser/sync_mapping.go @@ -3,14 +3,14 @@ package browser import ( "fmt" - "github.com/dop251/goja" + "github.com/grafana/sobek" k6common "go.k6.io/k6/js/common" ) -// syncMapBrowserToGoja maps the browser API to the JS module as a +// syncMapBrowserToSobek maps the browser API to the JS module as a // synchronous version. -func syncMapBrowserToGoja(vu moduleVU) *goja.Object { +func syncMapBrowserToSobek(vu moduleVU) *sobek.Object { var ( rt = vu.Runtime() obj = rt.NewObject() diff --git a/browser/sync_page_mapping.go b/browser/sync_page_mapping.go index c4cdddf98..19a6a7a7f 100644 --- a/browser/sync_page_mapping.go +++ b/browser/sync_page_mapping.go @@ -3,7 +3,7 @@ package browser import ( "fmt" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -15,7 +15,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop maps := mapping{ "bringToFront": p.BringToFront, "check": p.Check, - "click": func(selector string, opts goja.Value) (*goja.Promise, error) { + "click": func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts, err := parseFrameClickOptions(vu.Context(), opts, p.Timeout()) if err != nil { return nil, err @@ -26,7 +26,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, err //nolint:wrapcheck }), nil }, - "close": func(opts goja.Value) error { + "close": func(opts sobek.Value) error { vu.taskQueueRegistry.close(p.TargetID()) return p.Close(opts) //nolint:wrapcheck @@ -34,7 +34,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop "content": p.Content, "context": p.Context, "dblclick": p.Dblclick, - "dispatchEvent": func(selector, typ string, eventInit, opts goja.Value) error { + "dispatchEvent": func(selector, typ string, eventInit, opts sobek.Value) error { popts := common.NewFrameDispatchEventOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return fmt.Errorf("parsing page dispatch event options: %w", err) @@ -43,10 +43,10 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop }, "emulateMedia": p.EmulateMedia, "emulateVisionDeficiency": p.EmulateVisionDeficiency, - "evaluate": func(pageFunction goja.Value, gargs ...goja.Value) (any, error) { + "evaluate": func(pageFunction sobek.Value, gargs ...sobek.Value) (any, error) { return p.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck }, - "evaluateHandle": func(pageFunc goja.Value, gargs ...goja.Value) (mapping, error) { + "evaluateHandle": func(pageFunc sobek.Value, gargs ...sobek.Value) (mapping, error) { jsh, err := p.EvaluateHandle(pageFunc.String(), exportArgs(gargs)...) if err != nil { return nil, err //nolint:wrapcheck @@ -55,7 +55,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop }, "fill": p.Fill, "focus": p.Focus, - "frames": func() *goja.Object { + "frames": func() *sobek.Object { var ( mfrs []mapping frs = p.Frames() @@ -65,7 +65,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return rt.ToValue(mfrs).ToObject(rt) }, - "getAttribute": func(selector string, name string, opts goja.Value) (any, error) { + "getAttribute": func(selector string, name string, opts sobek.Value) (any, error) { v, ok, err := p.GetAttribute(selector, name, opts) if err != nil { return nil, err //nolint:wrapcheck @@ -75,7 +75,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return v, nil }, - "goto": func(url string, opts goja.Value) (*goja.Promise, error) { + "goto": func(url string, opts sobek.Value) (*sobek.Promise, error) { gopts := common.NewFrameGotoOptions( p.Referrer(), p.NavigationTimeout(), @@ -104,21 +104,21 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop "isHidden": p.IsHidden, "isVisible": p.IsVisible, "keyboard": rt.ToValue(p.GetKeyboard()).ToObject(rt), - "locator": func(selector string, opts goja.Value) *goja.Object { + "locator": func(selector string, opts sobek.Value) *sobek.Object { ml := syncMapLocator(vu, p.Locator(selector, opts)) return rt.ToValue(ml).ToObject(rt) }, - "mainFrame": func() *goja.Object { + "mainFrame": func() *sobek.Object { mf := syncMapFrame(vu, p.MainFrame()) return rt.ToValue(mf).ToObject(rt) }, "mouse": rt.ToValue(p.GetMouse()).ToObject(rt), - "on": func(event string, handler goja.Callable) error { + "on": func(event string, handler sobek.Callable) error { tq := vu.taskQueueRegistry.get(p.TargetID()) mapMsgAndHandleEvent := func(m *common.ConsoleMessage) error { mapping := syncMapConsoleMessage(vu, m) - _, err := handler(goja.Undefined(), vu.Runtime().ToValue(mapping)) + _, err := handler(sobek.Undefined(), vu.Runtime().ToValue(mapping)) return err } runInTaskQueue := func(m *common.ConsoleMessage) { @@ -134,7 +134,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop }, "opener": p.Opener, "press": p.Press, - "reload": func(opts goja.Value) (*goja.Object, error) { + "reload": func(opts sobek.Value) (*sobek.Object, error) { resp, err := p.Reload(opts) if err != nil { return nil, err //nolint:wrapcheck @@ -144,7 +144,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return rt.ToValue(r).ToObject(rt), nil }, - "screenshot": func(opts goja.Value) (*goja.ArrayBuffer, error) { + "screenshot": func(opts sobek.Value) (*sobek.ArrayBuffer, error) { ctx := vu.Context() popts := common.NewPageScreenshotOptions() @@ -168,7 +168,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop "setExtraHTTPHeaders": p.SetExtraHTTPHeaders, "setInputFiles": p.SetInputFiles, "setViewportSize": p.SetViewportSize, - "tap": func(selector string, opts goja.Value) (*goja.Promise, error) { + "tap": func(selector string, opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameTapOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing page tap options: %w", err) @@ -177,7 +177,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Tap(selector, popts) //nolint:wrapcheck }), nil }, - "textContent": func(selector string, opts goja.Value) (any, error) { + "textContent": func(selector string, opts sobek.Value) (any, error) { v, ok, err := p.TextContent(selector, opts) if err != nil { return nil, err //nolint:wrapcheck @@ -195,7 +195,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop "uncheck": p.Uncheck, "url": p.URL, "viewportSize": p.ViewportSize, - "waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) { + "waitForFunction": func(pageFunc, opts sobek.Value, args ...sobek.Value) (*sobek.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( vu.Context(), p.Timeout(), pageFunc, opts, args..., ) @@ -208,7 +208,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop }), nil }, "waitForLoadState": p.WaitForLoadState, - "waitForNavigation": func(opts goja.Value) (*goja.Promise, error) { + "waitForNavigation": func(opts sobek.Value) (*sobek.Promise, error) { popts := common.NewFrameWaitForNavigationOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing page wait for navigation options: %w", err) @@ -222,7 +222,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return syncMapResponse(vu, resp), nil }), nil }, - "waitForSelector": func(selector string, opts goja.Value) (mapping, error) { + "waitForSelector": func(selector string, opts sobek.Value) (mapping, error) { eh, err := p.WaitForSelector(selector, opts) if err != nil { return nil, err //nolint:wrapcheck @@ -230,7 +230,7 @@ func syncMapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return syncMapElementHandle(vu, eh), nil }, "waitForTimeout": p.WaitForTimeout, - "workers": func() *goja.Object { + "workers": func() *sobek.Object { var mws []mapping for _, w := range p.Workers() { mw := syncMapWorker(vu, w) diff --git a/browser/sync_touchscreen_mapping.go b/browser/sync_touchscreen_mapping.go index 2a97b1519..88537dc36 100644 --- a/browser/sync_touchscreen_mapping.go +++ b/browser/sync_touchscreen_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -10,7 +10,7 @@ import ( // syncMapTouchscreen is like mapTouchscreen but returns synchronous functions. func syncMapTouchscreen(vu moduleVU, ts *common.Touchscreen) mapping { return mapping{ - "tap": func(x float64, y float64) *goja.Promise { + "tap": func(x float64, y float64) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (result any, reason error) { return nil, ts.Tap(x, y) //nolint:wrapcheck }) diff --git a/browser/touchscreen_mapping.go b/browser/touchscreen_mapping.go index 1c665228a..ea18f95db 100644 --- a/browser/touchscreen_mapping.go +++ b/browser/touchscreen_mapping.go @@ -1,7 +1,7 @@ package browser import ( - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/k6ext" @@ -10,7 +10,7 @@ import ( // mapTouchscreen to the JS module. func mapTouchscreen(vu moduleVU, ts *common.Touchscreen) mapping { return mapping{ - "tap": func(x float64, y float64) *goja.Promise { + "tap": func(x float64, y float64) *sobek.Promise { return k6ext.Promise(vu.Context(), func() (result any, reason error) { return nil, ts.Tap(x, y) //nolint:wrapcheck }) diff --git a/chromium/browser_type.go b/chromium/browser_type.go index 40467fa86..ed3c2f4b4 100644 --- a/chromium/browser_type.go +++ b/chromium/browser_type.go @@ -36,7 +36,7 @@ type BrowserType struct { } // NewBrowserType registers our custom k6 metrics, creates method mappings on -// the goja runtime, and returns a new Chrome browser type. +// the sobek runtime, and returns a new Chrome browser type. func NewBrowserType(vu k6modules.VU) *BrowserType { // NOTE: vu.InitEnv() *must* be called from the script init scope, // otherwise it will return nil. diff --git a/common/browser.go b/common/browser.go index a4b4e1829..c1b9bc98c 100644 --- a/common/browser.go +++ b/common/browser.go @@ -9,17 +9,17 @@ import ( "sync/atomic" "time" - "github.com/grafana/xk6-browser/k6ext" - "github.com/grafana/xk6-browser/log" - - k6modules "go.k6.io/k6/js/modules" - "github.com/chromedp/cdproto" cdpbrowser "github.com/chromedp/cdproto/browser" "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/target" - "github.com/dop251/goja" "github.com/gorilla/websocket" + "github.com/grafana/sobek" + + "github.com/grafana/xk6-browser/k6ext" + "github.com/grafana/xk6-browser/log" + + k6modules "go.k6.io/k6/js/modules" ) const ( @@ -569,7 +569,7 @@ func (b *Browser) IsConnected() bool { } // NewContext creates a new incognito-like browser context. -func (b *Browser) NewContext(opts goja.Value) (*BrowserContext, error) { +func (b *Browser) NewContext(opts sobek.Value) (*BrowserContext, error) { _, span := TraceAPICall(b.ctx, "", "browser.newContext") defer span.End() @@ -610,7 +610,7 @@ func (b *Browser) NewContext(opts goja.Value) (*BrowserContext, error) { } // NewPage creates a new tab in the browser window. -func (b *Browser) NewPage(opts goja.Value) (*Page, error) { +func (b *Browser) NewPage(opts sobek.Value) (*Page, error) { _, span := TraceAPICall(b.ctx, "", "browser.newPage") defer span.End() diff --git a/common/browser_context.go b/common/browser_context.go index 8a9aa20d5..30a10a89a 100644 --- a/common/browser_context.go +++ b/common/browser_context.go @@ -7,19 +7,19 @@ import ( "strings" "time" + cdpbrowser "github.com/chromedp/cdproto/browser" + "github.com/chromedp/cdproto/cdp" + "github.com/chromedp/cdproto/network" + "github.com/chromedp/cdproto/storage" + "github.com/chromedp/cdproto/target" + "github.com/grafana/sobek" + "github.com/grafana/xk6-browser/common/js" "github.com/grafana/xk6-browser/k6error" "github.com/grafana/xk6-browser/k6ext" "github.com/grafana/xk6-browser/log" k6modules "go.k6.io/k6/js/modules" - - cdpbrowser "github.com/chromedp/cdproto/browser" - "github.com/chromedp/cdproto/cdp" - "github.com/chromedp/cdproto/network" - "github.com/chromedp/cdproto/storage" - "github.com/chromedp/cdproto/target" - "github.com/dop251/goja" ) // waitForEventType represents the event types that can be used when working @@ -260,7 +260,7 @@ func (b *BrowserContext) SetDefaultTimeout(timeout int64) { } // SetGeolocation overrides the geo location of the user. -func (b *BrowserContext) SetGeolocation(geolocation goja.Value) error { +func (b *BrowserContext) SetGeolocation(geolocation sobek.Value) error { b.logger.Debugf("BrowserContext:SetGeolocation", "bctxid:%v", b.id) g := NewGeolocation() @@ -284,7 +284,7 @@ func (b *BrowserContext) SetGeolocation(geolocation goja.Value) error { // See for details: // - https://github.com/microsoft/playwright/issues/2196#issuecomment-627134837 // - https://github.com/microsoft/playwright/pull/2763 -func (b *BrowserContext) SetHTTPCredentials(httpCredentials goja.Value) error { +func (b *BrowserContext) SetHTTPCredentials(httpCredentials sobek.Value) error { b.logger.Warnf("setHTTPCredentials", "setHTTPCredentials is deprecated."+ " Create a new BrowserContext with httpCredentials instead.") b.logger.Debugf("BrowserContext:SetHTTPCredentials", "bctxid:%v", b.id) diff --git a/common/browser_context_options.go b/common/browser_context_options.go index a47b02942..25cb0731c 100644 --- a/common/browser_context_options.go +++ b/common/browser_context_options.go @@ -6,9 +6,9 @@ import ( "fmt" "time" - "github.com/grafana/xk6-browser/k6ext" + "github.com/grafana/sobek" - "github.com/dop251/goja" + "github.com/grafana/xk6-browser/k6ext" ) // Geolocation represents a geolocation. @@ -24,13 +24,13 @@ func NewGeolocation() *Geolocation { } // Parse parses the geolocation options. -func (g *Geolocation) Parse(ctx context.Context, opts goja.Value) error { //nolint:cyclop +func (g *Geolocation) Parse(ctx context.Context, opts sobek.Value) error { //nolint:cyclop rt := k6ext.Runtime(ctx) longitude := 0.0 latitude := 0.0 accuracy := 0.0 - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -100,9 +100,9 @@ func NewBrowserContextOptions() *BrowserContextOptions { } } -func (b *BrowserContextOptions) Parse(ctx context.Context, opts goja.Value) error { +func (b *BrowserContextOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -188,7 +188,7 @@ func (b *BrowserContextOptions) Parse(ctx context.Context, opts goja.Value) erro // WaitForEventOptions are the options used by the browserContext.waitForEvent API. type WaitForEventOptions struct { Timeout time.Duration - PredicateFn goja.Callable + PredicateFn sobek.Callable } // NewWaitForEventOptions created a new instance of WaitForEventOptions with a @@ -202,8 +202,8 @@ func NewWaitForEventOptions(defaultTimeout time.Duration) *WaitForEventOptions { // Parse will parse the options or a callable predicate function. It can parse // only a callable predicate function or an object which contains a callable // predicate function and a timeout. -func (w *WaitForEventOptions) Parse(ctx context.Context, optsOrPredicate goja.Value) error { - if !gojaValueExists(optsOrPredicate) { +func (w *WaitForEventOptions) Parse(ctx context.Context, optsOrPredicate sobek.Value) error { + if !sobekValueExists(optsOrPredicate) { return nil } @@ -212,7 +212,7 @@ func (w *WaitForEventOptions) Parse(ctx context.Context, optsOrPredicate goja.Va rt = k6ext.Runtime(ctx) ) - w.PredicateFn, isCallable = goja.AssertFunction(optsOrPredicate) + w.PredicateFn, isCallable = sobek.AssertFunction(optsOrPredicate) if isCallable { return nil } @@ -221,7 +221,7 @@ func (w *WaitForEventOptions) Parse(ctx context.Context, optsOrPredicate goja.Va for _, k := range opts.Keys() { switch k { case "predicate": - w.PredicateFn, isCallable = goja.AssertFunction(opts.Get(k)) + w.PredicateFn, isCallable = sobek.AssertFunction(opts.Get(k)) if !isCallable { return errors.New("predicate function is not callable") } @@ -243,11 +243,11 @@ func NewGrantPermissionsOptions() *GrantPermissionsOptions { return &GrantPermissionsOptions{} } -// Parse parses the options from opts if opts exists in the Goja runtime. -func (g *GrantPermissionsOptions) Parse(ctx context.Context, opts goja.Value) { +// Parse parses the options from opts if opts exists in the sobek runtime. +func (g *GrantPermissionsOptions) Parse(ctx context.Context, opts sobek.Value) { rt := k6ext.Runtime(ctx) - if gojaValueExists(opts) { + if sobekValueExists(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { if k == "origin" { diff --git a/common/browser_context_options_test.go b/common/browser_context_options_test.go index c2cdc492a..afc25aab8 100644 --- a/common/browser_context_options_test.go +++ b/common/browser_context_options_test.go @@ -12,7 +12,7 @@ func TestBrowserContextOptionsPermissions(t *testing.T) { vu := k6test.NewVU(t) var opts BrowserContextOptions - err := opts.Parse(vu.Context(), vu.ToGojaValue((struct { + err := opts.Parse(vu.Context(), vu.ToSobekValue((struct { Permissions []any `js:"permissions"` }{ Permissions: []any{"camera", "microphone"}, diff --git a/common/connection.go b/common/connection.go index d8e1923c4..40645ec36 100644 --- a/common/connection.go +++ b/common/connection.go @@ -16,8 +16,8 @@ import ( "github.com/chromedp/cdproto/cdp" cdpruntime "github.com/chromedp/cdproto/runtime" "github.com/chromedp/cdproto/target" - "github.com/dop251/goja" "github.com/gorilla/websocket" + "github.com/grafana/sobek" "github.com/mailru/easyjson" "github.com/mailru/easyjson/jlexer" "github.com/mailru/easyjson/jwriter" @@ -51,7 +51,7 @@ type executorEmitter interface { type connection interface { executorEmitter - Close(...goja.Value) + Close(...sobek.Value) IgnoreIOErrors() getSession(target.SessionID) *Session } @@ -559,7 +559,7 @@ func (c *Connection) sendLoop() { // Close cleanly closes the WebSocket connection. // It returns an error if sending the Close control frame fails. -func (c *Connection) Close(args ...goja.Value) { +func (c *Connection) Close(args ...sobek.Value) { code := websocket.CloseGoingAway if len(args) > 0 { code = int(args[0].ToInteger()) diff --git a/common/element_handle.go b/common/element_handle.go index f6a9418fc..5c9d25f54 100644 --- a/common/element_handle.go +++ b/common/element_handle.go @@ -12,7 +12,7 @@ import ( "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/dom" cdppage "github.com/chromedp/cdproto/page" - "github.com/dop251/goja" + "github.com/grafana/sobek" "go.opentelemetry.io/otel/attribute" "github.com/grafana/xk6-browser/common/js" @@ -477,9 +477,9 @@ func (h *ElementHandle) press(apiCtx context.Context, key string, opts *Keyboard } //nolint:funlen,gocognit,cyclop -func (h *ElementHandle) selectOption(apiCtx context.Context, values goja.Value) (any, error) { - convertSelectOptionValues := func(values goja.Value) ([]any, error) { - if goja.IsNull(values) || goja.IsUndefined(values) { +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) { return nil, nil } @@ -498,7 +498,7 @@ func (h *ElementHandle) selectOption(apiCtx context.Context, values goja.Value) return nil, fmt.Errorf("options[%d]: expected object, got null", i) case reflect.TypeOf(&ElementHandle{}).Kind(): opts = append(opts, t.(*ElementHandle)) - case reflect.TypeOf(goja.Object{}).Kind(): + case reflect.TypeOf(sobek.Object{}).Kind(): obj := values.ToObject(rt) opt := SelectOption{} for _, k := range obj.Keys() { @@ -523,7 +523,7 @@ func (h *ElementHandle) selectOption(apiCtx context.Context, values goja.Value) } case reflect.TypeOf(&ElementHandle{}).Kind(): opts = append(opts, t.(*ElementHandle)) - case reflect.TypeOf(goja.Object{}).Kind(): + case reflect.TypeOf(sobek.Object{}).Kind(): obj := values.ToObject(rt) opt := SelectOption{} for _, k := range obj.Keys() { @@ -761,7 +761,7 @@ func (h *ElementHandle) ContentFrame() (*Frame, error) { } // Dblclick scrolls element into view and double clicks on the element. -func (h *ElementHandle) Dblclick(opts goja.Value) error { +func (h *ElementHandle) Dblclick(opts sobek.Value) error { popts := NewElementHandleDblclickOptions(h.defaultTimeout()) if err := popts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing element double click options: %w", err) @@ -799,7 +799,7 @@ func (h *ElementHandle) DispatchEvent(typ string, eventInit any) error { } // Fill types the given value into the element. -func (h *ElementHandle) Fill(value string, opts goja.Value) error { +func (h *ElementHandle) Fill(value string, opts sobek.Value) error { popts := NewElementHandleBaseOptions(h.defaultTimeout()) if err := popts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing element fill options: %w", err) @@ -869,7 +869,7 @@ func (h *ElementHandle) GetAttribute(name string) (string, bool, error) { } // Hover scrolls element into view and hovers over its center point. -func (h *ElementHandle) Hover(opts goja.Value) error { +func (h *ElementHandle) Hover(opts sobek.Value) error { aopts := NewElementHandleHoverOptions(h.defaultTimeout()) if err := aopts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing element hover options: %w", err) @@ -937,7 +937,7 @@ func (h *ElementHandle) InnerText() (string, error) { } // InputValue returns the value of the input element. -func (h *ElementHandle) InputValue(opts goja.Value) (string, error) { +func (h *ElementHandle) InputValue(opts sobek.Value) (string, error) { aopts := NewElementHandleBaseOptions(h.defaultTimeout()) if err := aopts.Parse(h.ctx, opts); err != nil { return "", fmt.Errorf("parsing element input value options: %w", err) @@ -1078,7 +1078,7 @@ func (h *ElementHandle) OwnerFrame() (_ *Frame, rerr error) { } // Press scrolls element into view and presses the given keys. -func (h *ElementHandle) Press(key string, opts goja.Value) error { +func (h *ElementHandle) Press(key string, opts sobek.Value) error { popts := NewElementHandlePressOptions(h.defaultTimeout()) if err := popts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing press %q options: %w", key, err) @@ -1200,7 +1200,7 @@ func (h *ElementHandle) queryAll(selector string, eval evalFunc) (_ []*ElementHa } // SetChecked checks or unchecks an element. -func (h *ElementHandle) SetChecked(checked bool, opts goja.Value) error { +func (h *ElementHandle) SetChecked(checked bool, opts sobek.Value) error { popts := NewElementHandleSetCheckedOptions(h.defaultTimeout()) if err := popts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing setChecked options: %w", err) @@ -1221,13 +1221,13 @@ func (h *ElementHandle) SetChecked(checked bool, opts goja.Value) error { // Uncheck scrolls element into view, and if it's an input element of type // checkbox that is already checked, clicks on it to mark it as unchecked. -func (h *ElementHandle) Uncheck(opts goja.Value) error { +func (h *ElementHandle) Uncheck(opts sobek.Value) error { return h.SetChecked(false, opts) } // Check scrolls element into view, and if it's an input element of type // checkbox that is unchecked, clicks on it to mark it as checked. -func (h *ElementHandle) Check(opts goja.Value) error { +func (h *ElementHandle) Check(opts sobek.Value) error { return h.SetChecked(true, opts) } @@ -1282,7 +1282,7 @@ func (h *ElementHandle) Screenshot( } // ScrollIntoViewIfNeeded scrolls element into view if needed. -func (h *ElementHandle) ScrollIntoViewIfNeeded(opts goja.Value) error { +func (h *ElementHandle) ScrollIntoViewIfNeeded(opts sobek.Value) error { aopts := NewElementHandleBaseOptions(h.defaultTimeout()) if err := aopts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing scrollIntoViewIfNeeded options: %w", err) @@ -1299,7 +1299,7 @@ func (h *ElementHandle) ScrollIntoViewIfNeeded(opts goja.Value) error { } // SelectOption selects the options matching the given values. -func (h *ElementHandle) SelectOption(values goja.Value, opts goja.Value) ([]string, error) { +func (h *ElementHandle) SelectOption(values sobek.Value, opts sobek.Value) ([]string, error) { aopts := NewElementHandleBaseOptions(h.defaultTimeout()) if err := aopts.Parse(h.ctx, opts); err != nil { return nil, fmt.Errorf("parsing selectOption options: %w", err) @@ -1326,7 +1326,7 @@ func (h *ElementHandle) SelectOption(values goja.Value, opts goja.Value) ([]stri } // SelectText selects the text of the element. -func (h *ElementHandle) SelectText(opts goja.Value) error { +func (h *ElementHandle) SelectText(opts sobek.Value) error { aopts := NewElementHandleBaseOptions(h.defaultTimeout()) if err := aopts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing selectText options: %w", err) @@ -1347,7 +1347,7 @@ func (h *ElementHandle) SelectText(opts goja.Value) error { } // SetInputFiles sets the given files into the input file element. -func (h *ElementHandle) SetInputFiles(files goja.Value, opts goja.Value) error { +func (h *ElementHandle) SetInputFiles(files sobek.Value, opts sobek.Value) error { aopts := NewElementHandleSetInputFilesOptions(h.defaultTimeout()) if err := aopts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing setInputFiles options: %w", err) @@ -1450,7 +1450,7 @@ func (h *ElementHandle) Timeout() time.Duration { } // Type scrolls element into view, focuses element and types text. -func (h *ElementHandle) Type(text string, opts goja.Value) error { +func (h *ElementHandle) Type(text string, opts sobek.Value) error { popts := NewElementHandleTypeOptions(h.defaultTimeout()) if err := popts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing type options: %w", err) @@ -1472,7 +1472,7 @@ func (h *ElementHandle) Type(text string, opts goja.Value) error { } // WaitForElementState waits for the element to reach the given state. -func (h *ElementHandle) WaitForElementState(state string, opts goja.Value) error { +func (h *ElementHandle) WaitForElementState(state string, opts sobek.Value) error { popts := NewElementHandleWaitForElementStateOptions(h.defaultTimeout()) if err := popts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing waitForElementState options: %w", err) @@ -1486,7 +1486,7 @@ func (h *ElementHandle) WaitForElementState(state string, opts goja.Value) error } // WaitForSelector waits for the selector to appear in the DOM. -func (h *ElementHandle) WaitForSelector(selector string, opts goja.Value) (*ElementHandle, error) { +func (h *ElementHandle) WaitForSelector(selector string, opts sobek.Value) (*ElementHandle, error) { parsedOpts := NewFrameWaitForSelectorOptions(h.defaultTimeout()) if err := parsedOpts.Parse(h.ctx, opts); err != nil { return nil, fmt.Errorf("parsing waitForSelector %q options: %w", selector, err) diff --git a/common/element_handle_options.go b/common/element_handle_options.go index 7ab0be919..4f3a5394c 100644 --- a/common/element_handle_options.go +++ b/common/element_handle_options.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/k6ext" ) @@ -135,8 +135,8 @@ func NewElementHandleBaseOptions(defaultTimeout time.Duration) *ElementHandleBas } } -func (o *ElementHandleBaseOptions) Parse(ctx context.Context, opts goja.Value) error { - if !gojaValueExists(opts) { +func (o *ElementHandleBaseOptions) Parse(ctx context.Context, opts sobek.Value) error { + if !sobekValueExists(opts) { return nil } gopts := opts.ToObject(k6ext.Runtime(ctx)) @@ -162,12 +162,12 @@ func NewElementHandleBasePointerOptions(defaultTimeout time.Duration) *ElementHa } } -func (o *ElementHandleBasePointerOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleBasePointerOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) if err := o.ElementHandleBaseOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -192,7 +192,7 @@ func NewElementHandleCheckOptions(defaultTimeout time.Duration) *ElementHandleCh } } -func (o *ElementHandleCheckOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleCheckOptions) Parse(ctx context.Context, opts sobek.Value) error { return o.ElementHandleBasePointerOptions.Parse(ctx, opts) } @@ -204,8 +204,8 @@ func NewElementHandleSetInputFilesOptions(defaultTimeout time.Duration) *Element } // addFile to the struct. Input value can only be a file descriptor object. -func (f *Files) addFile(ctx context.Context, file goja.Value) error { - if !gojaValueExists(file) { +func (f *Files) addFile(ctx context.Context, file sobek.Value) error { + if !sobekValueExists(file) { return nil } rt := k6ext.Runtime(ctx) @@ -224,10 +224,10 @@ func (f *Files) addFile(ctx context.Context, file goja.Value) error { return nil } -// Parse parses the Files struct from the given goja.Value. -func (f *Files) Parse(ctx context.Context, files goja.Value) error { +// Parse parses the Files struct from the given sobek.Value. +func (f *Files) Parse(ctx context.Context, files sobek.Value) error { rt := k6ext.Runtime(ctx) - if !gojaValueExists(files) { + if !sobekValueExists(files) { return nil } @@ -249,7 +249,7 @@ func (f *Files) Parse(ctx context.Context, files goja.Value) error { } // Parse parses the ElementHandleSetInputFilesOption from the given opts. -func (o *ElementHandleSetInputFilesOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleSetInputFilesOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.ElementHandleBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -267,12 +267,12 @@ func NewElementHandleClickOptions(defaultTimeout time.Duration) *ElementHandleCl } } -func (o *ElementHandleClickOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleClickOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) if err := o.ElementHandleBasePointerOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -311,12 +311,12 @@ func NewElementHandleDblclickOptions(defaultTimeout time.Duration) *ElementHandl } } -func (o *ElementHandleDblclickOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleDblclickOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) if err := o.ElementHandleBasePointerOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -351,12 +351,12 @@ func NewElementHandleHoverOptions(defaultTimeout time.Duration) *ElementHandleHo } } -func (o *ElementHandleHoverOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleHoverOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) if err := o.ElementHandleBasePointerOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -380,9 +380,9 @@ func NewElementHandlePressOptions(defaultTimeout time.Duration) *ElementHandlePr } } -func (o *ElementHandlePressOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandlePressOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -416,9 +416,9 @@ func NewElementHandleScreenshotOptions(defaultTimeout time.Duration) *ElementHan } } -func (o *ElementHandleScreenshotOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleScreenshotOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { formatSpecified := false opts := opts.ToObject(rt) for _, k := range opts.Keys() { @@ -456,14 +456,14 @@ func NewElementHandleSetCheckedOptions(defaultTimeout time.Duration) *ElementHan } } -func (o *ElementHandleSetCheckedOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleSetCheckedOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) if err := o.ElementHandleBasePointerOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -482,12 +482,12 @@ func NewElementHandleTapOptions(defaultTimeout time.Duration) *ElementHandleTapO } } -func (o *ElementHandleTapOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleTapOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) if err := o.ElementHandleBasePointerOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -511,9 +511,9 @@ func NewElementHandleTypeOptions(defaultTimeout time.Duration) *ElementHandleTyp } } -func (o *ElementHandleTypeOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleTypeOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -543,9 +543,9 @@ func NewElementHandleWaitForElementStateOptions(defaultTimeout time.Duration) *E } } -func (o *ElementHandleWaitForElementStateOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleWaitForElementStateOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { diff --git a/common/execution_context.go b/common/execution_context.go index 48106a1c2..749897e8b 100644 --- a/common/execution_context.go +++ b/common/execution_context.go @@ -157,8 +157,8 @@ func (e *ExecutionContext) adoptElementHandle(eh *ElementHandle) (*ElementHandle func (e *ExecutionContext) eval( apiCtx context.Context, opts evalOptions, js string, args ...any, ) (any, error) { - if escapesGojaValues(args...) { - return nil, errors.New("goja.Value escaped") + if escapesSobekValues(args...) { + return nil, errors.New("sobek.Value escaped") } e.logger.Debugf( "ExecutionContext:eval", @@ -299,8 +299,8 @@ func (e *ExecutionContext) getInjectedScript(apiCtx context.Context) (JSHandleAP // Eval evaluates the provided JavaScript within this execution context and // returns a value or handle. func (e *ExecutionContext) Eval(apiCtx context.Context, js string, args ...any) (any, error) { - if escapesGojaValues(args...) { - return nil, errors.New("goja.Value escaped") + if escapesSobekValues(args...) { + return nil, errors.New("sobek.Value escaped") } opts := evalOptions{ forceCallable: true, @@ -317,8 +317,8 @@ func (e *ExecutionContext) Eval(apiCtx context.Context, js string, args ...any) // EvalHandle evaluates the provided JavaScript within this execution context // and returns a JSHandle. func (e *ExecutionContext) EvalHandle(apiCtx context.Context, js string, args ...any) (JSHandleAPI, error) { - if escapesGojaValues(args...) { - return nil, errors.New("goja.Value escaped") + if escapesSobekValues(args...) { + return nil, errors.New("sobek.Value escaped") } opts := evalOptions{ forceCallable: true, diff --git a/common/frame.go b/common/frame.go index 80c9d313c..6e2aa2365 100644 --- a/common/frame.go +++ b/common/frame.go @@ -9,15 +9,15 @@ import ( "sync" "time" + "github.com/chromedp/cdproto/cdp" + "github.com/chromedp/cdproto/network" + "github.com/chromedp/cdproto/runtime" + "github.com/grafana/sobek" + "github.com/grafana/xk6-browser/k6ext" "github.com/grafana/xk6-browser/log" k6modules "go.k6.io/k6/js/modules" - - "github.com/chromedp/cdproto/cdp" - "github.com/chromedp/cdproto/network" - "github.com/chromedp/cdproto/runtime" - "github.com/dop251/goja" ) // maxRetry controls how many times to retry if an action fails. @@ -615,7 +615,7 @@ func (f *Frame) click(selector string, opts *FrameClickOptions) error { } // Check clicks the first element found that matches selector. -func (f *Frame) Check(selector string, opts goja.Value) error { +func (f *Frame) Check(selector string, opts sobek.Value) error { f.log.Debugf("Frame:Check", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameCheckOptions(f.defaultTimeout()) @@ -646,7 +646,7 @@ func (f *Frame) check(selector string, opts *FrameCheckOptions) error { } // Uncheck the first found element that matches the selector. -func (f *Frame) Uncheck(selector string, opts goja.Value) error { +func (f *Frame) Uncheck(selector string, opts sobek.Value) error { f.log.Debugf("Frame:Uncheck", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameUncheckOptions(f.defaultTimeout()) @@ -678,7 +678,7 @@ func (f *Frame) uncheck(selector string, opts *FrameUncheckOptions) error { // IsChecked returns true if the first element that matches the selector // is checked. Otherwise, returns false. -func (f *Frame) IsChecked(selector string, opts goja.Value) (bool, error) { +func (f *Frame) IsChecked(selector string, opts sobek.Value) (bool, error) { f.log.Debugf("Frame:IsChecked", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsCheckedOptions(f.defaultTimeout()) @@ -745,7 +745,7 @@ func (f *Frame) Content() (string, error) { } // Dblclick double clicks an element matching provided selector. -func (f *Frame) Dblclick(selector string, opts goja.Value) error { +func (f *Frame) Dblclick(selector string, opts sobek.Value) error { f.log.Debugf("Frame:DblClick", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameDblClickOptions(f.defaultTimeout()) @@ -812,7 +812,7 @@ func (f *Frame) dispatchEvent(selector, typ string, eventInit any, opts *FrameDi // EvaluateWithContext will evaluate provided page function within an execution context. // The passed in context will be used instead of the frame's context. The context must -// be a derivative of one that contains the goja runtime. +// be a derivative of one that contains the sobek runtime. func (f *Frame) EvaluateWithContext(ctx context.Context, pageFunc string, args ...any) (any, error) { f.log.Debugf("Frame:EvaluateWithContext", "fid:%s furl:%q", f.ID(), f.URL()) @@ -884,7 +884,7 @@ func (f *Frame) EvaluateHandle(pageFunc string, args ...any) (handle JSHandleAPI } // Fill fills out the first element found that matches the selector. -func (f *Frame) Fill(selector, value string, opts goja.Value) error { +func (f *Frame) Fill(selector, value string, opts sobek.Value) error { f.log.Debugf("Frame:Fill", "fid:%s furl:%q sel:%q val:%q", f.ID(), f.URL(), selector, value) popts := NewFrameFillOptions(f.defaultTimeout()) @@ -917,7 +917,7 @@ func (f *Frame) fill(selector, value string, opts *FrameFillOptions) error { } // Focus focuses on the first element that matches the selector. -func (f *Frame) Focus(selector string, opts goja.Value) error { +func (f *Frame) Focus(selector string, opts sobek.Value) error { f.log.Debugf("Frame:Focus", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameBaseOptions(f.defaultTimeout()) @@ -961,7 +961,7 @@ func (f *Frame) FrameElement() (*ElementHandle, error) { // GetAttribute of the first element found that matches the selector. // The second return value is true if the attribute exists, and false otherwise. -func (f *Frame) GetAttribute(selector, name string, opts goja.Value) (string, bool, error) { +func (f *Frame) GetAttribute(selector, name string, opts sobek.Value) (string, bool, error) { f.log.Debugf("Frame:GetAttribute", "fid:%s furl:%q sel:%q name:%s", f.ID(), f.URL(), selector, name) popts := NewFrameBaseOptions(f.defaultTimeout()) @@ -1031,7 +1031,7 @@ func (f *Frame) Goto(url string, opts *FrameGotoOptions) (*Response, error) { } // Hover moves the pointer over the first element that matches the selector. -func (f *Frame) Hover(selector string, opts goja.Value) error { +func (f *Frame) Hover(selector string, opts sobek.Value) error { f.log.Debugf("Frame:Hover", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameHoverOptions(f.defaultTimeout()) @@ -1063,7 +1063,7 @@ func (f *Frame) hover(selector string, opts *FrameHoverOptions) error { // InnerHTML returns the innerHTML attribute of the first element found // that matches the selector. -func (f *Frame) InnerHTML(selector string, opts goja.Value) (string, error) { +func (f *Frame) InnerHTML(selector string, opts sobek.Value) (string, error) { f.log.Debugf("Frame:InnerHTML", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameInnerHTMLOptions(f.defaultTimeout()) @@ -1103,7 +1103,7 @@ func (f *Frame) innerHTML(selector string, opts *FrameInnerHTMLOptions) (string, // InnerText returns the inner text of the first element found // that matches the selector. -func (f *Frame) InnerText(selector string, opts goja.Value) (string, error) { +func (f *Frame) InnerText(selector string, opts sobek.Value) (string, error) { f.log.Debugf("Frame:InnerText", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameInnerTextOptions(f.defaultTimeout()) @@ -1142,7 +1142,7 @@ func (f *Frame) innerText(selector string, opts *FrameInnerTextOptions) (string, } // InputValue returns the input value of the first element found that matches the selector. -func (f *Frame) InputValue(selector string, opts goja.Value) (string, error) { +func (f *Frame) InputValue(selector string, opts sobek.Value) (string, error) { f.log.Debugf("Frame:InputValue", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameInputValueOptions(f.defaultTimeout()) @@ -1195,7 +1195,7 @@ func (f *Frame) setDetached(detached bool) { // IsEditable returns true if the first element that matches the selector // is editable. Otherwise, returns false. -func (f *Frame) IsEditable(selector string, opts goja.Value) (bool, error) { +func (f *Frame) IsEditable(selector string, opts sobek.Value) (bool, error) { f.log.Debugf("Frame:IsEditable", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsEditableOptions(f.defaultTimeout()) @@ -1236,7 +1236,7 @@ func (f *Frame) isEditable(selector string, opts *FrameIsEditableOptions) (bool, // IsEnabled returns true if the first element that matches the selector // is enabled. Otherwise, returns false. -func (f *Frame) IsEnabled(selector string, opts goja.Value) (bool, error) { +func (f *Frame) IsEnabled(selector string, opts sobek.Value) (bool, error) { f.log.Debugf("Frame:IsEnabled", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsEnabledOptions(f.defaultTimeout()) @@ -1277,7 +1277,7 @@ func (f *Frame) isEnabled(selector string, opts *FrameIsEnabledOptions) (bool, e // IsDisabled returns true if the first element that matches the selector // is disabled. Otherwise, returns false. -func (f *Frame) IsDisabled(selector string, opts goja.Value) (bool, error) { +func (f *Frame) IsDisabled(selector string, opts sobek.Value) (bool, error) { f.log.Debugf("Frame:IsDisabled", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsDisabledOptions(f.defaultTimeout()) @@ -1318,7 +1318,7 @@ func (f *Frame) isDisabled(selector string, opts *FrameIsDisabledOptions) (bool, // IsHidden returns true if the first element that matches the selector // is hidden. Otherwise, returns false. -func (f *Frame) IsHidden(selector string, opts goja.Value) (bool, error) { +func (f *Frame) IsHidden(selector string, opts sobek.Value) (bool, error) { f.log.Debugf("Frame:IsHidden", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsHiddenOptions() @@ -1351,7 +1351,7 @@ func (f *Frame) isHidden(selector string, opts *FrameIsHiddenOptions) (bool, err // IsVisible returns true if the first element that matches the selector // is visible. Otherwise, returns false. -func (f *Frame) IsVisible(selector string, opts goja.Value) (bool, error) { +func (f *Frame) IsVisible(selector string, opts sobek.Value) (bool, error) { f.log.Debugf("Frame:IsVisible", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsVisibleOptions() @@ -1391,7 +1391,7 @@ func (f *Frame) ID() string { } // Locator creates and returns a new locator for this frame. -func (f *Frame) Locator(selector string, opts goja.Value) *Locator { +func (f *Frame) Locator(selector string, opts sobek.Value) *Locator { f.log.Debugf("Frame:Locator", "fid:%s furl:%q selector:%q opts:%+v", f.ID(), f.URL(), selector, opts) return NewLocator(f.ctx, selector, f, f.log) @@ -1447,7 +1447,7 @@ func (f *Frame) ParentFrame() *Frame { } // Press presses the given key for the first element found that matches the selector. -func (f *Frame) Press(selector, key string, opts goja.Value) error { +func (f *Frame) Press(selector, key string, opts sobek.Value) error { f.log.Debugf("Frame:Press", "fid:%s furl:%q sel:%q key:%q", f.ID(), f.URL(), selector, key) popts := NewFramePressOptions(f.defaultTimeout()) @@ -1480,7 +1480,7 @@ func (f *Frame) press(selector, key string, opts *FramePressOptions) error { // SelectOption selects the given options and returns the array of // option values of the first element found that matches the selector. -func (f *Frame) SelectOption(selector string, values goja.Value, opts goja.Value) ([]string, error) { +func (f *Frame) SelectOption(selector string, values sobek.Value, opts sobek.Value) ([]string, error) { f.log.Debugf("Frame:SelectOption", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameSelectOptionOptions(f.defaultTimeout()) @@ -1497,7 +1497,7 @@ func (f *Frame) SelectOption(selector string, values goja.Value, opts goja.Value return v, nil } -func (f *Frame) selectOption(selector string, values goja.Value, opts *FrameSelectOptionOptions) ([]string, error) { +func (f *Frame) selectOption(selector string, values sobek.Value, opts *FrameSelectOptionOptions) ([]string, error) { selectOption := func(apiCtx context.Context, handle *ElementHandle) (any, error) { return handle.selectOption(apiCtx, values) } @@ -1538,7 +1538,7 @@ func (f *Frame) selectOption(selector string, values goja.Value, opts *FrameSele } // SetContent replaces the entire HTML document content. -func (f *Frame) SetContent(html string, opts goja.Value) error { +func (f *Frame) SetContent(html string, opts sobek.Value) error { f.log.Debugf("Frame:SetContent", "fid:%s furl:%q", f.ID(), f.URL()) parsedOpts := NewFrameSetContentOptions( @@ -1571,7 +1571,7 @@ func (f *Frame) SetContent(html string, opts goja.Value) error { } // SetInputFiles sets input files for the selected element. -func (f *Frame) SetInputFiles(selector string, files goja.Value, opts goja.Value) error { +func (f *Frame) SetInputFiles(selector string, files sobek.Value, opts sobek.Value) error { f.log.Debugf("Frame:SetInputFiles", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameSetInputFilesOptions(f.defaultTimeout()) @@ -1640,7 +1640,7 @@ func (f *Frame) setInputFiles(selector string, files *Files, opts *FrameSetInput // TextContent returns the textContent attribute of the first element found // that matches the selector. The second return value is true if the returned // text content is not null or empty, and false otherwise. -func (f *Frame) TextContent(selector string, opts goja.Value) (string, bool, error) { +func (f *Frame) TextContent(selector string, opts sobek.Value) (string, bool, error) { f.log.Debugf("Frame:TextContent", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameTextContentOptions(f.defaultTimeout()) @@ -1697,7 +1697,7 @@ func (f *Frame) Title() string { } // Type text on the first element found matches the selector. -func (f *Frame) Type(selector, text string, opts goja.Value) error { +func (f *Frame) Type(selector, text string, opts sobek.Value) error { f.log.Debugf("Frame:Type", "fid:%s furl:%q sel:%q text:%q", f.ID(), f.URL(), selector, text) popts := NewFrameTypeOptions(f.defaultTimeout()) @@ -1830,7 +1830,7 @@ func (f *Frame) waitForFunction( // WaitForLoadState waits for the given load state to be reached. // This will unblock if that lifecycle event has already been received. -func (f *Frame) WaitForLoadState(state string, opts goja.Value) error { +func (f *Frame) WaitForLoadState(state string, opts sobek.Value) error { f.log.Debugf("Frame:WaitForLoadState", "fid:%s furl:%q state:%s", f.ID(), f.URL(), state) defer f.log.Debugf("Frame:WaitForLoadState:return", "fid:%s furl:%q state:%s", f.ID(), f.URL(), state) @@ -1963,7 +1963,7 @@ func (f *Frame) WaitForNavigation(opts *FrameWaitForNavigationOptions) (*Respons } // WaitForSelector waits for the given selector to match the waiting criteria. -func (f *Frame) WaitForSelector(selector string, opts goja.Value) (*ElementHandle, error) { +func (f *Frame) WaitForSelector(selector string, opts sobek.Value) (*ElementHandle, error) { parsedOpts := NewFrameWaitForSelectorOptions(f.defaultTimeout()) if err := parsedOpts.Parse(f.ctx, opts); err != nil { return nil, fmt.Errorf("parsing wait for selector %q options: %w", selector, err) diff --git a/common/frame_options.go b/common/frame_options.go index b8dba383c..a6189796f 100644 --- a/common/frame_options.go +++ b/common/frame_options.go @@ -8,7 +8,7 @@ import ( "reflect" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/k6ext" ) @@ -205,9 +205,9 @@ func NewFrameBaseOptions(defaultTimeout time.Duration) *FrameBaseOptions { } } -func (o *FrameBaseOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameBaseOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -228,7 +228,7 @@ func NewFrameCheckOptions(defaultTimeout time.Duration) *FrameCheckOptions { } } -func (o *FrameCheckOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameCheckOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.ElementHandleBasePointerOptions.Parse(ctx, opts); err != nil { return err } @@ -243,7 +243,7 @@ func NewFrameClickOptions(defaultTimeout time.Duration) *FrameClickOptions { } } -func (o *FrameClickOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameClickOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.ElementHandleClickOptions.Parse(ctx, opts); err != nil { return err } @@ -258,7 +258,7 @@ func NewFrameDblClickOptions(defaultTimeout time.Duration) *FrameDblclickOptions } } -func (o *FrameDblclickOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameDblclickOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.ElementHandleDblclickOptions.Parse(ctx, opts); err != nil { return err } @@ -273,7 +273,7 @@ func NewFrameFillOptions(defaultTimeout time.Duration) *FrameFillOptions { } } -func (o *FrameFillOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameFillOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.ElementHandleBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -289,9 +289,9 @@ func NewFrameGotoOptions(defaultReferer string, defaultTimeout time.Duration) *F } } -func (o *FrameGotoOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameGotoOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -317,7 +317,7 @@ func NewFrameHoverOptions(defaultTimeout time.Duration) *FrameHoverOptions { } } -func (o *FrameHoverOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameHoverOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.ElementHandleHoverOptions.Parse(ctx, opts); err != nil { return err } @@ -331,7 +331,7 @@ func NewFrameInnerHTMLOptions(defaultTimeout time.Duration) *FrameInnerHTMLOptio } } -func (o *FrameInnerHTMLOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameInnerHTMLOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.FrameBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -344,7 +344,7 @@ func NewFrameInnerTextOptions(defaultTimeout time.Duration) *FrameInnerTextOptio } } -func (o *FrameInnerTextOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameInnerTextOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.FrameBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -357,7 +357,7 @@ func NewFrameInputValueOptions(defaultTimeout time.Duration) *FrameInputValueOpt } } -func (o *FrameInputValueOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameInputValueOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.FrameBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -370,7 +370,7 @@ func NewFrameIsCheckedOptions(defaultTimeout time.Duration) *FrameIsCheckedOptio } } -func (o *FrameIsCheckedOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameIsCheckedOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.FrameBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -383,7 +383,7 @@ func NewFrameIsDisabledOptions(defaultTimeout time.Duration) *FrameIsDisabledOpt } } -func (o *FrameIsDisabledOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameIsDisabledOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.FrameBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -396,7 +396,7 @@ func NewFrameIsEditableOptions(defaultTimeout time.Duration) *FrameIsEditableOpt } } -func (o *FrameIsEditableOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameIsEditableOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.FrameBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -409,7 +409,7 @@ func NewFrameIsEnabledOptions(defaultTimeout time.Duration) *FrameIsEnabledOptio } } -func (o *FrameIsEnabledOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameIsEnabledOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.FrameBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -421,7 +421,7 @@ func NewFrameIsHiddenOptions() *FrameIsHiddenOptions { return &FrameIsHiddenOptions{} } -func (o *FrameIsHiddenOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameIsHiddenOptions) Parse(ctx context.Context, opts sobek.Value) error { o.Strict = parseStrict(ctx, opts) return nil } @@ -431,7 +431,7 @@ func NewFrameIsVisibleOptions() *FrameIsVisibleOptions { return &FrameIsVisibleOptions{} } -func (o *FrameIsVisibleOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameIsVisibleOptions) Parse(ctx context.Context, opts sobek.Value) error { o.Strict = parseStrict(ctx, opts) return nil } @@ -456,7 +456,7 @@ func NewFrameSelectOptionOptions(defaultTimeout time.Duration) *FrameSelectOptio } } -func (o *FrameSelectOptionOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameSelectOptionOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.ElementHandleBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -471,10 +471,10 @@ func NewFrameSetContentOptions(defaultTimeout time.Duration) *FrameSetContentOpt } } -func (o *FrameSetContentOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameSetContentOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -500,8 +500,8 @@ func NewFrameSetInputFilesOptions(defaultTimeout time.Duration) *FrameSetInputFi } } -// Parse parses FrameSetInputFilesOptions from goja.Value. -func (o *FrameSetInputFilesOptions) Parse(ctx context.Context, opts goja.Value) error { +// Parse parses FrameSetInputFilesOptions from sobek.Value. +func (o *FrameSetInputFilesOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.ElementHandleSetInputFilesOptions.Parse(ctx, opts); err != nil { return err } @@ -516,12 +516,12 @@ func NewFrameTapOptions(defaultTimeout time.Duration) *FrameTapOptions { } } -func (o *FrameTapOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameTapOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) if err := o.ElementHandleBasePointerOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -545,7 +545,7 @@ func NewFrameTextContentOptions(defaultTimeout time.Duration) *FrameTextContentO } } -func (o *FrameTextContentOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameTextContentOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.FrameBaseOptions.Parse(ctx, opts); err != nil { return err } @@ -572,7 +572,7 @@ func NewFrameUncheckOptions(defaultTimeout time.Duration) *FrameUncheckOptions { } } -func (o *FrameUncheckOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameUncheckOptions) Parse(ctx context.Context, opts sobek.Value) error { if err := o.ElementHandleBasePointerOptions.Parse(ctx, opts); err != nil { return err } @@ -589,10 +589,10 @@ func NewFrameWaitForFunctionOptions(defaultTimeout time.Duration) *FrameWaitForF } // Parse JavaScript waitForFunction options. -func (o *FrameWaitForFunctionOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameWaitForFunctionOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { v := opts.Get(k) @@ -627,9 +627,9 @@ func NewFrameWaitForLoadStateOptions(defaultTimeout time.Duration) *FrameWaitFor } } -func (o *FrameWaitForLoadStateOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameWaitForLoadStateOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -649,9 +649,9 @@ func NewFrameWaitForNavigationOptions(defaultTimeout time.Duration) *FrameWaitFo } } -func (o *FrameWaitForNavigationOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameWaitForNavigationOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -678,10 +678,10 @@ func NewFrameWaitForSelectorOptions(defaultTimeout time.Duration) *FrameWaitForS } } -func (o *FrameWaitForSelectorOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *FrameWaitForSelectorOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -715,11 +715,11 @@ func NewFrameDispatchEventOptions(defaultTimeout time.Duration) *FrameDispatchEv } } -func parseStrict(ctx context.Context, opts goja.Value) bool { +func parseStrict(ctx context.Context, opts sobek.Value) bool { var strict bool rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { if k == "strict" { diff --git a/common/frame_options_test.go b/common/frame_options_test.go index b10cb03ea..ac6d4e579 100644 --- a/common/frame_options_test.go +++ b/common/frame_options_test.go @@ -17,7 +17,7 @@ func TestFrameGotoOptionsParse(t *testing.T) { t.Parallel() vu := k6test.NewVU(t) - opts := vu.ToGojaValue(map[string]any{ + opts := vu.ToSobekValue(map[string]any{ "timeout": "1000", "waitUntil": "networkidle", }) @@ -34,7 +34,7 @@ func TestFrameGotoOptionsParse(t *testing.T) { t.Parallel() vu := k6test.NewVU(t) - opts := vu.ToGojaValue(map[string]any{ + opts := vu.ToSobekValue(map[string]any{ "waitUntil": "none", }) navOpts := NewFrameGotoOptions("", 0) @@ -54,7 +54,7 @@ func TestFrameSetContentOptionsParse(t *testing.T) { t.Parallel() vu := k6test.NewVU(t) - opts := vu.ToGojaValue(map[string]any{ + opts := vu.ToSobekValue(map[string]any{ "waitUntil": "networkidle", }) scOpts := NewFrameSetContentOptions(30 * time.Second) @@ -69,7 +69,7 @@ func TestFrameSetContentOptionsParse(t *testing.T) { t.Parallel() vu := k6test.NewVU(t) - opts := vu.ToGojaValue(map[string]any{ + opts := vu.ToSobekValue(map[string]any{ "waitUntil": "none", }) navOpts := NewFrameSetContentOptions(0) @@ -89,7 +89,7 @@ func TestFrameWaitForNavigationOptionsParse(t *testing.T) { t.Parallel() vu := k6test.NewVU(t) - opts := vu.ToGojaValue(map[string]any{ + opts := vu.ToSobekValue(map[string]any{ "url": "https://example.com/", "timeout": "1000", "waitUntil": "networkidle", @@ -107,7 +107,7 @@ func TestFrameWaitForNavigationOptionsParse(t *testing.T) { t.Parallel() vu := k6test.NewVU(t) - opts := vu.ToGojaValue(map[string]any{ + opts := vu.ToSobekValue(map[string]any{ "waitUntil": "none", }) navOpts := NewFrameWaitForNavigationOptions(0) diff --git a/common/helpers.go b/common/helpers.go index 4bf49a442..9e3dd8161 100644 --- a/common/helpers.go +++ b/common/helpers.go @@ -9,7 +9,7 @@ import ( "time" cdpruntime "github.com/chromedp/cdproto/runtime" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/k6ext" ) @@ -36,8 +36,8 @@ func convertBaseJSHandleTypes(ctx context.Context, execCtx *ExecutionContext, ob func convertArgument( ctx context.Context, execCtx *ExecutionContext, arg any, ) (*cdpruntime.CallArgument, error) { - if escapesGojaValues(arg) { - return nil, errors.New("goja.Value escaped") + if escapesSobekValues(arg) { + return nil, errors.New("sobek.Value escaped") } switch a := arg.(type) { case int64: @@ -220,26 +220,26 @@ func TrimQuotes(s string) string { return s } -// gojaValueExists returns true if a given value is not nil and exists -// (defined and not null) in the goja runtime. -func gojaValueExists(v goja.Value) bool { - return v != nil && !goja.IsUndefined(v) && !goja.IsNull(v) +// sobekValueExists returns true if a given value is not nil and exists +// (defined and not null) in the sobek runtime. +func sobekValueExists(v sobek.Value) bool { + return v != nil && !sobek.IsUndefined(v) && !sobek.IsNull(v) } -// asGojaValue return v as a goja value. -// panics if v is not a goja value. -func asGojaValue(ctx context.Context, v any) goja.Value { - gv, ok := v.(goja.Value) +// asSobekValue return v as a sobek value. +// panics if v is not a sobek value. +func asSobekValue(ctx context.Context, v any) sobek.Value { + gv, ok := v.(sobek.Value) if !ok { k6ext.Panic(ctx, "unexpected type %T", v) } return gv } -// gojaValueToString returns v as string. -// panics if v is not a goja value. -func gojaValueToString(ctx context.Context, v any) string { - return asGojaValue(ctx, v).String() +// sobekValueToString returns v as string. +// panics if v is not a sobek value. +func sobekValueToString(ctx context.Context, v any) string { + return asSobekValue(ctx, v).String() } // convert is a helper function to convert any value to a given type. @@ -253,11 +253,11 @@ func convert[T any](from any, to *T) error { } // TODO: -// remove this temporary helper after ensuring the goja-free +// remove this temporary helper after ensuring the sobek-free // business logic works. -func escapesGojaValues(args ...any) bool { +func escapesSobekValues(args ...any) bool { for _, arg := range args { - if _, ok := arg.(goja.Value); ok { + if _, ok := arg.(sobek.Value); ok { return true } } diff --git a/common/http.go b/common/http.go index 2d3afb1e1..7518df6f5 100644 --- a/common/http.go +++ b/common/http.go @@ -12,7 +12,7 @@ import ( "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/network" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/k6ext" "github.com/grafana/xk6-browser/log" @@ -179,12 +179,12 @@ func (r *Request) Frame() *Frame { } // HeaderValue returns the value of the given header. -func (r *Request) HeaderValue(name string) goja.Value { +func (r *Request) HeaderValue(name string) sobek.Value { rt := r.vu.Runtime() headers := r.AllHeaders() val, ok := headers[name] if !ok { - return goja.Null() + return sobek.Null() } return rt.ToValue(val) } @@ -248,7 +248,7 @@ func (r *Request) Size() HTTPMessageSize { } // Timing returns the request timing information. -func (r *Request) Timing() goja.Value { +func (r *Request) Timing() sobek.Value { type resourceTiming struct { StartTime float64 `js:"startTime"` DomainLookupStart float64 `js:"domainLookupStart"` diff --git a/common/keyboard.go b/common/keyboard.go index 9bb95d3c8..e8007c0f7 100644 --- a/common/keyboard.go +++ b/common/keyboard.go @@ -6,11 +6,11 @@ import ( "strings" "time" - "github.com/grafana/xk6-browser/keyboardlayout" - "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/input" - "github.com/dop251/goja" + "github.com/grafana/sobek" + + "github.com/grafana/xk6-browser/keyboardlayout" ) const ( @@ -62,7 +62,7 @@ func (k *Keyboard) Up(key string) error { // Press sends a key press message to a session target. // It delays the action if `Delay` option is specified. // A press message consists of successive key down and up messages. -func (k *Keyboard) Press(key string, opts goja.Value) error { +func (k *Keyboard) Press(key string, opts sobek.Value) error { kbdOpts := NewKeyboardOptions() if err := kbdOpts.Parse(k.ctx, opts); err != nil { return fmt.Errorf("parsing keyboard options: %w", err) @@ -88,7 +88,7 @@ func (k *Keyboard) InsertText(text string) error { // // It sends an insertText message if a character is not among // valid characters in the keyboard's layout. -func (k *Keyboard) Type(text string, opts goja.Value) error { +func (k *Keyboard) Type(text string, opts sobek.Value) error { kbdOpts := NewKeyboardOptions() if err := kbdOpts.Parse(k.ctx, opts); err != nil { return fmt.Errorf("parsing keyboard options: %w", err) diff --git a/common/keyboard_options.go b/common/keyboard_options.go index da39f46c8..8549db3ab 100644 --- a/common/keyboard_options.go +++ b/common/keyboard_options.go @@ -3,7 +3,7 @@ package common import ( "context" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/k6ext" ) @@ -18,9 +18,9 @@ func NewKeyboardOptions() *KeyboardOptions { } } -func (o *KeyboardOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *KeyboardOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { diff --git a/common/layout.go b/common/layout.go index ade023d3b..afc8ad964 100644 --- a/common/layout.go +++ b/common/layout.go @@ -5,7 +5,7 @@ import ( "fmt" "math" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/k6ext" ) @@ -52,10 +52,10 @@ func (s Size) enclosingIntSize() *Size { } } -// Parse size details from a given goja viewport value. -func (s *Size) Parse(ctx context.Context, viewport goja.Value) error { +// Parse size details from a given sobek viewport value. +func (s *Size) Parse(ctx context.Context, viewport sobek.Value) error { rt := k6ext.Runtime(ctx) - if viewport != nil && !goja.IsUndefined(viewport) && !goja.IsNull(viewport) { + if viewport != nil && !sobek.IsUndefined(viewport) && !sobek.IsNull(viewport) { viewport := viewport.ToObject(rt) for _, k := range viewport.Keys() { switch k { @@ -80,10 +80,10 @@ type Viewport struct { Height int64 `js:"height"` } -// Parse viewport details from a given goja viewport value. -func (v *Viewport) Parse(ctx context.Context, viewport goja.Value) error { +// Parse viewport details from a given sobek viewport value. +func (v *Viewport) Parse(ctx context.Context, viewport sobek.Value) error { rt := k6ext.Runtime(ctx) - if viewport != nil && !goja.IsUndefined(viewport) && !goja.IsNull(viewport) { + if viewport != nil && !sobek.IsUndefined(viewport) && !sobek.IsNull(viewport) { viewport := viewport.ToObject(rt) for _, k := range viewport.Keys() { switch k { diff --git a/common/locator.go b/common/locator.go index ad4f65989..89158ae62 100644 --- a/common/locator.go +++ b/common/locator.go @@ -5,9 +5,9 @@ import ( "fmt" "time" - "github.com/grafana/xk6-browser/log" + "github.com/grafana/sobek" - "github.com/dop251/goja" + "github.com/grafana/xk6-browser/log" ) // Strict mode: @@ -81,7 +81,7 @@ func (l *Locator) click(opts *FrameClickOptions) error { } // Dblclick double clicks on an element using locator's selector with strict mode on. -func (l *Locator) Dblclick(opts goja.Value) error { +func (l *Locator) Dblclick(opts sobek.Value) error { l.log.Debugf("Locator:Dblclick", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameDblClickOptions(l.frame.defaultTimeout()) @@ -105,7 +105,7 @@ func (l *Locator) dblclick(opts *FrameDblclickOptions) error { } // Check on an element using locator's selector with strict mode on. -func (l *Locator) Check(opts goja.Value) error { +func (l *Locator) Check(opts sobek.Value) error { l.log.Debugf("Locator:Check", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameCheckOptions(l.frame.defaultTimeout()) @@ -129,7 +129,7 @@ func (l *Locator) check(opts *FrameCheckOptions) error { } // Uncheck on an element using locator's selector with strict mode on. -func (l *Locator) Uncheck(opts goja.Value) error { +func (l *Locator) Uncheck(opts sobek.Value) error { l.log.Debugf("Locator:Uncheck", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameUncheckOptions(l.frame.defaultTimeout()) @@ -154,7 +154,7 @@ func (l *Locator) uncheck(opts *FrameUncheckOptions) error { // IsChecked returns true if the element matches the locator's // selector and is checked. Otherwise, returns false. -func (l *Locator) IsChecked(opts goja.Value) (bool, error) { +func (l *Locator) IsChecked(opts sobek.Value) (bool, error) { l.log.Debugf("Locator:IsChecked", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameIsCheckedOptions(l.frame.defaultTimeout()) @@ -178,7 +178,7 @@ func (l *Locator) isChecked(opts *FrameIsCheckedOptions) (bool, error) { // IsEditable returns true if the element matches the locator's // selector and is Editable. Otherwise, returns false. -func (l *Locator) IsEditable(opts goja.Value) (bool, error) { +func (l *Locator) IsEditable(opts sobek.Value) (bool, error) { l.log.Debugf("Locator:IsEditable", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameIsEditableOptions(l.frame.defaultTimeout()) @@ -202,7 +202,7 @@ func (l *Locator) isEditable(opts *FrameIsEditableOptions) (bool, error) { // IsEnabled returns true if the element matches the locator's // selector and is Enabled. Otherwise, returns false. -func (l *Locator) IsEnabled(opts goja.Value) (bool, error) { +func (l *Locator) IsEnabled(opts sobek.Value) (bool, error) { l.log.Debugf("Locator:IsEnabled", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameIsEnabledOptions(l.frame.defaultTimeout()) @@ -226,7 +226,7 @@ func (l *Locator) isEnabled(opts *FrameIsEnabledOptions) (bool, error) { // IsDisabled returns true if the element matches the locator's // selector and is disabled. Otherwise, returns false. -func (l *Locator) IsDisabled(opts goja.Value) (bool, error) { +func (l *Locator) IsDisabled(opts sobek.Value) (bool, error) { l.log.Debugf("Locator:IsDisabled", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameIsDisabledOptions(l.frame.defaultTimeout()) @@ -275,7 +275,7 @@ func (l *Locator) IsHidden() (bool, error) { } // Fill out the element using locator's selector with strict mode on. -func (l *Locator) Fill(value string, opts goja.Value) error { +func (l *Locator) Fill(value string, opts sobek.Value) error { l.log.Debugf( "Locator:Fill", "fid:%s furl:%q sel:%q val:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, value, opts, @@ -300,7 +300,7 @@ func (l *Locator) fill(value string, opts *FrameFillOptions) error { } // Focus on the element using locator's selector with strict mode on. -func (l *Locator) Focus(opts goja.Value) error { +func (l *Locator) Focus(opts sobek.Value) error { l.log.Debugf("Locator:Focus", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameBaseOptions(l.frame.defaultTimeout()) @@ -323,7 +323,7 @@ func (l *Locator) focus(opts *FrameBaseOptions) error { // GetAttribute of the element using locator's selector with strict mode on. // The second return value is true if the attribute exists, and false otherwise. -func (l *Locator) GetAttribute(name string, opts goja.Value) (string, bool, error) { +func (l *Locator) GetAttribute(name string, opts sobek.Value) (string, bool, error) { l.log.Debugf( "Locator:GetAttribute", "fid:%s furl:%q sel:%q name:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, name, opts, @@ -348,7 +348,7 @@ func (l *Locator) getAttribute(name string, opts *FrameBaseOptions) (string, boo // InnerHTML returns the element's inner HTML that matches // the locator's selector with strict mode on. -func (l *Locator) InnerHTML(opts goja.Value) (string, error) { +func (l *Locator) InnerHTML(opts sobek.Value) (string, error) { l.log.Debugf("Locator:InnerHTML", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameInnerHTMLOptions(l.frame.defaultTimeout()) @@ -370,7 +370,7 @@ func (l *Locator) innerHTML(opts *FrameInnerHTMLOptions) (string, error) { // InnerText returns the element's inner text that matches // the locator's selector with strict mode on. -func (l *Locator) InnerText(opts goja.Value) (string, error) { +func (l *Locator) InnerText(opts sobek.Value) (string, error) { l.log.Debugf("Locator:InnerText", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameInnerTextOptions(l.frame.defaultTimeout()) @@ -394,7 +394,7 @@ func (l *Locator) innerText(opts *FrameInnerTextOptions) (string, error) { // the locator's selector with strict mode on. The second return // value is true if the returned text content is not null or empty, // and false otherwise. -func (l *Locator) TextContent(opts goja.Value) (string, bool, error) { +func (l *Locator) TextContent(opts sobek.Value) (string, bool, error) { l.log.Debugf("Locator:TextContent", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameTextContentOptions(l.frame.defaultTimeout()) @@ -416,7 +416,7 @@ func (l *Locator) textContent(opts *FrameTextContentOptions) (string, bool, erro // InputValue returns the element's input value that matches // the locator's selector with strict mode on. -func (l *Locator) InputValue(opts goja.Value) (string, error) { +func (l *Locator) InputValue(opts sobek.Value) (string, error) { l.log.Debugf("Locator:InputValue", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameInputValueOptions(l.frame.defaultTimeout()) @@ -439,7 +439,7 @@ func (l *Locator) inputValue(opts *FrameInputValueOptions) (string, error) { // SelectOption filters option values of the first element that matches // the locator's selector (with strict mode on), selects the options, // and returns the filtered options. -func (l *Locator) SelectOption(values goja.Value, opts goja.Value) ([]string, error) { +func (l *Locator) SelectOption(values sobek.Value, opts sobek.Value) ([]string, error) { l.log.Debugf("Locator:SelectOption", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameSelectOptionOptions(l.frame.defaultTimeout()) @@ -456,14 +456,14 @@ func (l *Locator) SelectOption(values goja.Value, opts goja.Value) ([]string, er return v, nil } -func (l *Locator) selectOption(values goja.Value, opts *FrameSelectOptionOptions) ([]string, error) { +func (l *Locator) selectOption(values sobek.Value, opts *FrameSelectOptionOptions) ([]string, error) { opts.Strict = true return l.frame.selectOption(l.selector, values, opts) } // Press the given key on the element found that matches the locator's // selector with strict mode on. -func (l *Locator) Press(key string, opts goja.Value) error { +func (l *Locator) Press(key string, opts sobek.Value) error { l.log.Debugf( "Locator:Press", "fid:%s furl:%q sel:%q key:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, key, opts, @@ -489,7 +489,7 @@ func (l *Locator) press(key string, opts *FramePressOptions) error { // Type text on the element found that matches the locator's // selector with strict mode on. -func (l *Locator) Type(text string, opts goja.Value) error { +func (l *Locator) Type(text string, opts sobek.Value) error { l.log.Debugf( "Locator:Type", "fid:%s furl:%q sel:%q text:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, text, opts, @@ -521,7 +521,7 @@ func (l *Locator) typ(text string, opts *FrameTypeOptions) error { // Hover moves the pointer over the element that matches the locator's // selector with strict mode on. -func (l *Locator) Hover(opts goja.Value) error { +func (l *Locator) Hover(opts sobek.Value) error { l.log.Debugf("Locator:Hover", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) copts := NewFrameHoverOptions(l.frame.defaultTimeout()) @@ -579,7 +579,7 @@ func (l *Locator) dispatchEvent(typ string, eventInit any, opts *FrameDispatchEv } // WaitFor waits for the element matching the locator's selector with strict mode on. -func (l *Locator) WaitFor(opts goja.Value) error { +func (l *Locator) WaitFor(opts sobek.Value) error { l.log.Debugf("Locator:WaitFor", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) popts := NewFrameWaitForSelectorOptions(l.frame.defaultTimeout()) diff --git a/common/mouse.go b/common/mouse.go index 865b6e6e5..0df78e6f4 100644 --- a/common/mouse.go +++ b/common/mouse.go @@ -7,7 +7,7 @@ import ( "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/input" - "github.com/dop251/goja" + "github.com/grafana/sobek" ) // Mouse represents a mouse input device. @@ -35,7 +35,7 @@ func NewMouse(ctx context.Context, s session, f *Frame, ts *TimeoutSettings, k * } // Click will trigger a series of MouseMove, MouseDown and MouseUp events in the browser. -func (m *Mouse) Click(x float64, y float64, opts goja.Value) error { +func (m *Mouse) Click(x float64, y float64, opts sobek.Value) error { mouseOpts := NewMouseClickOptions() if err := mouseOpts.Parse(m.ctx, opts); err != nil { return fmt.Errorf("parsing mouse click options: %w", err) @@ -72,7 +72,7 @@ func (m *Mouse) click(x float64, y float64, opts *MouseClickOptions) error { } // DblClick will trigger Click twice in quick succession. -func (m *Mouse) DblClick(x float64, y float64, opts goja.Value) error { +func (m *Mouse) DblClick(x float64, y float64, opts sobek.Value) error { mouseOpts := NewMouseDblClickOptions() if err := mouseOpts.Parse(m.ctx, opts); err != nil { return fmt.Errorf("parsing double click options: %w", err) @@ -84,7 +84,7 @@ func (m *Mouse) DblClick(x float64, y float64, opts goja.Value) error { } // Down will trigger a MouseDown event in the browser. -func (m *Mouse) Down(opts goja.Value) error { +func (m *Mouse) Down(opts sobek.Value) error { mouseOpts := NewMouseDownUpOptions() if err := mouseOpts.Parse(m.ctx, opts); err != nil { return fmt.Errorf("parsing mouse down options: %w", err) @@ -108,7 +108,7 @@ func (m *Mouse) down(opts *MouseDownUpOptions) error { } // Up will trigger a MouseUp event in the browser. -func (m *Mouse) Up(opts goja.Value) error { +func (m *Mouse) Up(opts sobek.Value) error { mouseOpts := NewMouseDownUpOptions() if err := mouseOpts.Parse(m.ctx, opts); err != nil { return fmt.Errorf("parsing mouse up options: %w", err) @@ -133,7 +133,7 @@ func (m *Mouse) up(opts *MouseDownUpOptions) error { } // Move will trigger a MouseMoved event in the browser. -func (m *Mouse) Move(x float64, y float64, opts goja.Value) error { +func (m *Mouse) Move(x float64, y float64, opts sobek.Value) error { mouseOpts := NewMouseMoveOptions() if err := mouseOpts.Parse(m.ctx, opts); err != nil { return fmt.Errorf("parsing mouse move options: %w", err) diff --git a/common/mouse_options.go b/common/mouse_options.go index 7109bfbd6..9e7ffcb0a 100644 --- a/common/mouse_options.go +++ b/common/mouse_options.go @@ -3,7 +3,7 @@ package common import ( "context" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/k6ext" ) @@ -36,9 +36,9 @@ func NewMouseClickOptions() *MouseClickOptions { } } -func (o *MouseClickOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *MouseClickOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -68,9 +68,9 @@ func NewMouseDblClickOptions() *MouseDblClickOptions { } } -func (o *MouseDblClickOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *MouseDblClickOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -100,9 +100,9 @@ func NewMouseDownUpOptions() *MouseDownUpOptions { } } -func (o *MouseDownUpOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *MouseDownUpOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -122,9 +122,9 @@ func NewMouseMoveOptions() *MouseMoveOptions { } } -func (o *MouseMoveOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *MouseMoveOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { diff --git a/common/network_manager.go b/common/network_manager.go index bb7529dd3..dd4512676 100644 --- a/common/network_manager.go +++ b/common/network_manager.go @@ -25,7 +25,7 @@ import ( "github.com/chromedp/cdproto/emulation" "github.com/chromedp/cdproto/fetch" "github.com/chromedp/cdproto/network" - "github.com/dop251/goja" + "github.com/grafana/sobek" ) // Credentials holds HTTP authentication credentials. @@ -39,10 +39,10 @@ func NewCredentials() *Credentials { return &Credentials{} } -// Parse credentials details from a given goja credentials value. -func (c *Credentials) Parse(ctx context.Context, credentials goja.Value) error { +// Parse credentials details from a given sobek credentials value. +func (c *Credentials) Parse(ctx context.Context, credentials sobek.Value) error { rt := k6ext.Runtime(ctx) - if credentials != nil && !goja.IsUndefined(credentials) && !goja.IsNull(credentials) { + if credentials != nil && !sobek.IsUndefined(credentials) && !sobek.IsNull(credentials) { credentials := credentials.ToObject(rt) for _, k := range credentials.Keys() { switch k { @@ -718,7 +718,7 @@ func (m *NetworkManager) Authenticate(credentials *Credentials) error { } // ExtraHTTPHeaders returns the currently set extra HTTP request headers. -func (m *NetworkManager) ExtraHTTPHeaders() goja.Value { +func (m *NetworkManager) ExtraHTTPHeaders() sobek.Value { rt := m.vu.Runtime() return rt.ToValue(m.extraHTTPHeaders) } diff --git a/common/page.go b/common/page.go index a071340b9..96585993d 100644 --- a/common/page.go +++ b/common/page.go @@ -19,7 +19,7 @@ import ( "github.com/chromedp/cdproto/runtime" cdpruntime "github.com/chromedp/cdproto/runtime" "github.com/chromedp/cdproto/target" - "github.com/dop251/goja" + "github.com/grafana/sobek" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -104,9 +104,9 @@ const ( ) // Parse parses the given screen options. -func (s *Screen) Parse(ctx context.Context, screen goja.Value) error { +func (s *Screen) Parse(ctx context.Context, screen sobek.Value) error { rt := k6ext.Runtime(ctx) - if screen != nil && !goja.IsUndefined(screen) && !goja.IsNull(screen) { + if screen != nil && !sobek.IsUndefined(screen) && !sobek.IsNull(screen) { screen := screen.ToObject(rt) for _, k := range screen.Keys() { switch k { @@ -629,14 +629,14 @@ func (p *Page) BringToFront() error { } // Check checks an element matching the provided selector. -func (p *Page) Check(selector string, opts goja.Value) error { +func (p *Page) Check(selector string, opts sobek.Value) error { p.logger.Debugf("Page:Check", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().Check(selector, opts) } // Uncheck unchecks an element matching the provided selector. -func (p *Page) Uncheck(selector string, opts goja.Value) error { +func (p *Page) Uncheck(selector string, opts sobek.Value) error { p.logger.Debugf("Page:Uncheck", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().Uncheck(selector, opts) @@ -644,7 +644,7 @@ func (p *Page) Uncheck(selector string, opts goja.Value) error { // IsChecked returns true if the first element that matches the selector // is checked. Otherwise, returns false. -func (p *Page) IsChecked(selector string, opts goja.Value) (bool, error) { +func (p *Page) IsChecked(selector string, opts sobek.Value) (bool, error) { p.logger.Debugf("Page:IsChecked", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsChecked(selector, opts) @@ -658,7 +658,7 @@ func (p *Page) Click(selector string, opts *FrameClickOptions) error { } // Close closes the page. -func (p *Page) Close(_ goja.Value) error { +func (p *Page) Close(_ sobek.Value) error { p.logger.Debugf("Page:Close", "sid:%v", p.sessionID()) _, span := TraceAPICall(p.ctx, p.targetID.String(), "page.close") defer span.End() @@ -716,7 +716,7 @@ func (p *Page) Context() *BrowserContext { } // Dblclick double clicks an element matching provided selector. -func (p *Page) Dblclick(selector string, opts goja.Value) error { +func (p *Page) Dblclick(selector string, opts sobek.Value) error { p.logger.Debugf("Page:Dblclick", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().Dblclick(selector, opts) @@ -730,7 +730,7 @@ func (p *Page) DispatchEvent(selector string, typ string, eventInit any, opts *F } // EmulateMedia emulates the given media type. -func (p *Page) EmulateMedia(opts goja.Value) error { +func (p *Page) EmulateMedia(opts sobek.Value) error { p.logger.Debugf("Page:EmulateMedia", "sid:%v", p.sessionID()) parsedOpts := NewPageEmulateMediaOptions(p.mediaType, p.colorScheme, p.reducedMotion) @@ -802,14 +802,14 @@ func (p *Page) EvaluateHandle(pageFunc string, args ...any) (JSHandleAPI, error) } // Fill fills an input element with the provided value. -func (p *Page) Fill(selector string, value string, opts goja.Value) error { +func (p *Page) Fill(selector string, value string, opts sobek.Value) error { p.logger.Debugf("Page:Fill", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().Fill(selector, value, opts) } // Focus focuses an element matching the provided selector. -func (p *Page) Focus(selector string, opts goja.Value) error { +func (p *Page) Focus(selector string, opts sobek.Value) error { p.logger.Debugf("Page:Focus", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().Focus(selector, opts) @@ -822,7 +822,7 @@ func (p *Page) Frames() []*Frame { // GetAttribute returns the attribute value of the element matching the provided selector. // The second return value is true if the attribute exists, and false otherwise. -func (p *Page) GetAttribute(selector string, name string, opts goja.Value) (string, bool, error) { +func (p *Page) GetAttribute(selector string, name string, opts sobek.Value) (string, bool, error) { p.logger.Debugf("Page:GetAttribute", "sid:%v selector:%s name:%s", p.sessionID(), selector, name) @@ -865,28 +865,28 @@ func (p *Page) Goto(url string, opts *FrameGotoOptions) (*Response, error) { } // Hover hovers over an element matching the provided selector. -func (p *Page) Hover(selector string, opts goja.Value) error { +func (p *Page) Hover(selector string, opts sobek.Value) error { p.logger.Debugf("Page:Hover", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().Hover(selector, opts) } // InnerHTML returns the inner HTML of the element matching the provided selector. -func (p *Page) InnerHTML(selector string, opts goja.Value) (string, error) { +func (p *Page) InnerHTML(selector string, opts sobek.Value) (string, error) { p.logger.Debugf("Page:InnerHTML", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().InnerHTML(selector, opts) } // InnerText returns the inner text of the element matching the provided selector. -func (p *Page) InnerText(selector string, opts goja.Value) (string, error) { +func (p *Page) InnerText(selector string, opts sobek.Value) (string, error) { p.logger.Debugf("Page:InnerText", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().InnerText(selector, opts) } // InputValue returns the value of the input element matching the provided selector. -func (p *Page) InputValue(selector string, opts goja.Value) (string, error) { +func (p *Page) InputValue(selector string, opts sobek.Value) (string, error) { p.logger.Debugf("Page:InputValue", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().InputValue(selector, opts) @@ -901,7 +901,7 @@ func (p *Page) IsClosed() bool { // IsDisabled returns true if the first element that matches the selector // is disabled. Otherwise, returns false. -func (p *Page) IsDisabled(selector string, opts goja.Value) (bool, error) { +func (p *Page) IsDisabled(selector string, opts sobek.Value) (bool, error) { p.logger.Debugf("Page:IsDisabled", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsDisabled(selector, opts) @@ -909,7 +909,7 @@ func (p *Page) IsDisabled(selector string, opts goja.Value) (bool, error) { // IsEditable returns true if the first element that matches the selector // is editable. Otherwise, returns false. -func (p *Page) IsEditable(selector string, opts goja.Value) (bool, error) { +func (p *Page) IsEditable(selector string, opts sobek.Value) (bool, error) { p.logger.Debugf("Page:IsEditable", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsEditable(selector, opts) @@ -917,7 +917,7 @@ func (p *Page) IsEditable(selector string, opts goja.Value) (bool, error) { // IsEnabled returns true if the first element that matches the selector // is enabled. Otherwise, returns false. -func (p *Page) IsEnabled(selector string, opts goja.Value) (bool, error) { +func (p *Page) IsEnabled(selector string, opts sobek.Value) (bool, error) { p.logger.Debugf("Page:IsEnabled", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsEnabled(selector, opts) @@ -926,7 +926,7 @@ func (p *Page) IsEnabled(selector string, opts goja.Value) (bool, error) { // IsHidden will look for an element in the dom with given selector and see if // the element is hidden. It will not wait for a match to occur. If no elements // match `false` will be returned. -func (p *Page) IsHidden(selector string, opts goja.Value) (bool, error) { +func (p *Page) IsHidden(selector string, opts sobek.Value) (bool, error) { p.logger.Debugf("Page:IsHidden", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsHidden(selector, opts) @@ -934,14 +934,14 @@ func (p *Page) IsHidden(selector string, opts goja.Value) (bool, error) { // IsVisible will look for an element in the dom with given selector. It will // not wait for a match to occur. If no elements match `false` will be returned. -func (p *Page) IsVisible(selector string, opts goja.Value) (bool, error) { +func (p *Page) IsVisible(selector string, opts sobek.Value) (bool, error) { p.logger.Debugf("Page:IsVisible", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsVisible(selector, opts) } // Locator creates and returns a new locator for this page (main frame). -func (p *Page) Locator(selector string, opts goja.Value) *Locator { +func (p *Page) Locator(selector string, opts sobek.Value) *Locator { p.logger.Debugf("Page:Locator", "sid:%s sel: %q opts:%+v", p.sessionID(), selector, opts) return p.MainFrame().Locator(selector, opts) @@ -1000,7 +1000,7 @@ func (p *Page) Opener() *Page { } // Press presses the given key for the first element found that matches the selector. -func (p *Page) Press(selector string, key string, opts goja.Value) error { +func (p *Page) Press(selector string, key string, opts sobek.Value) error { p.logger.Debugf("Page:Press", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().Press(selector, key, opts) @@ -1021,7 +1021,7 @@ func (p *Page) QueryAll(selector string) ([]*ElementHandle, error) { } // Reload will reload the current page. -func (p *Page) Reload(opts goja.Value) (*Response, error) { //nolint:funlen,cyclop +func (p *Page) Reload(opts sobek.Value) (*Response, error) { //nolint:funlen,cyclop p.logger.Debugf("Page:Reload", "sid:%v", p.sessionID()) _, span := TraceAPICall(p.ctx, p.targetID.String(), "page.reload") defer span.End() @@ -1138,14 +1138,14 @@ func (p *Page) Screenshot(opts *PageScreenshotOptions, sp ScreenshotPersister) ( // SelectOption selects the given options and returns the array of // option values of the first element found that matches the selector. -func (p *Page) SelectOption(selector string, values goja.Value, opts goja.Value) ([]string, error) { +func (p *Page) SelectOption(selector string, values sobek.Value, opts sobek.Value) ([]string, error) { p.logger.Debugf("Page:SelectOption", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().SelectOption(selector, values, opts) } // SetContent replaces the entire HTML document content. -func (p *Page) SetContent(html string, opts goja.Value) error { +func (p *Page) SetContent(html string, opts sobek.Value) error { p.logger.Debugf("Page:SetContent", "sid:%v", p.sessionID()) return p.MainFrame().SetContent(html, opts) @@ -1174,14 +1174,14 @@ func (p *Page) SetExtraHTTPHeaders(headers map[string]string) error { } // SetInputFiles sets input files for the selected element. -func (p *Page) SetInputFiles(selector string, files goja.Value, opts goja.Value) error { +func (p *Page) SetInputFiles(selector string, files sobek.Value, opts sobek.Value) error { p.logger.Debugf("Page:SetInputFiles", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().SetInputFiles(selector, files, opts) } // SetViewportSize will update the viewport width and height. -func (p *Page) SetViewportSize(viewportSize goja.Value) error { +func (p *Page) SetViewportSize(viewportSize sobek.Value) error { p.logger.Debugf("Page:SetViewportSize", "sid:%v", p.sessionID()) var s Size @@ -1205,7 +1205,7 @@ func (p *Page) Tap(selector string, opts *FrameTapOptions) error { // TextContent returns the textContent attribute of the first element found // that matches the selector. The second return value is true if the returned // text content is not null or empty, and false otherwise. -func (p *Page) TextContent(selector string, opts goja.Value) (string, bool, error) { +func (p *Page) TextContent(selector string, opts sobek.Value) (string, bool, error) { p.logger.Debugf("Page:TextContent", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().TextContent(selector, opts) @@ -1269,7 +1269,7 @@ func (p *Page) ThrottleNetwork(networkProfile NetworkProfile) error { } // Type text on the first element found matches the selector. -func (p *Page) Type(selector string, text string, opts goja.Value) error { +func (p *Page) Type(selector string, text string, opts sobek.Value) error { p.logger.Debugf("Page:Type", "sid:%v selector:%s text:%s", p.sessionID(), selector, text) return p.MainFrame().Type(selector, text, opts) @@ -1310,7 +1310,7 @@ func (p *Page) WaitForFunction(js string, opts *FrameWaitForFunctionOptions, jsA } // WaitForLoadState waits for the specified page life cycle event. -func (p *Page) WaitForLoadState(state string, opts goja.Value) error { +func (p *Page) WaitForLoadState(state string, opts sobek.Value) error { p.logger.Debugf("Page:WaitForLoadState", "sid:%v state:%q", p.sessionID(), state) return p.frameManager.MainFrame().WaitForLoadState(state, opts) @@ -1332,7 +1332,7 @@ func (p *Page) WaitForNavigation(opts *FrameWaitForNavigationOptions) (*Response } // WaitForSelector waits for the given selector to match the waiting criteria. -func (p *Page) WaitForSelector(selector string, opts goja.Value) (*ElementHandle, error) { +func (p *Page) WaitForSelector(selector string, opts sobek.Value) (*ElementHandle, error) { p.logger.Debugf("Page:WaitForSelector", "sid:%v stid:%v ptid:%v selector:%s", p.sessionID(), p.session.TargetID(), p.targetID, selector) diff --git a/common/page_options.go b/common/page_options.go index cca1bdfe2..f2796c349 100644 --- a/common/page_options.go +++ b/common/page_options.go @@ -7,7 +7,7 @@ import ( "time" "github.com/chromedp/cdproto/page" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/k6ext" ) @@ -40,9 +40,9 @@ func NewPageEmulateMediaOptions(defaultMedia MediaType, defaultColorScheme Color } } -func (o *PageEmulateMediaOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *PageEmulateMediaOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -65,9 +65,9 @@ func NewPageReloadOptions(defaultWaitUntil LifecycleEvent, defaultTimeout time.D } } -func (o *PageReloadOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *PageReloadOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { opts := opts.ToObject(rt) for _, k := range opts.Keys() { switch k { @@ -97,9 +97,9 @@ func NewPageScreenshotOptions() *PageScreenshotOptions { } } -func (o *PageScreenshotOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *PageScreenshotOptions) Parse(ctx context.Context, opts sobek.Value) error { rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) { formatSpecified := false opts := opts.ToObject(rt) for _, k := range opts.Keys() { diff --git a/go.mod b/go.mod index 4bb5fc542..161f2d6b4 100644 --- a/go.mod +++ b/go.mod @@ -4,18 +4,19 @@ go 1.20 require ( github.com/chromedp/cdproto v0.0.0-20221023212508-67ada9507fb2 - github.com/dop251/goja v0.0.0-20240220182346-e401ed450204 + github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 github.com/gorilla/websocket v1.5.1 + github.com/grafana/sobek v0.0.0-20240606091932-2da0e9e5f3e7 github.com/mailru/easyjson v0.7.7 github.com/mccutchen/go-httpbin v1.1.2-0.20190116014521-c5cb2f4802fa github.com/mstoykov/k6-taskqueue-lib v0.1.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 - go.k6.io/k6 v0.51.1-0.20240529085517-bdbe5b52d1f5 + go.k6.io/k6 v0.51.1-0.20240607085553-e5b00dbe9090 go.opentelemetry.io/otel v1.24.0 go.opentelemetry.io/otel/trace v1.24.0 - golang.org/x/net v0.23.0 - golang.org/x/sync v0.6.0 + golang.org/x/net v0.26.0 + golang.org/x/sync v0.7.0 gopkg.in/guregu/null.v3 v3.3.0 ) @@ -56,9 +57,9 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/sdk v1.24.0 // indirect go.opentelemetry.io/proto/otlp v1.1.0 // indirect - golang.org/x/crypto v0.21.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/crypto v0.24.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect diff --git a/go.sum b/go.sum index eda3c0ba7..bbb24915c 100644 --- a/go.sum +++ b/go.sum @@ -16,23 +16,14 @@ github.com/chromedp/cdproto v0.0.0-20221023212508-67ada9507fb2 h1:xESwMZNYkDnZf9 github.com/chromedp/cdproto v0.0.0-20221023212508-67ada9507fb2/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs= github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic= github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= -github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= -github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic= -github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= -github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= -github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dlclark/regexp2 v1.9.0 h1:pTK/l/3qYIKaRXuHnEnIf7Y5NxfRPfpb7dis6/gdlVI= github.com/dlclark/regexp2 v1.9.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= -github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= -github.com/dop251/goja v0.0.0-20240220182346-e401ed450204 h1:O7I1iuzEA7SG+dK8ocOBSlYAA9jBUmCYl/Qa7ey7JAM= -github.com/dop251/goja v0.0.0-20240220182346-e401ed450204/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4= -github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= -github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM= +github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 h1:OFTHt+yJDo/uaIKMGjEKzc3DGhrpQZoqvMUIloZv6ZY= +github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2/go.mod h1:o31y53rb/qiIAONF7w3FHJZRqqP3fzHUr1HqanthByw= github.com/evanw/esbuild v0.21.2 h1:CLplcGi794CfHLVmUbvVfTMKkykm+nyIHU8SU60KUTA= github.com/evanw/esbuild v0.21.2/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= @@ -45,7 +36,6 @@ github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sourcemap/sourcemap v2.1.4+incompatible h1:a+iTbH5auLKxaNwQFg0B+TCYl6lbukKPc7b5x0n1s6Q= github.com/go-sourcemap/sourcemap v2.1.4+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= @@ -61,32 +51,26 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg= github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 h1:ZgoomqkdjGbQ3+qQXCkvYMCDvGDNg2k5JJDjjdTB6jY= github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +github.com/grafana/sobek v0.0.0-20240606091932-2da0e9e5f3e7 h1:Ed0df3dkkPsjL0RKagJAv/821vrTBiB6GBk+198pxi4= +github.com/grafana/sobek v0.0.0-20240606091932-2da0e9e5f3e7/go.mod h1:6ZH0b0iOxyigeTh+/IlGoL0Hd3lVXA94xoXf0ldNgCM= github.com/grafana/xk6-redis v0.2.0 h1:iXmAKVlAxafZ/h8ptuXTFhGu63IFsyDI8QjUgWm66BU= github.com/grafana/xk6-webcrypto v0.3.0 h1:piwiTrLTQDbuzC4CK0dVjbzQqNhIoGjWXrflf++W8aE= github.com/grafana/xk6-websockets v0.4.0 h1:gK0ekd7nIO4tPDzWk4ljQGzMep5Usy3Y/iuXZM7xXHI= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 h1:Wqo399gCIufwto+VfwCSvsnfGpF/w5E9CNxSwbpD6No= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0/go.mod h1:qmOFXW2epJhM0qSnUUYpldc7gVz2KMQwJ/QYCDIa7XU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= github.com/jhump/protoreflect v1.15.6 h1:WMYJbw2Wo+KOWwZFvgY0jMoVHM6i4XIvRs2RcBj5VmI= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -117,7 +101,6 @@ github.com/onsi/gomega v1.20.2/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8lu github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e h1:zWKUYT07mGmVBH+9UgnHXd/ekCK99C8EbDSAt5qsjXE= github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs= @@ -139,8 +122,8 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.k6.io/k6 v0.51.1-0.20240529085517-bdbe5b52d1f5 h1:cJBN6CjQVgxjmKduTN3VmEbZxruGnLO6Ip79FAf84Gw= -go.k6.io/k6 v0.51.1-0.20240529085517-bdbe5b52d1f5/go.mod h1:YvtuIbREVgWl7DuAT0IZqaiw4SxxRqLOXdlgkXkR0rU= +go.k6.io/k6 v0.51.1-0.20240607085553-e5b00dbe9090 h1:6DcSUo9zjj6SwaWfBMyteH/TUZV9D/qzNaeh1phNBu8= +go.k6.io/k6 v0.51.1-0.20240607085553-e5b00dbe9090/go.mod h1:Lgit6WY4nLmqLeNnPBltUX8kTBx5mUT1AyVkhrjo3HQ= go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 h1:t6wl9SPayj+c7lEIFgm4ooDBZVb01IhLB4InpomhRw8= @@ -162,8 +145,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= @@ -176,15 +159,15 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -196,7 +179,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -204,21 +186,19 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -246,10 +226,7 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/guregu/null.v3 v3.3.0 h1:8j3ggqq+NgKt/O7mbFVUFKUMWN+l1AmT5jQmJ6nPh2c= gopkg.in/guregu/null.v3 v3.3.0/go.mod h1:E4tX2Qe3h7QdL+uZ3a0vqvYwKQsRSQKM5V4YltdgH9Y= @@ -259,7 +236,6 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/k6ext/context.go b/k6ext/context.go index 8f763bcdc..f4570c59a 100644 --- a/k6ext/context.go +++ b/k6ext/context.go @@ -6,7 +6,7 @@ import ( k6modules "go.k6.io/k6/js/modules" k6lib "go.k6.io/k6/lib" - "github.com/dop251/goja" + "github.com/grafana/sobek" ) type ctxKey int @@ -23,7 +23,7 @@ func WithVU(ctx context.Context, vu k6modules.VU) context.Context { } // GetVU returns the attached k6 VU instance from ctx, which can be used to -// retrieve the goja runtime and other k6 objects relevant to the currently +// retrieve the sobek runtime and other k6 objects relevant to the currently // executing VU. // See https://github.com/grafana/k6/blob/v0.37.0/js/initcontext.go#L168-L186 func GetVU(ctx context.Context) k6modules.VU { @@ -49,7 +49,7 @@ func GetCustomMetrics(ctx context.Context) *CustomMetrics { } // Runtime is a convenience function for getting a k6 VU runtime. -func Runtime(ctx context.Context) *goja.Runtime { +func Runtime(ctx context.Context) *sobek.Runtime { return GetVU(ctx).Runtime() } diff --git a/k6ext/k6test/vu.go b/k6ext/k6test/vu.go index 007a68cd0..15e15bf63 100644 --- a/k6ext/k6test/vu.go +++ b/k6ext/k6test/vu.go @@ -5,7 +5,7 @@ import ( "fmt" "testing" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/stretchr/testify/require" "gopkg.in/guregu/null.v3" @@ -27,7 +27,7 @@ import ( // VU is a k6 VU instance. // TODO: Do we still need this VU wrapper? -// ToGojaValue can be a helper function that takes a goja.Runtime (although it's +// ToSobekValue can be a helper function that takes a sobek.Runtime (although it's // not much of a helper from calling ToValue(i) directly...), and we can access // EventLoop from modulestest.Runtime.EventLoop. type VU struct { @@ -38,8 +38,8 @@ type VU struct { TestRT *k6modulestest.Runtime } -// ToGojaValue is a convenience method for converting any value to a goja value. -func (v *VU) ToGojaValue(i any) goja.Value { return v.Runtime().ToValue(i) } +// ToSobekValue is a convenience method for converting any value to a sobek value. +func (v *VU) ToSobekValue(i any) sobek.Value { return v.Runtime().ToValue(i) } // ActivateVU mimicks activation of the VU as in k6. // It transitions the VU from the init stage to the execution stage by @@ -127,24 +127,24 @@ func (v *VU) iterEvent(tb testing.TB, eventType event.Type, eventName string, op } // RunOnEventLoop runs the given JavaScript code on the VU's event loop and -// returns the result as a goja.Value. -func (v *VU) RunOnEventLoop(tb testing.TB, js string, args ...any) (goja.Value, error) { +// returns the result as a sobek.Value. +func (v *VU) RunOnEventLoop(tb testing.TB, js string, args ...any) (sobek.Value, error) { tb.Helper() return v.TestRT.RunOnEventLoop(fmt.Sprintf(js, args...)) } // RunAsync runs the given JavaScript code on the VU's event loop and returns -// the result as a goja.Value. -func (v *VU) RunAsync(tb testing.TB, js string, args ...any) (goja.Value, error) { +// the result as a sobek.Value. +func (v *VU) RunAsync(tb testing.TB, js string, args ...any) (sobek.Value, error) { tb.Helper() return v.RunOnEventLoop(tb, fmt.Sprintf("(async function() { "+js+" })();", args...)) } // RunPromise runs the given JavaScript code on the VU's event loop and returns -// the result as a *goja.Promise. -func (v *VU) RunPromise(tb testing.TB, js string, args ...any) *goja.Promise { +// the result as a *sobek.Promise. +func (v *VU) RunPromise(tb testing.TB, js string, args ...any) *sobek.Promise { tb.Helper() gv, err := v.RunAsync(tb, js, args...) @@ -152,7 +152,7 @@ func (v *VU) RunPromise(tb testing.TB, js string, args ...any) *goja.Promise { return ToPromise(tb, gv) } -// SetVar sets a variable in the VU's Goja runtime's global scope. +// SetVar sets a variable in the VU's sobek runtime's global scope. func (v *VU) SetVar(tb testing.TB, name string, value any) { tb.Helper() @@ -160,12 +160,12 @@ func (v *VU) SetVar(tb testing.TB, name string, value any) { require.NoError(tb, err, "setting variable %q to %v", name, value) } -// ToPromise asserts and returns a goja.Value as a *goja.Promise. -func ToPromise(tb testing.TB, gv goja.Value) *goja.Promise { +// ToPromise asserts and returns a sobek.Value as a *sobek.Promise. +func ToPromise(tb testing.TB, gv sobek.Value) *sobek.Promise { tb.Helper() - p, ok := gv.Export().(*goja.Promise) - require.True(tb, ok, "got: %T, want *goja.Promise", gv.Export()) + p, ok := gv.Export().(*sobek.Promise) + require.True(tb, ok, "got: %T, want *sobek.Promise", gv.Export()) return p } diff --git a/k6ext/panic.go b/k6ext/panic.go index 53611c88f..780568026 100644 --- a/k6ext/panic.go +++ b/k6ext/panic.go @@ -8,18 +8,18 @@ import ( "strings" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "go.k6.io/k6/errext" k6common "go.k6.io/k6/js/common" ) // Abort will shutdown the whole test run. This should -// only be used from the goja mapping layer. It is only +// only be used from the sobek mapping layer. It is only // to be used when an error will occur in all iterations, // so it's permanent. func Abort(ctx context.Context, format string, a ...any) { - failFunc := func(rt *goja.Runtime, a ...any) { + failFunc := func(rt *sobek.Runtime, a ...any) { reason := fmt.Errorf(format, a...).Error() rt.Interrupt(&errext.InterruptError{Reason: reason}) } @@ -31,13 +31,13 @@ func Abort(ctx context.Context, format string, a ...any) { // browser process from the context and kill it if it still exists. // TODO: test. func Panic(ctx context.Context, format string, a ...any) { - failFunc := func(rt *goja.Runtime, a ...any) { + failFunc := func(rt *sobek.Runtime, a ...any) { k6common.Throw(rt, fmt.Errorf(format, a...)) } sharedPanic(ctx, failFunc, a...) } -func sharedPanic(ctx context.Context, failFunc func(rt *goja.Runtime, a ...any), a ...any) { +func sharedPanic(ctx context.Context, failFunc func(rt *sobek.Runtime, a ...any), a ...any) { rt := Runtime(ctx) if rt == nil { // this should never happen unless a programmer error diff --git a/k6ext/promise.go b/k6ext/promise.go index 6b4465f40..5aca02218 100644 --- a/k6ext/promise.go +++ b/k6ext/promise.go @@ -3,7 +3,7 @@ package k6ext import ( "context" - "github.com/dop251/goja" + "github.com/grafana/sobek" ) // eventLoopDirective determines whether the event @@ -18,20 +18,20 @@ const ( // PromisifiedFunc is a type of the function to run as a promise. type PromisifiedFunc func() (result any, reason error) -// Promise runs fn in a goroutine and returns a new goja.Promise. +// Promise runs fn in a goroutine and returns a new sobek.Promise. // - If fn returns a nil error, resolves the promise with the // first result value fn returns. // - Otherwise, rejects the promise with the error fn returns. -func Promise(ctx context.Context, fn PromisifiedFunc) *goja.Promise { +func Promise(ctx context.Context, fn PromisifiedFunc) *sobek.Promise { return promise(ctx, fn, continueEventLoop) } // AbortingPromise is like Promise, but it aborts the event loop if an error occurs. -func AbortingPromise(ctx context.Context, fn PromisifiedFunc) *goja.Promise { +func AbortingPromise(ctx context.Context, fn PromisifiedFunc) *sobek.Promise { return promise(ctx, fn, abortEventLoop) } -func promise(ctx context.Context, fn PromisifiedFunc, d eventLoopDirective) *goja.Promise { +func promise(ctx context.Context, fn PromisifiedFunc, d eventLoopDirective) *sobek.Promise { var ( vu = GetVU(ctx) cb = vu.RegisterCallback() diff --git a/tests/browser_context_options_test.go b/tests/browser_context_options_test.go index ee062036f..4741bb547 100644 --- a/tests/browser_context_options_test.go +++ b/tests/browser_context_options_test.go @@ -51,7 +51,7 @@ func TestBrowserContextOptionsSetViewport(t *testing.T) { t.Parallel() tb := newTestBrowser(t) - bctx, err := tb.NewContext(tb.toGojaValue(struct { + bctx, err := tb.NewContext(tb.toSobekValue(struct { Viewport common.Viewport `js:"viewport"` }{ Viewport: common.Viewport{ @@ -77,7 +77,7 @@ func TestBrowserContextOptionsExtraHTTPHeaders(t *testing.T) { t.Parallel() tb := newTestBrowser(t, withHTTPServer()) - bctx, err := tb.NewContext(tb.toGojaValue(struct { + bctx, err := tb.NewContext(tb.toSobekValue(struct { ExtraHTTPHeaders map[string]string `js:"extraHTTPHeaders"` }{ ExtraHTTPHeaders: map[string]string{ diff --git a/tests/browser_type_test.go b/tests/browser_type_test.go index b803c7256..13734d404 100644 --- a/tests/browser_type_test.go +++ b/tests/browser_type_test.go @@ -38,7 +38,7 @@ func TestBrowserTypeLaunchToConnect(t *testing.T) { // pointing to test browser proxy vu := k6test.NewVU(t, env.ConstLookup(env.WebSocketURLs, bp.wsURL())) - // We have to call launch method through JS API in Goja + // We have to call launch method through JS API in sobek // to take mapping layer into account, instead of calling // BrowserType.Launch method directly root := browser.New() diff --git a/tests/element_handle_test.go b/tests/element_handle_test.go index d81ffba37..89b966363 100644 --- a/tests/element_handle_test.go +++ b/tests/element_handle_test.go @@ -182,7 +182,7 @@ func TestElementHandleClickConcealedLink(t *testing.T) { tb := newTestBrowser(t, withFileServer()) bc, err := tb.NewContext( - tb.toGojaValue(struct { + tb.toSobekValue(struct { Viewport common.Viewport `js:"viewport"` }{ Viewport: common.Viewport{ @@ -412,7 +412,7 @@ func TestElementHandleScreenshot(t *testing.T) { tb := newTestBrowser(t) p := tb.NewPage(nil) - err := p.SetViewportSize(tb.toGojaValue(struct { + err := p.SetViewportSize(tb.toSobekValue(struct { Width float64 `js:"width"` Height float64 `js:"height"` }{Width: 800, Height: 600})) @@ -486,7 +486,7 @@ func TestElementHandleWaitForSelector(t *testing.T) { } `) require.NoError(t, err) - element, err := root.WaitForSelector(".element-to-appear", tb.toGojaValue(struct { + element, err := root.WaitForSelector(".element-to-appear", tb.toSobekValue(struct { Timeout int64 `js:"timeout"` }{Timeout: 1000})) require.NoError(t, err) diff --git a/tests/helpers.go b/tests/helpers.go index 4a4852e69..35295bbc2 100644 --- a/tests/helpers.go +++ b/tests/helpers.go @@ -3,7 +3,7 @@ package tests import ( "testing" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/stretchr/testify/require" "github.com/grafana/xk6-browser/browser" @@ -15,7 +15,7 @@ import ( // force all tests that work with this to go through the mapping layer. // This returns a cleanup function which should be deferred. // The opts are passed to k6test.NewVU as is without any modification. -func startIteration(t *testing.T, opts ...any) (*k6test.VU, *goja.Runtime, *[]string, func()) { +func startIteration(t *testing.T, opts ...any) (*k6test.VU, *sobek.Runtime, *[]string, func()) { t.Helper() vu := k6test.NewVU(t, opts...) @@ -25,7 +25,7 @@ func startIteration(t *testing.T, opts ...any) (*k6test.VU, *goja.Runtime, *[]st jsMod, ok := mod.Exports().Default.(*browser.JSModule) require.Truef(t, ok, "unexpected default mod export type %T", mod.Exports().Default) - // Setting the mapped browser into the vu's goja runtime. + // Setting the mapped browser into the vu's sobek runtime. require.NoError(t, rt.Set("browser", jsMod.Browser)) // Setting log, which is used by the callers to assert that certain actions diff --git a/tests/launch_options_slowmo_test.go b/tests/launch_options_slowmo_test.go index 889b2205a..341adf0d9 100644 --- a/tests/launch_options_slowmo_test.go +++ b/tests/launch_options_slowmo_test.go @@ -54,7 +54,7 @@ func TestBrowserOptionsSlowMo(t *testing.T) { t.Parallel() tb := newTestBrowser(t, withFileServer()) testPageSlowMoImpl(t, tb, func(_ *testBrowser, p *common.Page) { - err := p.EmulateMedia(tb.toGojaValue(struct { + err := p.EmulateMedia(tb.toSobekValue(struct { Media string `js:"media"` }{ Media: "print", @@ -149,7 +149,7 @@ func TestBrowserOptionsSlowMo(t *testing.T) { t.Parallel() tb := newTestBrowser(t, withFileServer()) testPageSlowMoImpl(t, tb, func(_ *testBrowser, p *common.Page) { - _, err := p.SelectOption("select", tb.toGojaValue("foo"), nil) + _, err := p.SelectOption("select", tb.toSobekValue("foo"), nil) require.NoError(t, err) }) }) @@ -281,7 +281,7 @@ func TestBrowserOptionsSlowMo(t *testing.T) { t.Parallel() tb := newTestBrowser(t, withFileServer()) testFrameSlowMoImpl(t, tb, func(_ *testBrowser, f *common.Frame) { - _, err := f.SelectOption("select", tb.toGojaValue("foo"), nil) + _, err := f.SelectOption("select", tb.toSobekValue("foo"), nil) require.NoError(t, err) }) }) diff --git a/tests/lifecycle_wait_test.go b/tests/lifecycle_wait_test.go index 715bb4628..c56f237fc 100644 --- a/tests/lifecycle_wait_test.go +++ b/tests/lifecycle_wait_test.go @@ -412,7 +412,7 @@ func TestLifecycleReload(t *testing.T) { } tt.pingJSTextAssert(result) - opts := tb.toGojaValue(common.PageReloadOptions{ + opts := tb.toSobekValue(common.PageReloadOptions{ WaitUntil: tt.waitUntil, Timeout: 30 * time.Second, }) diff --git a/tests/locator_test.go b/tests/locator_test.go index caaedeac4..464a06228 100644 --- a/tests/locator_test.go +++ b/tests/locator_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -16,7 +16,7 @@ import ( // than one element matches the locator's selector. // Note: -// We skip adding t.Parallel to subtests because goja or our code might race. +// We skip adding t.Parallel to subtests because sobek or our code might race. type jsFrameWaitForSelectorOpts struct { jsFrameBaseOpts @@ -228,7 +228,7 @@ func TestLocator(t *testing.T) { { "SelectOption", func(tb *testBrowser, p *common.Page) { l := p.Locator("#selectElement", nil) - rv, err := l.SelectOption(tb.toGojaValue(`option text 2`), nil) + rv, err := l.SelectOption(tb.toSobekValue(`option text 2`), nil) require.NoError(t, err) require.Len(t, rv, 1) require.Equal(t, "option text 2", rv[0]) @@ -267,14 +267,14 @@ func TestLocator(t *testing.T) { }, { "WaitFor state:visible", func(tb *testBrowser, p *common.Page) { - opts := tb.toGojaValue(jsFrameBaseOpts{Timeout: "100"}) + opts := tb.toSobekValue(jsFrameBaseOpts{Timeout: "100"}) lo := p.Locator("#link", nil) require.NoError(t, lo.WaitFor(opts)) }, }, { "WaitFor state:attached", func(tb *testBrowser, p *common.Page) { - opts := tb.toGojaValue(jsFrameWaitForSelectorOpts{ + opts := tb.toSobekValue(jsFrameWaitForSelectorOpts{ jsFrameBaseOpts: jsFrameBaseOpts{Timeout: "100"}, State: "attached", }) @@ -284,7 +284,7 @@ func TestLocator(t *testing.T) { }, { "WaitFor state:hidden", func(tb *testBrowser, p *common.Page) { - opts := tb.toGojaValue(jsFrameWaitForSelectorOpts{ + opts := tb.toSobekValue(jsFrameWaitForSelectorOpts{ jsFrameBaseOpts: jsFrameBaseOpts{Timeout: "100"}, State: "hidden", }) @@ -294,7 +294,7 @@ func TestLocator(t *testing.T) { }, { "WaitFor state:detached", func(tb *testBrowser, p *common.Page) { - opts := tb.toGojaValue(jsFrameWaitForSelectorOpts{ + opts := tb.toSobekValue(jsFrameWaitForSelectorOpts{ jsFrameBaseOpts: jsFrameBaseOpts{Timeout: "100"}, State: "detached", }) @@ -322,8 +322,8 @@ func TestLocator(t *testing.T) { }) } - timeout := func(tb *testBrowser) goja.Value { - return tb.toGojaValue(jsFrameBaseOpts{Timeout: "100"}) + timeout := func(tb *testBrowser) sobek.Value { + return tb.toSobekValue(jsFrameBaseOpts{Timeout: "100"}) } sanityTests := []struct { name string @@ -403,7 +403,7 @@ func TestLocator(t *testing.T) { }, { "SelectOption", func(l *common.Locator, tb *testBrowser) error { - _, err := l.SelectOption(tb.toGojaValue(""), timeout(tb)) + _, err := l.SelectOption(tb.toSobekValue(""), timeout(tb)) return err }, }, @@ -548,8 +548,8 @@ func TestLocatorElementState(t *testing.T) { }) } - timeout := func(tb *testBrowser) goja.Value { - return tb.toGojaValue(jsFrameBaseOpts{Timeout: "100"}) + timeout := func(tb *testBrowser) sobek.Value { + return tb.toSobekValue(jsFrameBaseOpts{Timeout: "100"}) } sanityTests := []struct { name string diff --git a/tests/network_manager_test.go b/tests/network_manager_test.go index 0352911c3..7416c1e90 100644 --- a/tests/network_manager_test.go +++ b/tests/network_manager_test.go @@ -113,7 +113,7 @@ func TestBasicAuth(t *testing.T) { browser := newTestBrowser(t, withHTTPServer()) bc, err := browser.NewContext( - browser.toGojaValue(struct { + browser.toSobekValue(struct { HttpCredentials *common.Credentials `js:"httpCredentials"` //nolint:revive }{ HttpCredentials: &common.Credentials{ diff --git a/tests/page_test.go b/tests/page_test.go index b30ed6701..bf7bef659 100644 --- a/tests/page_test.go +++ b/tests/page_test.go @@ -14,7 +14,7 @@ import ( "testing" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -87,7 +87,7 @@ func TestPageEmulateMedia(t *testing.T) { tb := newTestBrowser(t) p := tb.NewPage(nil) - err := p.EmulateMedia(tb.toGojaValue(emulateMediaOpts{ + err := p.EmulateMedia(tb.toSobekValue(emulateMediaOpts{ Media: "print", ColorScheme: "dark", ReducedMotion: "reduce", @@ -203,12 +203,12 @@ func TestPageEvaluateMapping(t *testing.T) { { name: "arrow_func_no_return", script: "() => {2}", - want: goja.Null(), + want: sobek.Null(), }, { name: "full_func_no_return", script: "function() {3}", - want: goja.Null(), + want: sobek.Null(), }, { name: "async_func", @@ -226,19 +226,19 @@ func TestPageEvaluateMapping(t *testing.T) { defer cleanUp() // Test script as non string input - vu.SetVar(t, "p", &goja.Object{}) + vu.SetVar(t, "p", &sobek.Object{}) got := vu.RunPromise(t, ` p = await browser.newPage() return await p.evaluate(%s) `, tt.script) - assert.Equal(t, vu.ToGojaValue(tt.want), got.Result()) + assert.Equal(t, vu.ToSobekValue(tt.want), got.Result()) // Test script as string input got = vu.RunPromise(t, `return await p.evaluate("%s")`, tt.script, ) - assert.Equal(t, vu.ToGojaValue(tt.want), got.Result()) + assert.Equal(t, vu.ToSobekValue(tt.want), got.Result()) }) } } @@ -272,7 +272,7 @@ func TestPageEvaluateMappingError(t *testing.T) { defer cleanUp() // Test script as non string input - vu.SetVar(t, "p", &goja.Object{}) + vu.SetVar(t, "p", &sobek.Object{}) _, err := vu.RunAsync(t, ` p = await browser.newPage() await p.evaluate(%s) @@ -403,7 +403,7 @@ func TestPageInnerHTML(t *testing.T) { p := tb.NewPage(nil) err := p.SetContent(sampleHTML, nil) require.NoError(t, err) - _, err = p.InnerHTML("p", tb.toGojaValue(jsFrameBaseOpts{Timeout: "100"})) + _, err = p.InnerHTML("p", tb.toSobekValue(jsFrameBaseOpts{Timeout: "100"})) require.Error(t, err) }) } @@ -438,7 +438,7 @@ func TestPageInnerText(t *testing.T) { p := tb.NewPage(nil) err := p.SetContent(sampleHTML, nil) require.NoError(t, err) - _, err = p.InnerText("p", tb.toGojaValue(jsFrameBaseOpts{Timeout: "100"})) + _, err = p.InnerText("p", tb.toSobekValue(jsFrameBaseOpts{Timeout: "100"})) require.Error(t, err) }) } @@ -474,7 +474,7 @@ func TestPageTextContent(t *testing.T) { p := tb.NewPage(nil) err := p.SetContent(sampleHTML, nil) require.NoError(t, err) - _, _, err = p.TextContent("p", tb.toGojaValue(jsFrameBaseOpts{ + _, _, err = p.TextContent("p", tb.toSobekValue(jsFrameBaseOpts{ Timeout: "100", })) require.Error(t, err) @@ -487,7 +487,7 @@ func TestPageTextContent(t *testing.T) { p := tb.NewPage(nil) err := p.SetContent(sampleHTML, nil) require.NoError(t, err) - _, _, err = p.TextContent("p", tb.toGojaValue(jsFrameBaseOpts{ + _, _, err = p.TextContent("p", tb.toSobekValue(jsFrameBaseOpts{ Timeout: "100", })) require.Error(t, err) @@ -615,7 +615,7 @@ func TestPageScreenshotFullpage(t *testing.T) { tb := newTestBrowser(t) p := tb.NewPage(nil) - err := p.SetViewportSize(tb.toGojaValue(struct { + err := p.SetViewportSize(tb.toSobekValue(struct { Width float64 `js:"width"` Height float64 `js:"height"` }{ @@ -723,7 +723,7 @@ func TestPageWaitForFunction(t *testing.T) { vu, _, log, cleanUp := startIteration(t) defer cleanUp() - vu.SetVar(t, "page", &goja.Object{}) + vu.SetVar(t, "page", &sobek.Object{}) _, err := vu.RunOnEventLoop(t, `fn = () => { if (typeof window._cnt == 'undefined') window._cnt = 0; if (window._cnt >= 50) return true; @@ -754,7 +754,7 @@ func TestPageWaitForFunction(t *testing.T) { assert.Contains(t, *log, "ok: null") p := vu.RunPromise(t, `return await page.evaluate(() => window._arg);`) - require.Equal(t, p.State(), goja.PromiseStateFulfilled) + require.Equal(t, p.State(), sobek.PromiseStateFulfilled) assert.Equal(t, "raf_arg", p.Result().String()) }) @@ -779,7 +779,7 @@ func TestPageWaitForFunction(t *testing.T) { assert.Contains(t, *log, "ok: null") p := vu.RunPromise(t, `return await page.evaluate(() => window._args);`) - require.Equal(t, p.State(), goja.PromiseStateFulfilled) + require.Equal(t, p.State(), sobek.PromiseStateFulfilled) var gotArgs []int _ = rt.ExportTo(p.Result(), &gotArgs) assert.Equal(t, args, gotArgs) @@ -814,7 +814,7 @@ func TestPageWaitForFunction(t *testing.T) { vu, _, log, cleanUp := startIteration(t) defer cleanUp() - vu.SetVar(t, "page", &goja.Object{}) + vu.SetVar(t, "page", &sobek.Object{}) _, err := vu.RunAsync(t, ` page = await browser.newPage(); await page.evaluate(() => { @@ -845,7 +845,7 @@ func TestPageWaitForFunction(t *testing.T) { vu, _, log, cleanUp := startIteration(t) defer cleanUp() - vu.SetVar(t, "page", &goja.Object{}) + vu.SetVar(t, "page", &sobek.Object{}) _, err := vu.RunAsync(t, ` fn = () => document.querySelector('h1') !== null @@ -1262,12 +1262,12 @@ func TestPageOn(t *testing.T) { } } -func assertExceptionContains(t *testing.T, rt *goja.Runtime, fn func(), expErrMsg string) { +func assertExceptionContains(t *testing.T, rt *sobek.Runtime, fn func(), expErrMsg string) { t.Helper() - cal, _ := goja.AssertFunction(rt.ToValue(fn)) + cal, _ := sobek.AssertFunction(rt.ToValue(fn)) - _, err := cal(goja.Undefined()) + _, err := cal(sobek.Undefined()) require.ErrorContains(t, err, expErrMsg) } @@ -1383,7 +1383,7 @@ func TestPageWaitForSelector(t *testing.T) { ) require.NoError(t, err) - _, err = page.WaitForSelector(tc.selector, tb.toGojaValue(tc.opts)) + _, err = page.WaitForSelector(tc.selector, tb.toSobekValue(tc.opts)) tc.errAssert(t, err) }) } @@ -1614,7 +1614,7 @@ func TestPageIsVisible(t *testing.T) { ) require.NoError(t, err) - got, err := page.IsVisible(tc.selector, tb.toGojaValue(tc.options)) + got, err := page.IsVisible(tc.selector, tb.toSobekValue(tc.options)) if tc.wantErr != "" { assert.ErrorContains(t, err, tc.wantErr) @@ -1685,7 +1685,7 @@ func TestPageIsHidden(t *testing.T) { ) require.NoError(t, err) - got, err := page.IsHidden(tc.selector, tb.toGojaValue(tc.options)) + got, err := page.IsHidden(tc.selector, tb.toSobekValue(tc.options)) if tc.wantErr != "" { assert.ErrorContains(t, err, tc.wantErr) diff --git a/tests/setinputfiles_test.go b/tests/setinputfiles_test.go index 9859ca5f5..6e8f2a12a 100644 --- a/tests/setinputfiles_test.go +++ b/tests/setinputfiles_test.go @@ -3,7 +3,7 @@ package tests import ( "testing" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -16,8 +16,8 @@ func TestSetInputFiles(t *testing.T) { type file map[string]interface{} type indexedFn func(idx int, propName string) interface{} - type testFn func(tb *testBrowser, page *common.Page, files goja.Value) error - type setupFn func(tb *testBrowser) (goja.Value, func()) + type testFn func(tb *testBrowser, page *common.Page, files sobek.Value) error + type setupFn func(tb *testBrowser) (sobek.Value, func()) type checkFn func(t *testing.T, getFileCountFn func() interface{}, getFilePropFn indexedFn, @@ -35,13 +35,13 @@ func TestSetInputFiles(t *testing.T) { ` - defaultTestPage := func(tb *testBrowser, page *common.Page, files goja.Value) error { - return page.SetInputFiles("#upload", files, tb.toGojaValue(nil)) + defaultTestPage := func(tb *testBrowser, page *common.Page, files sobek.Value) error { + return page.SetInputFiles("#upload", files, tb.toSobekValue(nil)) } - defaultTestElementHandle := func(tb *testBrowser, page *common.Page, files goja.Value) error { - handle, err := page.WaitForSelector("#upload", tb.toGojaValue(nil)) + defaultTestElementHandle := func(tb *testBrowser, page *common.Page, files sobek.Value) error { + handle, err := page.WaitForSelector("#upload", tb.toSobekValue(nil)) assert.NoError(t, err) - return handle.SetInputFiles(files, tb.toGojaValue(nil)) + return handle.SetInputFiles(files, tb.toSobekValue(nil)) } testCases := []struct { @@ -52,8 +52,8 @@ func TestSetInputFiles(t *testing.T) { }{ { name: "set_one_file_with_object", - setup: func(tb *testBrowser) (goja.Value, func()) { - return tb.toGojaValue(file{"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}), nil + setup: func(tb *testBrowser) (sobek.Value, func()) { + return tb.toSobekValue(file{"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}), nil }, tests: []testFn{defaultTestPage, defaultTestElementHandle}, check: func(t *testing.T, getFileCountFn func() interface{}, getFilePropFn indexedFn, err error) { @@ -69,8 +69,8 @@ func TestSetInputFiles(t *testing.T) { }, { name: "set_two_files_with_array_of_objects", - setup: func(tb *testBrowser) (goja.Value, func()) { - return tb.toGojaValue( + setup: func(tb *testBrowser) (sobek.Value, func()) { + return tb.toSobekValue( []file{ {"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}, {"name": "test.xml", "mimetype": "text/xml", "buffer": "MDEyMzQ1Njc4OTAxMjM0"}, @@ -93,8 +93,8 @@ func TestSetInputFiles(t *testing.T) { }, { name: "set_nil", - setup: func(tb *testBrowser) (goja.Value, func()) { - return tb.toGojaValue(nil), nil + setup: func(tb *testBrowser) (sobek.Value, func()) { + return tb.toSobekValue(nil), nil }, tests: []testFn{defaultTestPage, defaultTestElementHandle}, check: func(t *testing.T, getFileCountFn func() interface{}, getFilePropertyFn indexedFn, err error) { @@ -106,8 +106,8 @@ func TestSetInputFiles(t *testing.T) { }, { name: "set_invalid_parameter", - setup: func(tb *testBrowser) (goja.Value, func()) { - return tb.toGojaValue([]int{12345}), nil + setup: func(tb *testBrowser) (sobek.Value, func()) { + return tb.toSobekValue([]int{12345}), nil }, tests: []testFn{defaultTestPage, defaultTestElementHandle}, check: func(t *testing.T, getFileCountFn func() interface{}, getFilePropFn indexedFn, err error) { @@ -119,17 +119,17 @@ func TestSetInputFiles(t *testing.T) { }, { name: "test_injected_script_notinput", - setup: func(tb *testBrowser) (goja.Value, func()) { - return tb.toGojaValue(file{"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}), nil + setup: func(tb *testBrowser) (sobek.Value, func()) { + return tb.toSobekValue(file{"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}), nil }, tests: []testFn{ - func(tb *testBrowser, page *common.Page, files goja.Value) error { - return page.SetInputFiles("#button1", files, tb.toGojaValue(nil)) + func(tb *testBrowser, page *common.Page, files sobek.Value) error { + return page.SetInputFiles("#button1", files, tb.toSobekValue(nil)) }, - func(tb *testBrowser, page *common.Page, files goja.Value) error { - handle, err := page.WaitForSelector("#button1", tb.toGojaValue(nil)) + func(tb *testBrowser, page *common.Page, files sobek.Value) error { + handle, err := page.WaitForSelector("#button1", tb.toSobekValue(nil)) assert.NoError(t, err) - return handle.SetInputFiles(files, tb.toGojaValue(nil)) + return handle.SetInputFiles(files, tb.toSobekValue(nil)) }, }, check: func(t *testing.T, getFileCountFn func() interface{}, getFilePropFn indexedFn, err error) { @@ -142,17 +142,17 @@ func TestSetInputFiles(t *testing.T) { }, { name: "test_injected_script_notfile", - setup: func(tb *testBrowser) (goja.Value, func()) { - return tb.toGojaValue(file{"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}), nil + setup: func(tb *testBrowser) (sobek.Value, func()) { + return tb.toSobekValue(file{"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}), nil }, tests: []testFn{ - func(tb *testBrowser, page *common.Page, files goja.Value) error { - return page.SetInputFiles("#textinput", files, tb.toGojaValue(nil)) + func(tb *testBrowser, page *common.Page, files sobek.Value) error { + return page.SetInputFiles("#textinput", files, tb.toSobekValue(nil)) }, - func(tb *testBrowser, page *common.Page, files goja.Value) error { - handle, err := page.WaitForSelector("#textinput", tb.toGojaValue(nil)) + func(tb *testBrowser, page *common.Page, files sobek.Value) error { + handle, err := page.WaitForSelector("#textinput", tb.toSobekValue(nil)) assert.NoError(t, err) - return handle.SetInputFiles(files, tb.toGojaValue(nil)) + return handle.SetInputFiles(files, tb.toSobekValue(nil)) }, }, check: func(t *testing.T, getFileCountFn func() interface{}, getFilePropFn indexedFn, err error) { diff --git a/tests/test_browser.go b/tests/test_browser.go index aad479a1a..c56ced2b3 100644 --- a/tests/test_browser.go +++ b/tests/test_browser.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/stretchr/testify/require" "golang.org/x/sync/errgroup" @@ -253,7 +253,7 @@ func withSkipClose() func(*testBrowser) { // NewPage is a wrapper around Browser.NewPage that fails the test if an // error occurs. Added this helper to avoid boilerplate code in tests. -func (b *testBrowser) NewPage(opts goja.Value) *common.Page { +func (b *testBrowser) NewPage(opts sobek.Value) *common.Page { b.t.Helper() p, err := b.Browser.NewPage(opts) @@ -285,13 +285,13 @@ func (b *testBrowser) context() context.Context { return b.ctx } func (b *testBrowser) cancelContext() { b.cancel() } // runtime returns a VU runtime. -func (b *testBrowser) runtime() *goja.Runtime { return b.vu.Runtime() } +func (b *testBrowser) runtime() *sobek.Runtime { return b.vu.Runtime() } -// toGojaValue converts a value to goja value. -func (b *testBrowser) toGojaValue(i any) goja.Value { return b.runtime().ToValue(i) } +// toSobekValue converts a value to sobek value. +func (b *testBrowser) toSobekValue(i any) sobek.Value { return b.runtime().ToValue(i) } -// runJavaScript in the goja runtime. -func (b *testBrowser) runJavaScript(s string, args ...any) (goja.Value, error) { +// runJavaScript in the sobek runtime. +func (b *testBrowser) runJavaScript(s string, args ...any) (sobek.Value, error) { b.t.Helper() v, err := b.runtime().RunString(fmt.Sprintf(s, args...)) if err != nil { diff --git a/tests/tracing_test.go b/tests/tracing_test.go index c7e884119..32cdc0488 100644 --- a/tests/tracing_test.go +++ b/tests/tracing_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace/embedded" @@ -158,7 +158,7 @@ func TestTracing(t *testing.T) { } } -func setupTestTracing(t *testing.T, rt *goja.Runtime) { +func setupTestTracing(t *testing.T, rt *sobek.Runtime) { t.Helper() // Declare a global page var that we can use @@ -185,11 +185,11 @@ func assertJSInEventLoop(t *testing.T, vu *k6test.VU, js string) { _, err := rt.RunString(f) require.NoError(t, err) - test, ok := goja.AssertFunction(rt.Get("test")) + test, ok := sobek.AssertFunction(rt.Get("test")) require.True(t, ok) err = vu.Loop.Start(func() error { - _, err := test(goja.Undefined()) + _, err := test(sobek.Undefined()) return err }) require.NoError(t, err)