From 2d8a5affe9530035697675df2a5e9cb28a3b6c7d Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 6 Jun 2024 16:18:58 +0300 Subject: [PATCH] Change to using serbo instead of goja We are moving to a fork of goja under grafana org called serbo. More info in: - https://github.com/grafana/k6/issues/3772 - https://github.com/grafana/k6/issues/3773 --- browser/browser_context_mapping.go | 16 +- browser/browser_mapping.go | 6 +- browser/console_message_mapping.go | 10 +- browser/element_handle_mapping.go | 12 +- browser/frame_mapping.go | 28 +-- browser/helpers.go | 10 +- browser/js_handle_mapping.go | 8 +- browser/locator_mapping.go | 10 +- browser/mapping.go | 6 +- browser/mapping_test.go | 282 ++++++++++++++--------------- browser/module.go | 4 +- browser/page_mapping.go | 42 ++--- browser/request_mapping.go | 6 +- browser/response_mapping.go | 6 +- browser/touchscreen_mapping.go | 4 +- common/browser.go | 6 +- common/browser_context.go | 6 +- common/browser_context_options.go | 20 +- common/connection.go | 6 +- common/element_handle.go | 42 ++--- common/element_handle_options.go | 54 +++--- common/execution_context.go | 6 +- common/frame.go | 54 +++--- common/frame_options.go | 76 ++++---- common/helpers.go | 14 +- common/http.go | 22 +-- common/keyboard.go | 6 +- common/keyboard_options.go | 6 +- common/layout.go | 10 +- common/locator.go | 42 ++--- common/mouse.go | 16 +- common/mouse_options.go | 18 +- common/network_manager.go | 8 +- common/page.go | 64 +++---- common/page_options.go | 14 +- go.mod | 5 +- go.sum | 36 +--- k6ext/context.go | 4 +- k6ext/k6test/vu.go | 6 +- k6ext/panic.go | 8 +- k6ext/promise.go | 10 +- tests/locator_test.go | 6 +- tests/page_test.go | 14 +- tests/setinputfiles_test.go | 30 +-- tests/test_browser.go | 10 +- tests/tracing_test.go | 8 +- 46 files changed, 527 insertions(+), 550 deletions(-) diff --git a/browser/browser_context_mapping.go b/browser/browser_context_mapping.go index b7bb9e190..9ba8c7054 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" @@ -16,7 +16,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin rt := vu.Runtime() return mapping{ "addCookies": bc.AddCookies, - "addInitScript": func(script goja.Value) error { + "addInitScript": func(script sobek.Value) error { if !gojaValueExists(script) { return nil } @@ -25,7 +25,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" { @@ -33,7 +33,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 { @@ -48,7 +48,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin "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 mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin "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 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) @@ -106,7 +106,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() diff --git a/browser/browser_mapping.go b/browser/browser_mapping.go index f2cfc7640..0cd7ebb29 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" ) @@ -33,7 +33,7 @@ func mapBrowser(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 @@ -65,7 +65,7 @@ func mapBrowser(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/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 31b1c9712..85d45d7cc 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" @@ -17,7 +17,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: 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()) @@ -38,7 +38,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return mapFrame(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, @@ -62,7 +62,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: return mapFrame(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()) @@ -83,7 +83,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: "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) @@ -96,7 +96,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint: "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/frame_mapping.go b/browser/frame_mapping.go index 60b41b194..b3e001d14 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" @@ -16,7 +16,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop rt := vu.Runtime() maps := mapping{ "check": f.Check, - "childFrames": func() *goja.Object { + "childFrames": func() *sobek.Object { var ( mcfs []mapping cfs = f.ChildFrames() @@ -26,7 +26,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop } 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 @@ -39,17 +39,17 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop }, "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 { + "evaluate": func(pageFunction sobek.Value, gargs ...sobek.Value) any { return f.Evaluate(pageFunction.String(), exportArgs(gargs)...) }, - "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 @@ -66,7 +66,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop return mapElementHandle(vu, fe), nil }, "getAttribute": f.GetAttribute, - "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(), @@ -94,16 +94,16 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop "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 := mapLocator(vu, f.Locator(selector, opts)) return rt.ToValue(ml).ToObject(rt) }, "name": f.Name, - "page": func() *goja.Object { + "page": func() *sobek.Object { mp := mapPage(vu, f.Page()) return rt.ToValue(mp).ToObject(rt) }, - "parentFrame": func() *goja.Object { + "parentFrame": func() *sobek.Object { mf := mapFrame(vu, f.ParentFrame()) return rt.ToValue(mf).ToObject(rt) }, @@ -111,7 +111,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop "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) @@ -125,7 +125,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop "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..., ) @@ -138,7 +138,7 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { //nolint:gocognit,cyclop }), 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) @@ -152,7 +152,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) (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/helpers.go b/browser/helpers.go index 47375281f..5799be266 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,7 +18,7 @@ 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 { +func exportArg(gv sobek.Value) any { if !gojaValueExists(gv) { return nil } @@ -26,7 +26,7 @@ func exportArg(gv goja.Value) any { } // exportArgs returns a slice of exported Goja values. -func exportArgs(gargs []goja.Value) []any { +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 @@ -38,6 +38,6 @@ func exportArgs(gargs []goja.Value) []any { // 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) +func gojaValueExists(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 a5a11389d..f16b079d4 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" ) @@ -10,19 +10,19 @@ import ( func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { rt := vu.Runtime() return mapping{ - "asElement": func() *goja.Object { + "asElement": func() *sobek.Object { m := mapElementHandle(vu, jsh.AsElement()) return rt.ToValue(m).ToObject(rt) }, "dispose": jsh.Dispose, - "evaluate": func(pageFunc goja.Value, gargs ...goja.Value) any { + "evaluate": func(pageFunc sobek.Value, gargs ...sobek.Value) any { args := make([]any, 0, len(gargs)) for _, a := range gargs { args = append(args, exportArg(a)) } return jsh.Evaluate(pageFunc.String(), args...) }, - "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/locator_mapping.go b/browser/locator_mapping.go index 115b669c8..07bb2ff93 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 { 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 mapLocator(vu moduleVU, lo *common.Locator) mapping { 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 @@ -52,7 +52,7 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { "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) @@ -61,7 +61,7 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { 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/mapping.go b/browser/mapping.go index c96cb73ab..9aaed271d 100644 --- a/browser/mapping.go +++ b/browser/mapping.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/grafana/xk6-browser/common" @@ -21,7 +21,7 @@ type mapping = map[string]any // The motivation of this mapping was to support $ and $$ wildcard // methods. // See issue #661 for more details. -func mapBrowserToGoja(vu moduleVU) *goja.Object { +func mapBrowserToGoja(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 316b825b9..6598daf03 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(), @@ -252,8 +252,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 @@ -262,85 +262,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() Close() Cookies(urls ...string) ([]*common.Cookie, error) - GrantPermissions(permissions []string, opts goja.Value) + GrantPermissions(permissions []string, opts sobek.Value) NewPage() (*common.Page, error) Pages() []*common.Page SetDefaultNavigationTimeout(timeout int64) SetDefaultTimeout(timeout int64) - SetGeolocation(geolocation goja.Value) - SetHTTPCredentials(httpCredentials goja.Value) + SetGeolocation(geolocation sobek.Value) + SetHTTPCredentials(httpCredentials sobek.Value) SetOffline(offline bool) - 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() - Check(selector string, opts goja.Value) - Click(selector string, opts goja.Value) error - Close(opts goja.Value) error + Check(selector string, opts sobek.Value) + Click(selector string, opts sobek.Value) error + Close(opts sobek.Value) error Content() string Context() *common.BrowserContext - Dblclick(selector string, opts goja.Value) - DispatchEvent(selector string, typ string, eventInit goja.Value, opts goja.Value) - EmulateMedia(opts goja.Value) + Dblclick(selector string, opts sobek.Value) + DispatchEvent(selector string, typ string, eventInit sobek.Value, opts sobek.Value) + EmulateMedia(opts sobek.Value) EmulateVisionDeficiency(typ string) - Evaluate(pageFunc goja.Value, arg ...goja.Value) any - EvaluateHandle(pageFunc goja.Value, arg ...goja.Value) (common.JSHandleAPI, error) - Fill(selector string, value string, opts goja.Value) - Focus(selector string, opts goja.Value) + Evaluate(pageFunc sobek.Value, arg ...sobek.Value) any + EvaluateHandle(pageFunc sobek.Value, arg ...sobek.Value) (common.JSHandleAPI, error) + Fill(selector string, value string, opts sobek.Value) + Focus(selector string, opts sobek.Value) Frames() []*common.Frame - GetAttribute(selector string, name string, opts goja.Value) goja.Value + GetAttribute(selector string, name string, opts sobek.Value) sobek.Value GetKeyboard() *common.Keyboard GetMouse() *common.Mouse GetTouchscreen() *common.Touchscreen - Goto(url string, opts goja.Value) (*common.Response, error) - Hover(selector string, opts goja.Value) - InnerHTML(selector string, opts goja.Value) string - InnerText(selector string, opts goja.Value) string - InputValue(selector string, opts goja.Value) string - IsChecked(selector string, opts goja.Value) bool + Goto(url string, opts sobek.Value) (*common.Response, error) + Hover(selector string, opts sobek.Value) + InnerHTML(selector string, opts sobek.Value) string + InnerText(selector string, opts sobek.Value) string + InputValue(selector string, opts sobek.Value) string + IsChecked(selector string, opts sobek.Value) bool IsClosed() bool - IsDisabled(selector string, opts goja.Value) bool - IsEditable(selector string, opts goja.Value) bool - IsEnabled(selector string, opts goja.Value) bool - IsHidden(selector string, opts goja.Value) bool - IsVisible(selector string, opts goja.Value) bool - Locator(selector string, opts goja.Value) *common.Locator + IsDisabled(selector string, opts sobek.Value) bool + IsEditable(selector string, opts sobek.Value) bool + IsEnabled(selector string, opts sobek.Value) bool + IsHidden(selector string, opts sobek.Value) bool + IsVisible(selector string, opts sobek.Value) bool + 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) + Press(selector string, key string, opts sobek.Value) Query(selector string) (*common.ElementHandle, error) QueryAll(selector string) ([]*common.ElementHandle, error) - Reload(opts goja.Value) *common.Response - Screenshot(opts goja.Value) goja.ArrayBuffer - SelectOption(selector string, values goja.Value, opts goja.Value) []string - SetContent(html string, opts goja.Value) + Reload(opts sobek.Value) *common.Response + Screenshot(opts sobek.Value) sobek.ArrayBuffer + SelectOption(selector string, values sobek.Value, opts sobek.Value) []string + SetContent(html string, opts sobek.Value) SetDefaultNavigationTimeout(timeout int64) SetDefaultTimeout(timeout int64) SetExtraHTTPHeaders(headers map[string]string) - SetInputFiles(selector string, files goja.Value, opts goja.Value) - SetViewportSize(viewportSize goja.Value) - Tap(selector string, opts goja.Value) (*goja.Promise, error) - TextContent(selector string, opts goja.Value) string + SetInputFiles(selector string, files sobek.Value, opts sobek.Value) + SetViewportSize(viewportSize sobek.Value) + Tap(selector string, opts sobek.Value) (*sobek.Promise, error) + TextContent(selector string, opts sobek.Value) string ThrottleCPU(common.CPUProfile) error ThrottleNetwork(common.NetworkProfile) error Title() string - Type(selector string, text string, opts goja.Value) - Uncheck(selector string, opts goja.Value) + Type(selector string, text string, opts sobek.Value) + Uncheck(selector string, opts sobek.Value) URL() string ViewportSize() map[string]float64 - WaitForFunction(fn, opts goja.Value, args ...goja.Value) (any, error) - WaitForLoadState(state string, opts goja.Value) - 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) + WaitForNavigation(opts sobek.Value) (*common.Response, error) + WaitForSelector(selector string, opts sobek.Value) (*common.ElementHandle, error) WaitForTimeout(timeout int64) Workers() []*common.Worker } @@ -355,54 +355,54 @@ type consoleMessageAPI interface { // frameAPI is the interface of a CDP target frame. type frameAPI interface { - Check(selector string, opts goja.Value) + Check(selector string, opts sobek.Value) ChildFrames() []*common.Frame - Click(selector string, opts goja.Value) error + Click(selector string, opts sobek.Value) error Content() string - Dblclick(selector string, opts goja.Value) - DispatchEvent(selector string, typ string, eventInit goja.Value, opts goja.Value) + Dblclick(selector string, opts sobek.Value) + DispatchEvent(selector string, typ string, eventInit sobek.Value, opts sobek.Value) // 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 - EvaluateHandle(pageFunc goja.Value, args ...goja.Value) (common.JSHandleAPI, error) - Fill(selector string, value string, opts goja.Value) - Focus(selector string, opts goja.Value) + EvaluateWithContext(ctx context.Context, pageFunc sobek.Value, args ...sobek.Value) (any, error) + Evaluate(pageFunc sobek.Value, args ...sobek.Value) any + EvaluateHandle(pageFunc sobek.Value, args ...sobek.Value) (common.JSHandleAPI, error) + Fill(selector string, value string, opts sobek.Value) + Focus(selector string, opts sobek.Value) FrameElement() (*common.ElementHandle, error) - GetAttribute(selector string, name string, opts goja.Value) goja.Value - Goto(url string, opts goja.Value) (*common.Response, error) - Hover(selector string, opts goja.Value) - InnerHTML(selector string, opts goja.Value) string - InnerText(selector string, opts goja.Value) string - InputValue(selector string, opts goja.Value) string - IsChecked(selector string, opts goja.Value) bool + GetAttribute(selector string, name string, opts sobek.Value) sobek.Value + Goto(url string, opts sobek.Value) (*common.Response, error) + Hover(selector string, opts sobek.Value) + InnerHTML(selector string, opts sobek.Value) string + InnerText(selector string, opts sobek.Value) string + InputValue(selector string, opts sobek.Value) string + IsChecked(selector string, opts sobek.Value) bool IsDetached() bool - IsDisabled(selector string, opts goja.Value) bool - IsEditable(selector string, opts goja.Value) bool - IsEnabled(selector string, opts goja.Value) bool - IsHidden(selector string, opts goja.Value) bool - IsVisible(selector string, opts goja.Value) bool + IsDisabled(selector string, opts sobek.Value) bool + IsEditable(selector string, opts sobek.Value) bool + IsEnabled(selector string, opts sobek.Value) bool + IsHidden(selector string, opts sobek.Value) bool + IsVisible(selector string, opts sobek.Value) bool 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) - SelectOption(selector string, values goja.Value, opts goja.Value) []string - SetContent(html string, opts goja.Value) - SetInputFiles(selector string, files goja.Value, opts goja.Value) - Tap(selector string, opts goja.Value) (*goja.Promise, error) - TextContent(selector string, opts goja.Value) string + Press(selector string, key string, opts sobek.Value) + SelectOption(selector string, values sobek.Value, opts sobek.Value) []string + SetContent(html string, opts sobek.Value) + SetInputFiles(selector string, files sobek.Value, opts sobek.Value) + Tap(selector string, opts sobek.Value) (*sobek.Promise, error) + TextContent(selector string, opts sobek.Value) string Title() string - Type(selector string, text string, opts goja.Value) - Uncheck(selector string, opts goja.Value) + Type(selector string, text string, opts sobek.Value) + Uncheck(selector string, opts sobek.Value) URL() string - WaitForFunction(pageFunc, opts goja.Value, args ...goja.Value) (any, error) - WaitForLoadState(state string, opts goja.Value) - 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) + WaitForNavigation(opts sobek.Value) (*common.Response, error) + WaitForSelector(selector string, opts sobek.Value) (*common.ElementHandle, error) WaitForTimeout(timeout int64) } @@ -411,18 +411,18 @@ type elementHandleAPI interface { common.JSHandleAPI BoundingBox() *common.Rect - Check(opts goja.Value) - Click(opts goja.Value) error + Check(opts sobek.Value) + Click(opts sobek.Value) error ContentFrame() (*common.Frame, error) - Dblclick(opts goja.Value) - DispatchEvent(typ string, props goja.Value) - Fill(value string, opts goja.Value) + Dblclick(opts sobek.Value) + DispatchEvent(typ string, props sobek.Value) + Fill(value string, opts sobek.Value) Focus() - GetAttribute(name string) goja.Value - Hover(opts goja.Value) + GetAttribute(name string) sobek.Value + Hover(opts sobek.Value) InnerHTML() string InnerText() string - InputValue(opts goja.Value) string + InputValue(opts sobek.Value) string IsChecked() bool IsDisabled() bool IsEditable() bool @@ -430,54 +430,54 @@ type elementHandleAPI interface { IsHidden() bool IsVisible() bool OwnerFrame() (*common.Frame, error) - Press(key string, opts goja.Value) + Press(key string, opts sobek.Value) Query(selector string) (*common.ElementHandle, error) QueryAll(selector string) ([]*common.ElementHandle, error) - Screenshot(opts goja.Value) goja.ArrayBuffer - ScrollIntoViewIfNeeded(opts goja.Value) - SelectOption(values goja.Value, opts goja.Value) []string - SelectText(opts goja.Value) - SetInputFiles(files goja.Value, opts goja.Value) - Tap(opts goja.Value) (*goja.Promise, error) + Screenshot(opts sobek.Value) sobek.ArrayBuffer + ScrollIntoViewIfNeeded(opts sobek.Value) + SelectOption(values sobek.Value, opts sobek.Value) []string + SelectText(opts sobek.Value) + SetInputFiles(files sobek.Value, opts sobek.Value) + Tap(opts sobek.Value) (*sobek.Promise, error) TextContent() string - Type(text string, opts goja.Value) - Uncheck(opts goja.Value) - WaitForElementState(state string, opts goja.Value) - WaitForSelector(selector string, opts goja.Value) (*common.ElementHandle, error) + Type(text string, opts sobek.Value) + Uncheck(opts sobek.Value) + WaitForElementState(state string, opts sobek.Value) + 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 } // responseAPI is the interface of an HTTP response. type responseAPI interface { AllHeaders() map[string]string - Body() goja.ArrayBuffer + Body() sobek.ArrayBuffer Frame() *common.Frame - HeaderValue(string) goja.Value + HeaderValue(string) sobek.Value HeaderValues(string) []string Headers() map[string]string HeadersArray() []common.HTTPHeader - JSON() goja.Value + JSON() sobek.Value Ok() bool Request() *common.Request - SecurityDetails() goja.Value - ServerAddr() goja.Value + SecurityDetails() sobek.Value + ServerAddr() sobek.Value Size() common.HTTPMessageSize Status() int64 StatusText() string @@ -487,30 +487,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) - Check(opts goja.Value) - Uncheck(opts goja.Value) - IsChecked(opts goja.Value) bool - IsEditable(opts goja.Value) bool - IsEnabled(opts goja.Value) bool - IsDisabled(opts goja.Value) bool - IsVisible(opts goja.Value) bool - IsHidden(opts goja.Value) bool - Fill(value string, opts goja.Value) - Focus(opts goja.Value) - GetAttribute(name string, opts goja.Value) goja.Value - InnerHTML(opts goja.Value) string - InnerText(opts goja.Value) string - TextContent(opts goja.Value) string - InputValue(opts goja.Value) string - SelectOption(values goja.Value, opts goja.Value) []string - Press(key string, opts goja.Value) - Type(text string, opts goja.Value) - Hover(opts goja.Value) - Tap(opts goja.Value) (*goja.Promise, error) - DispatchEvent(typ string, eventInit, opts goja.Value) - WaitFor(opts goja.Value) + Click(opts sobek.Value) error + Dblclick(opts sobek.Value) + Check(opts sobek.Value) + Uncheck(opts sobek.Value) + IsChecked(opts sobek.Value) bool + IsEditable(opts sobek.Value) bool + IsEnabled(opts sobek.Value) bool + IsDisabled(opts sobek.Value) bool + IsVisible(opts sobek.Value) bool + IsHidden(opts sobek.Value) bool + Fill(value string, opts sobek.Value) + Focus(opts sobek.Value) + GetAttribute(name string, opts sobek.Value) sobek.Value + InnerHTML(opts sobek.Value) string + InnerText(opts sobek.Value) string + TextContent(opts sobek.Value) string + InputValue(opts sobek.Value) string + SelectOption(values sobek.Value, opts sobek.Value) []string + Press(key string, opts sobek.Value) + Type(text string, opts sobek.Value) + Hover(opts sobek.Value) + Tap(opts sobek.Value) (*sobek.Promise, error) + DispatchEvent(typ string, eventInit, opts sobek.Value) + WaitFor(opts sobek.Value) } // keyboardAPI is the interface of a keyboard input device. @@ -520,14 +520,14 @@ type locatorAPI interface { type keyboardAPI interface { //nolint: unused Down(key string) InsertText(char string) - Press(key string, opts goja.Value) - Type(text string, opts goja.Value) + Press(key string, opts sobek.Value) + Type(text string, opts sobek.Value) Up(key string) } // touchscreenAPI is the interface of a touchscreen. type touchscreenAPI interface { - Tap(x float64, y float64) *goja.Promise + Tap(x float64, y float64) *sobek.Promise } // mouseAPI is the interface of a mouse input device. @@ -535,12 +535,12 @@ type touchscreenAPI interface { // mapping is not tested using this interface. We use the concrete type // without testing its exported methods. type mouseAPI interface { //nolint: unused - Click(x float64, y float64, opts goja.Value) - DblClick(x float64, y float64, opts goja.Value) - Down(x float64, y float64, opts goja.Value) - Move(x float64, y float64, opts goja.Value) - Up(x float64, y float64, opts goja.Value) - // Wheel(opts goja.Value) + Click(x float64, y float64, opts sobek.Value) + DblClick(x float64, y float64, opts sobek.Value) + Down(x float64, y float64, opts sobek.Value) + Move(x float64, y float64, opts sobek.Value) + Up(x float64, y float64, opts sobek.Value) + // Wheel(opts sobek.Value) } // workerAPI is the interface of a web worker. diff --git a/browser/module.go b/browser/module.go index 821fa06ac..54a8203b9 100644 --- a/browser/module.go +++ b/browser/module.go @@ -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" @@ -43,7 +43,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"` } diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 9b5c06b5b..95b23ffa2 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" @@ -19,7 +19,7 @@ func mapPage(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 @@ -30,7 +30,7 @@ func mapPage(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 @@ -38,7 +38,7 @@ func mapPage(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) @@ -47,10 +47,10 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop }, "emulateMedia": p.EmulateMedia, "emulateVisionDeficiency": p.EmulateVisionDeficiency, - "evaluate": func(pageFunction goja.Value, gargs ...goja.Value) any { + "evaluate": func(pageFunction sobek.Value, gargs ...sobek.Value) any { return p.Evaluate(pageFunction.String(), exportArgs(gargs)...) }, - "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 @@ -59,7 +59,7 @@ func mapPage(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() @@ -70,7 +70,7 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return rt.ToValue(mfrs).ToObject(rt) }, "getAttribute": p.GetAttribute, - "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(), @@ -99,21 +99,21 @@ func mapPage(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 := 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": 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 := 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) { @@ -129,7 +129,7 @@ func mapPage(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 @@ -139,7 +139,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.ArrayBuffer, error) { + "screenshot": func(opts sobek.Value) (*sobek.ArrayBuffer, error) { ctx := vu.Context() popts := common.NewPageScreenshotOptions() @@ -163,7 +163,7 @@ func mapPage(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) @@ -181,7 +181,7 @@ func mapPage(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..., ) @@ -194,7 +194,7 @@ func mapPage(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) @@ -208,7 +208,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) (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 @@ -216,7 +216,7 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return mapElementHandle(vu, eh), nil }, "waitForTimeout": p.WaitForTimeout, - "workers": func() *goja.Object { + "workers": func() *sobek.Object { var mws []mapping for _, w := range p.Workers() { mw := mapWorker(vu, w) @@ -257,7 +257,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) @@ -266,7 +266,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 7932c4646..6514e87ff 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" ) @@ -11,7 +11,7 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { rt := vu.Runtime() maps := mapping{ "allHeaders": r.AllHeaders, - "frame": func() *goja.Object { + "frame": func() *sobek.Object { mf := mapFrame(vu, r.Frame()) return rt.ToValue(mf).ToObject(rt) }, @@ -23,7 +23,7 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { "postData": r.PostData, "postDataBuffer": r.PostDataBuffer, "resourceType": r.ResourceType, - "response": func() *goja.Object { + "response": func() *sobek.Object { mr := mapResponse(vu, r.Response()) return rt.ToValue(mr).ToObject(rt) }, diff --git a/browser/response_mapping.go b/browser/response_mapping.go index c82abb0c2..c09159fd9 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" ) @@ -15,7 +15,7 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { maps := mapping{ "allHeaders": r.AllHeaders, "body": r.Body, - "frame": func() *goja.Object { + "frame": func() *sobek.Object { mf := mapFrame(vu, r.Frame()) return rt.ToValue(mf).ToObject(rt) }, @@ -25,7 +25,7 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { "headersArray": r.HeadersArray, "json": r.JSON, "ok": r.Ok, - "request": func() *goja.Object { + "request": func() *sobek.Object { mr := mapRequest(vu, r.Request()) return rt.ToValue(mr).ToObject(rt) }, 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/common/browser.go b/common/browser.go index 8ac922a68..b588df9a8 100644 --- a/common/browser.go +++ b/common/browser.go @@ -18,7 +18,7 @@ import ( cdpbrowser "github.com/chromedp/cdproto/browser" "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/target" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/gorilla/websocket" ) @@ -570,7 +570,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() @@ -611,7 +611,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 09db5b44d..88f547e04 100644 --- a/common/browser_context.go +++ b/common/browser_context.go @@ -19,7 +19,7 @@ import ( "github.com/chromedp/cdproto/network" "github.com/chromedp/cdproto/storage" "github.com/chromedp/cdproto/target" - "github.com/dop251/goja" + "github.com/grafana/sobek" ) // waitForEventType represents the event types that can be used when working @@ -259,7 +259,7 @@ func (b *BrowserContext) SetDefaultTimeout(timeout int64) { } // SetGeolocation overrides the geo location of the user. -func (b *BrowserContext) SetGeolocation(geolocation goja.Value) { +func (b *BrowserContext) SetGeolocation(geolocation sobek.Value) { b.logger.Debugf("BrowserContext:SetGeolocation", "bctxid:%v", b.id) g := NewGeolocation() @@ -281,7 +281,7 @@ func (b *BrowserContext) SetGeolocation(geolocation goja.Value) { // 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) { +func (b *BrowserContext) SetHTTPCredentials(httpCredentials sobek.Value) { 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..e029c5a82 100644 --- a/common/browser_context_options.go +++ b/common/browser_context_options.go @@ -8,7 +8,7 @@ import ( "github.com/grafana/xk6-browser/k6ext" - "github.com/dop251/goja" + "github.com/grafana/sobek" ) // 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,7 +202,7 @@ 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 { +func (w *WaitForEventOptions) Parse(ctx context.Context, optsOrPredicate sobek.Value) error { if !gojaValueExists(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") } @@ -244,7 +244,7 @@ func NewGrantPermissionsOptions() *GrantPermissionsOptions { } // Parse parses the options from opts if opts exists in the Goja runtime. -func (g *GrantPermissionsOptions) Parse(ctx context.Context, opts goja.Value) { +func (g *GrantPermissionsOptions) Parse(ctx context.Context, opts sobek.Value) { rt := k6ext.Runtime(ctx) if gojaValueExists(opts) { diff --git a/common/connection.go b/common/connection.go index d8e1923c4..4b0c528e7 100644 --- a/common/connection.go +++ b/common/connection.go @@ -16,7 +16,7 @@ import ( "github.com/chromedp/cdproto/cdp" cdpruntime "github.com/chromedp/cdproto/runtime" "github.com/chromedp/cdproto/target" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/gorilla/websocket" "github.com/mailru/easyjson" "github.com/mailru/easyjson/jlexer" @@ -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 5eebcb6d8..258849a6b 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" @@ -468,9 +468,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 } @@ -489,7 +489,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() { @@ -514,7 +514,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() { @@ -748,7 +748,7 @@ func (h *ElementHandle) ContentFrame() (*Frame, error) { return frame, nil } -func (h *ElementHandle) Dblclick(opts goja.Value) { +func (h *ElementHandle) Dblclick(opts sobek.Value) { actionOpts := NewElementHandleDblclickOptions(h.defaultTimeout()) if err := actionOpts.Parse(h.ctx, opts); err != nil { k6ext.Panic(h.ctx, "parsing element double click options: %w", err) @@ -781,7 +781,7 @@ func (h *ElementHandle) DispatchEvent(typ string, eventInit any) error { return nil } -func (h *ElementHandle) Fill(value string, opts goja.Value) { +func (h *ElementHandle) Fill(value string, opts sobek.Value) { actionOpts := NewElementHandleBaseOptions(h.defaultTimeout()) if err := actionOpts.Parse(h.ctx, opts); err != nil { k6ext.Panic(h.ctx, "parsing element fill options: %w", err) @@ -831,7 +831,7 @@ func (h *ElementHandle) GetAttribute(name string) any { } // Hover scrolls element into view and hovers over its center point. -func (h *ElementHandle) Hover(opts goja.Value) { +func (h *ElementHandle) Hover(opts sobek.Value) { actionOpts := NewElementHandleHoverOptions(h.defaultTimeout()) if err := actionOpts.Parse(h.ctx, opts); err != nil { k6ext.Panic(h.ctx, "parsing element hover options: %w", err) @@ -883,7 +883,7 @@ func (h *ElementHandle) InnerText() string { return v.(string) //nolint:forcetypeassert } -func (h *ElementHandle) InputValue(opts goja.Value) string { +func (h *ElementHandle) InputValue(opts sobek.Value) string { actionOpts := NewElementHandleBaseOptions(h.defaultTimeout()) if err := actionOpts.Parse(h.ctx, opts); err != nil { k6ext.Panic(h.ctx, "parsing element input value options: %w", err) @@ -1002,7 +1002,7 @@ func (h *ElementHandle) OwnerFrame() (*Frame, error) { return frame, nil } -func (h *ElementHandle) Press(key string, opts goja.Value) { +func (h *ElementHandle) Press(key string, opts sobek.Value) { parsedOpts := NewElementHandlePressOptions(h.defaultTimeout()) if err := parsedOpts.Parse(h.ctx, opts); err != nil { k6ext.Panic(h.ctx, "parsing press %q options: %v", key, err) @@ -1111,7 +1111,7 @@ func (h *ElementHandle) queryAll(selector string, eval evalFunc) ([]*ElementHand } // SetChecked checks or unchecks an element. -func (h *ElementHandle) SetChecked(checked bool, opts goja.Value) { +func (h *ElementHandle) SetChecked(checked bool, opts sobek.Value) { parsedOpts := NewElementHandleSetCheckedOptions(h.defaultTimeout()) err := parsedOpts.Parse(h.ctx, opts) if err != nil { @@ -1131,13 +1131,13 @@ func (h *ElementHandle) SetChecked(checked bool, opts goja.Value) { // 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) { +func (h *ElementHandle) Uncheck(opts sobek.Value) { 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) { +func (h *ElementHandle) Check(opts sobek.Value) { h.SetChecked(true, opts) } @@ -1191,7 +1191,7 @@ func (h *ElementHandle) Screenshot( return buf, err } -func (h *ElementHandle) ScrollIntoViewIfNeeded(opts goja.Value) { +func (h *ElementHandle) ScrollIntoViewIfNeeded(opts sobek.Value) { actionOpts := NewElementHandleBaseOptions(h.defaultTimeout()) if err := actionOpts.Parse(h.ctx, opts); err != nil { k6ext.Panic(h.ctx, "parsing scrollIntoViewIfNeeded options: %w", err) @@ -1203,7 +1203,7 @@ func (h *ElementHandle) ScrollIntoViewIfNeeded(opts goja.Value) { applySlowMo(h.ctx) } -func (h *ElementHandle) SelectOption(values goja.Value, opts goja.Value) []string { +func (h *ElementHandle) SelectOption(values sobek.Value, opts sobek.Value) []string { actionOpts := NewElementHandleBaseOptions(h.defaultTimeout()) if err := actionOpts.Parse(h.ctx, opts); err != nil { k6ext.Panic(h.ctx, "parsing selectOption options: %w", err) @@ -1226,7 +1226,7 @@ func (h *ElementHandle) SelectOption(values goja.Value, opts goja.Value) []strin return returnVal } -func (h *ElementHandle) SelectText(opts goja.Value) { +func (h *ElementHandle) SelectText(opts sobek.Value) { actionOpts := NewElementHandleBaseOptions(h.defaultTimeout()) if err := actionOpts.Parse(h.ctx, opts); err != nil { k6ext.Panic(h.ctx, "parsing selectText options: %w", err) @@ -1243,7 +1243,7 @@ func (h *ElementHandle) SelectText(opts goja.Value) { } // 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 { actionOpts := NewElementHandleSetInputFilesOptions(h.defaultTimeout()) if err := actionOpts.Parse(h.ctx, opts); err != nil { return fmt.Errorf("parsing setInputFiles options: %w", err) @@ -1336,7 +1336,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) { +func (h *ElementHandle) Type(text string, opts sobek.Value) { parsedOpts := NewElementHandleTypeOptions(h.defaultTimeout()) if err := parsedOpts.Parse(h.ctx, opts); err != nil { k6ext.Panic(h.ctx, "parsing type options: %v", err) @@ -1352,7 +1352,7 @@ func (h *ElementHandle) Type(text string, opts goja.Value) { applySlowMo(h.ctx) } -func (h *ElementHandle) WaitForElementState(state string, opts goja.Value) { +func (h *ElementHandle) WaitForElementState(state string, opts sobek.Value) { parsedOpts := NewElementHandleWaitForElementStateOptions(h.defaultTimeout()) err := parsedOpts.Parse(h.ctx, opts) if err != nil { @@ -1365,7 +1365,7 @@ func (h *ElementHandle) WaitForElementState(state string, opts goja.Value) { } // 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..bdaa648ef 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,7 +135,7 @@ func NewElementHandleBaseOptions(defaultTimeout time.Duration) *ElementHandleBas } } -func (o *ElementHandleBaseOptions) Parse(ctx context.Context, opts goja.Value) error { +func (o *ElementHandleBaseOptions) Parse(ctx context.Context, opts sobek.Value) error { if !gojaValueExists(opts) { return nil } @@ -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,7 +204,7 @@ 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 { +func (f *Files) addFile(ctx context.Context, file sobek.Value) error { if !gojaValueExists(file) { return nil } @@ -224,8 +224,8 @@ 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) { 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..56cc222d5 100644 --- a/common/execution_context.go +++ b/common/execution_context.go @@ -158,7 +158,7 @@ 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") + return nil, errors.New("sobek.Value escaped") } e.logger.Debugf( "ExecutionContext:eval", @@ -300,7 +300,7 @@ func (e *ExecutionContext) getInjectedScript(apiCtx context.Context) (JSHandleAP // 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") + return nil, errors.New("sobek.Value escaped") } opts := evalOptions{ forceCallable: true, @@ -318,7 +318,7 @@ func (e *ExecutionContext) Eval(apiCtx context.Context, js string, args ...any) // 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") + return nil, errors.New("sobek.Value escaped") } opts := evalOptions{ forceCallable: true, diff --git a/common/frame.go b/common/frame.go index 2bd95ca15..593389ddd 100644 --- a/common/frame.go +++ b/common/frame.go @@ -17,7 +17,7 @@ import ( "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/network" "github.com/chromedp/cdproto/runtime" - "github.com/dop251/goja" + "github.com/grafana/sobek" ) // maxRetry controls how many times to retry if an action fails. @@ -604,7 +604,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) { +func (f *Frame) Check(selector string, opts sobek.Value) { f.log.Debugf("Frame:Check", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameCheckOptions(f.defaultTimeout()) @@ -632,7 +632,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) { +func (f *Frame) Uncheck(selector string, opts sobek.Value) { f.log.Debugf("Frame:Uncheck", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameUncheckOptions(f.defaultTimeout()) @@ -661,7 +661,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 { +func (f *Frame) IsChecked(selector string, opts sobek.Value) bool { f.log.Debugf("Frame:IsChecked", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsCheckedOptions(f.defaultTimeout()) @@ -721,7 +721,7 @@ func (f *Frame) Content() string { } // Dblclick double clicks an element matching provided selector. -func (f *Frame) Dblclick(selector string, opts goja.Value) { +func (f *Frame) Dblclick(selector string, opts sobek.Value) { f.log.Debugf("Frame:DblClick", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameDblClickOptions(f.defaultTimeout()) @@ -861,7 +861,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) { +func (f *Frame) Fill(selector, value string, opts sobek.Value) { f.log.Debugf("Frame:Fill", "fid:%s furl:%q sel:%q val:%q", f.ID(), f.URL(), selector, value) popts := NewFrameFillOptions(f.defaultTimeout()) @@ -891,7 +891,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) { +func (f *Frame) Focus(selector string, opts sobek.Value) { f.log.Debugf("Frame:Focus", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameBaseOptions(f.defaultTimeout()) @@ -931,7 +931,7 @@ func (f *Frame) FrameElement() (*ElementHandle, error) { } // GetAttribute of the first element found that matches the selector. -func (f *Frame) GetAttribute(selector, name string, opts goja.Value) any { +func (f *Frame) GetAttribute(selector, name string, opts sobek.Value) any { f.log.Debugf("Frame:GetAttribute", "fid:%s furl:%q sel:%q name:%s", f.ID(), f.URL(), selector, name) popts := NewFrameBaseOptions(f.defaultTimeout()) @@ -996,7 +996,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) { +func (f *Frame) Hover(selector string, opts sobek.Value) { f.log.Debugf("Frame:Hover", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameHoverOptions(f.defaultTimeout()) @@ -1026,7 +1026,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 { +func (f *Frame) InnerHTML(selector string, opts sobek.Value) string { f.log.Debugf("Frame:InnerHTML", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameInnerHTMLOptions(f.defaultTimeout()) @@ -1068,7 +1068,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 { +func (f *Frame) InnerText(selector string, opts sobek.Value) string { f.log.Debugf("Frame:InnerText", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameInnerTextOptions(f.defaultTimeout()) @@ -1110,7 +1110,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 { +func (f *Frame) InputValue(selector string, opts sobek.Value) string { f.log.Debugf("Frame:InputValue", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameInputValueOptions(f.defaultTimeout()) @@ -1163,7 +1163,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 { +func (f *Frame) IsEditable(selector string, opts sobek.Value) bool { f.log.Debugf("Frame:IsEditable", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsEditableOptions(f.defaultTimeout()) @@ -1204,7 +1204,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 { +func (f *Frame) IsEnabled(selector string, opts sobek.Value) bool { f.log.Debugf("Frame:IsEnabled", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsEnabledOptions(f.defaultTimeout()) @@ -1245,7 +1245,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 { +func (f *Frame) IsDisabled(selector string, opts sobek.Value) bool { f.log.Debugf("Frame:IsDisabled", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameIsDisabledOptions(f.defaultTimeout()) @@ -1286,7 +1286,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() @@ -1319,7 +1319,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() @@ -1359,7 +1359,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) @@ -1415,7 +1415,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) { +func (f *Frame) Press(selector, key string, opts sobek.Value) { f.log.Debugf("Frame:Press", "fid:%s furl:%q sel:%q key:%q", f.ID(), f.URL(), selector, key) popts := NewFramePressOptions(f.defaultTimeout()) @@ -1446,7 +1446,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 { +func (f *Frame) SelectOption(selector string, values sobek.Value, opts sobek.Value) []string { f.log.Debugf("Frame:SelectOption", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameSelectOptionOptions(f.defaultTimeout()) @@ -1463,7 +1463,7 @@ func (f *Frame) SelectOption(selector string, values goja.Value, opts goja.Value return v } -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) } @@ -1504,7 +1504,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) { +func (f *Frame) SetContent(html string, opts sobek.Value) { f.log.Debugf("Frame:SetContent", "fid:%s furl:%q", f.ID(), f.URL()) parsedOpts := NewFrameSetContentOptions( @@ -1535,7 +1535,7 @@ func (f *Frame) SetContent(html string, opts goja.Value) { } // 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()) @@ -1603,7 +1603,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. -func (f *Frame) TextContent(selector string, opts goja.Value) string { +func (f *Frame) TextContent(selector string, opts sobek.Value) string { f.log.Debugf("Frame:TextContent", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) popts := NewFrameTextContentOptions(f.defaultTimeout()) @@ -1661,7 +1661,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) { +func (f *Frame) Type(selector, text string, opts sobek.Value) { f.log.Debugf("Frame:Type", "fid:%s furl:%q sel:%q text:%q", f.ID(), f.URL(), selector, text) popts := NewFrameTypeOptions(f.defaultTimeout()) @@ -1792,7 +1792,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) { +func (f *Frame) WaitForLoadState(state string, opts sobek.Value) { 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) @@ -1922,7 +1922,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/helpers.go b/common/helpers.go index 4bf49a442..d29790641 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" ) @@ -37,7 +37,7 @@ func convertArgument( ctx context.Context, execCtx *ExecutionContext, arg any, ) (*cdpruntime.CallArgument, error) { if escapesGojaValues(arg) { - return nil, errors.New("goja.Value escaped") + return nil, errors.New("sobek.Value escaped") } switch a := arg.(type) { case int64: @@ -222,14 +222,14 @@ func TrimQuotes(s string) string { // 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) +func gojaValueExists(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) +func asGojaValue(ctx context.Context, v any) sobek.Value { + gv, ok := v.(sobek.Value) if !ok { k6ext.Panic(ctx, "unexpected type %T", v) } @@ -257,7 +257,7 @@ func convert[T any](from any, to *T) error { // business logic works. func escapesGojaValues(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 20f5b7655..31ba459e8 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) } @@ -225,7 +225,7 @@ func (r *Request) PostData() string { } // PostDataBuffer returns the request post data as an ArrayBuffer. -func (r *Request) PostDataBuffer() goja.ArrayBuffer { +func (r *Request) PostDataBuffer() sobek.ArrayBuffer { rt := r.vu.Runtime() return rt.NewArrayBuffer([]byte(r.postData)) } @@ -249,7 +249,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"` @@ -420,7 +420,7 @@ func (r *Response) AllHeaders() map[string]string { } // Body returns the response body as a binary buffer. -func (r *Response) Body() goja.ArrayBuffer { +func (r *Response) Body() sobek.ArrayBuffer { if r.status >= 300 && r.status <= 399 { k6ext.Panic(r.ctx, "Response body is unavailable for redirect responses") } @@ -457,11 +457,11 @@ func (r *Response) Frame() *Frame { } // HeaderValue returns the value of the given header. -func (r *Response) HeaderValue(name string) goja.Value { +func (r *Response) HeaderValue(name string) sobek.Value { headers := r.AllHeaders() val, ok := headers[name] if !ok { - return goja.Null() + return sobek.Null() } rt := r.vu.Runtime() return rt.ToValue(val) @@ -509,7 +509,7 @@ func (r *Response) HeadersArray() []HTTPHeader { } // JSON returns the response body as JSON data. -func (r *Response) JSON() goja.Value { +func (r *Response) JSON() sobek.Value { if r.cachedJSON == nil { if err := r.fetchBody(); err != nil { k6ext.Panic(r.ctx, "getting response body: %w", err) @@ -542,13 +542,13 @@ func (r *Response) Request() *Request { } // SecurityDetails returns the security details of the response. -func (r *Response) SecurityDetails() goja.Value { +func (r *Response) SecurityDetails() sobek.Value { rt := r.vu.Runtime() return rt.ToValue(r.securityDetails) } // ServerAddr returns the remote address of the server. -func (r *Response) ServerAddr() goja.Value { +func (r *Response) ServerAddr() sobek.Value { rt := r.vu.Runtime() return rt.ToValue(r.remoteAddress) } diff --git a/common/keyboard.go b/common/keyboard.go index 50735de58..0b5840367 100644 --- a/common/keyboard.go +++ b/common/keyboard.go @@ -11,7 +11,7 @@ import ( "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/input" - "github.com/dop251/goja" + "github.com/grafana/sobek" ) const ( @@ -61,7 +61,7 @@ func (k *Keyboard) Up(key string) { // 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) { +func (k *Keyboard) Press(key string, opts sobek.Value) { kbdOpts := NewKeyboardOptions() if err := kbdOpts.Parse(k.ctx, opts); err != nil { k6ext.Panic(k.ctx, "parsing keyboard options: %w", err) @@ -84,7 +84,7 @@ func (k *Keyboard) InsertText(text string) { // // 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) { +func (k *Keyboard) Type(text string, opts sobek.Value) { kbdOpts := NewKeyboardOptions() if err := kbdOpts.Parse(k.ctx, opts); err != nil { k6ext.Panic(k.ctx, "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..b4f2a7e34 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" ) @@ -53,9 +53,9 @@ 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 { +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 { @@ -81,9 +81,9 @@ type Viewport struct { } // Parse viewport details from a given goja viewport value. -func (v *Viewport) Parse(ctx context.Context, viewport goja.Value) error { +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 acc1b6fdd..f2a1535a9 100644 --- a/common/locator.go +++ b/common/locator.go @@ -8,7 +8,7 @@ import ( "github.com/grafana/xk6-browser/k6ext" "github.com/grafana/xk6-browser/log" - "github.com/dop251/goja" + "github.com/grafana/sobek" ) // Strict mode: @@ -82,7 +82,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) { +func (l *Locator) Dblclick(opts sobek.Value) { l.log.Debugf("Locator:Dblclick", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) var err error @@ -107,7 +107,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) { +func (l *Locator) Check(opts sobek.Value) { l.log.Debugf("Locator:Check", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) var err error @@ -132,7 +132,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) { +func (l *Locator) Uncheck(opts sobek.Value) { l.log.Debugf("Locator:Uncheck", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) var err error @@ -158,7 +158,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 { +func (l *Locator) IsChecked(opts sobek.Value) bool { 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()) @@ -182,7 +182,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 { +func (l *Locator) IsEditable(opts sobek.Value) bool { 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()) @@ -206,7 +206,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 { +func (l *Locator) IsEnabled(opts sobek.Value) bool { 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()) @@ -230,7 +230,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 { +func (l *Locator) IsDisabled(opts sobek.Value) bool { 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()) @@ -279,7 +279,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) { +func (l *Locator) Fill(value string, opts sobek.Value) { 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, @@ -305,7 +305,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) { +func (l *Locator) Focus(opts sobek.Value) { l.log.Debugf("Locator:Focus", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) var err error @@ -328,7 +328,7 @@ func (l *Locator) focus(opts *FrameBaseOptions) error { } // GetAttribute of the element using locator's selector with strict mode on. -func (l *Locator) GetAttribute(name string, opts goja.Value) any { +func (l *Locator) GetAttribute(name string, opts sobek.Value) any { 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, @@ -358,7 +358,7 @@ func (l *Locator) getAttribute(name string, opts *FrameBaseOptions) (any, error) // 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 { +func (l *Locator) InnerHTML(opts sobek.Value) string { l.log.Debugf("Locator:InnerHTML", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) var err error @@ -385,7 +385,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 { +func (l *Locator) InnerText(opts sobek.Value) string { l.log.Debugf("Locator:InnerText", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) var err error @@ -412,7 +412,7 @@ func (l *Locator) innerText(opts *FrameInnerTextOptions) (string, error) { // TextContent returns the element's text content that matches // the locator's selector with strict mode on. -func (l *Locator) TextContent(opts goja.Value) string { +func (l *Locator) TextContent(opts sobek.Value) string { l.log.Debugf("Locator:TextContent", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) var err error @@ -439,7 +439,7 @@ func (l *Locator) textContent(opts *FrameTextContentOptions) (string, error) { // 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 { +func (l *Locator) InputValue(opts sobek.Value) string { 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()) @@ -462,7 +462,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 { +func (l *Locator) SelectOption(values sobek.Value, opts sobek.Value) []string { 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()) @@ -477,14 +477,14 @@ func (l *Locator) SelectOption(values goja.Value, opts goja.Value) []string { return v } -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) { +func (l *Locator) Press(key string, opts sobek.Value) { 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, @@ -511,7 +511,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, @@ -543,7 +543,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) { +func (l *Locator) Hover(opts sobek.Value) { l.log.Debugf("Locator:Hover", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) var err error @@ -603,7 +603,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) { +func (l *Locator) WaitFor(opts sobek.Value) { 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 450cc850a..92108bb5d 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" "github.com/grafana/xk6-browser/k6ext" ) @@ -106,7 +106,7 @@ func (m *Mouse) up(opts *MouseDownUpOptions) error { } // 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) { +func (m *Mouse) Click(x float64, y float64, opts sobek.Value) { mouseOpts := NewMouseClickOptions() if err := mouseOpts.Parse(m.ctx, opts); err != nil { k6ext.Panic(m.ctx, "parsing mouse click options: %w", err) @@ -117,7 +117,7 @@ func (m *Mouse) Click(x float64, y float64, opts goja.Value) { } // DblClick will trigger Click twice in quick succession. -func (m *Mouse) DblClick(x float64, y float64, opts goja.Value) { +func (m *Mouse) DblClick(x float64, y float64, opts sobek.Value) { mouseOpts := NewMouseDblClickOptions() if err := mouseOpts.Parse(m.ctx, opts); err != nil { k6ext.Panic(m.ctx, "parsing double click options: %w", err) @@ -128,7 +128,7 @@ func (m *Mouse) DblClick(x float64, y float64, opts goja.Value) { } // Down will trigger a MouseDown event in the browser. -func (m *Mouse) Down(opts goja.Value) { +func (m *Mouse) Down(opts sobek.Value) { mouseOpts := NewMouseDownUpOptions() if err := mouseOpts.Parse(m.ctx, opts); err != nil { k6ext.Panic(m.ctx, "parsing mouse down options: %w", err) @@ -139,7 +139,7 @@ func (m *Mouse) Down(opts goja.Value) { } // Move will trigger a MouseMoved event in the browser. -func (m *Mouse) Move(x float64, y float64, opts goja.Value) { +func (m *Mouse) Move(x float64, y float64, opts sobek.Value) { mouseOpts := NewMouseMoveOptions() if err := mouseOpts.Parse(m.ctx, opts); err != nil { k6ext.Panic(m.ctx, "parsing mouse move options: %w", err) @@ -150,7 +150,7 @@ func (m *Mouse) Move(x float64, y float64, opts goja.Value) { } // Up will trigger a MouseUp event in the browser. -func (m *Mouse) Up(opts goja.Value) { +func (m *Mouse) Up(opts sobek.Value) { mouseOpts := NewMouseDownUpOptions() if err := mouseOpts.Parse(m.ctx, opts); err != nil { k6ext.Panic(m.ctx, "parsing mouse up options: %w", err) @@ -161,11 +161,11 @@ func (m *Mouse) Up(opts goja.Value) { } // Wheel will trigger a MouseWheel event in the browser -/*func (m *Mouse) Wheel(opts goja.Value) { +/*func (m *Mouse) Wheel(opts sobek.Value) { var deltaX float64 = 0.0 var deltaY float64 = 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 { 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 3930eb0b3..c0e67b17d 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. @@ -40,9 +40,9 @@ func NewCredentials() *Credentials { } // Parse credentials details from a given goja credentials value. -func (c *Credentials) Parse(ctx context.Context, credentials goja.Value) error { +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 { @@ -716,7 +716,7 @@ func (m *NetworkManager) Authenticate(credentials *Credentials) { } // 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 39fa13933..822272e2f 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 { @@ -612,14 +612,14 @@ func (p *Page) BringToFront() { } // Check checks an element matching the provided selector. -func (p *Page) Check(selector string, opts goja.Value) { +func (p *Page) Check(selector string, opts sobek.Value) { p.logger.Debugf("Page:Check", "sid:%v selector:%s", p.sessionID(), selector) p.MainFrame().Check(selector, opts) } // Uncheck unchecks an element matching the provided selector. -func (p *Page) Uncheck(selector string, opts goja.Value) { +func (p *Page) Uncheck(selector string, opts sobek.Value) { p.logger.Debugf("Page:Uncheck", "sid:%v selector:%s", p.sessionID(), selector) p.MainFrame().Uncheck(selector, opts) @@ -627,7 +627,7 @@ func (p *Page) Uncheck(selector string, opts goja.Value) { // 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 { +func (p *Page) IsChecked(selector string, opts sobek.Value) bool { p.logger.Debugf("Page:IsChecked", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsChecked(selector, opts) @@ -641,7 +641,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() @@ -699,7 +699,7 @@ func (p *Page) Context() *BrowserContext { } // Dblclick double clicks an element matching provided selector. -func (p *Page) Dblclick(selector string, opts goja.Value) { +func (p *Page) Dblclick(selector string, opts sobek.Value) { p.logger.Debugf("Page:Dblclick", "sid:%v selector:%s", p.sessionID(), selector) p.MainFrame().Dblclick(selector, opts) @@ -712,7 +712,7 @@ func (p *Page) DispatchEvent(selector string, typ string, eventInit any, opts *F return p.MainFrame().DispatchEvent(selector, typ, eventInit, opts) } -func (p *Page) EmulateMedia(opts goja.Value) { +func (p *Page) EmulateMedia(opts sobek.Value) { p.logger.Debugf("Page:EmulateMedia", "sid:%v", p.sessionID()) parsedOpts := NewPageEmulateMediaOptions(p.mediaType, p.colorScheme, p.reducedMotion) @@ -779,13 +779,13 @@ func (p *Page) EvaluateHandle(pageFunc string, args ...any) (JSHandleAPI, error) return h, nil } -func (p *Page) Fill(selector string, value string, opts goja.Value) { +func (p *Page) Fill(selector string, value string, opts sobek.Value) { p.logger.Debugf("Page:Fill", "sid:%v selector:%s", p.sessionID(), selector) p.MainFrame().Fill(selector, value, opts) } -func (p *Page) Focus(selector string, opts goja.Value) { +func (p *Page) Focus(selector string, opts sobek.Value) { p.logger.Debugf("Page:Focus", "sid:%v selector:%s", p.sessionID(), selector) p.MainFrame().Focus(selector, opts) @@ -797,7 +797,7 @@ func (p *Page) Frames() []*Frame { } // GetAttribute returns the attribute value of the element matching the provided selector. -func (p *Page) GetAttribute(selector string, name string, opts goja.Value) any { +func (p *Page) GetAttribute(selector string, name string, opts sobek.Value) any { p.logger.Debugf("Page:GetAttribute", "sid:%v selector:%s name:%s", p.sessionID(), selector, name) @@ -839,25 +839,25 @@ func (p *Page) Goto(url string, opts *FrameGotoOptions) (*Response, error) { return resp, nil } -func (p *Page) Hover(selector string, opts goja.Value) { +func (p *Page) Hover(selector string, opts sobek.Value) { p.logger.Debugf("Page:Hover", "sid:%v selector:%s", p.sessionID(), selector) p.MainFrame().Hover(selector, opts) } -func (p *Page) InnerHTML(selector string, opts goja.Value) string { +func (p *Page) InnerHTML(selector string, opts sobek.Value) string { p.logger.Debugf("Page:InnerHTML", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().InnerHTML(selector, opts) } -func (p *Page) InnerText(selector string, opts goja.Value) string { +func (p *Page) InnerText(selector string, opts sobek.Value) string { p.logger.Debugf("Page:InnerText", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().InnerText(selector, opts) } -func (p *Page) InputValue(selector string, opts goja.Value) string { +func (p *Page) InputValue(selector string, opts sobek.Value) string { p.logger.Debugf("Page:InputValue", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().InputValue(selector, opts) @@ -870,19 +870,19 @@ func (p *Page) IsClosed() bool { return p.closed } -func (p *Page) IsDisabled(selector string, opts goja.Value) bool { +func (p *Page) IsDisabled(selector string, opts sobek.Value) bool { p.logger.Debugf("Page:IsDisabled", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsDisabled(selector, opts) } -func (p *Page) IsEditable(selector string, opts goja.Value) bool { +func (p *Page) IsEditable(selector string, opts sobek.Value) bool { p.logger.Debugf("Page:IsEditable", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsEditable(selector, opts) } -func (p *Page) IsEnabled(selector string, opts goja.Value) bool { +func (p *Page) IsEnabled(selector string, opts sobek.Value) bool { p.logger.Debugf("Page:IsEnabled", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().IsEnabled(selector, opts) @@ -891,7 +891,7 @@ func (p *Page) IsEnabled(selector string, opts goja.Value) bool { // 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) @@ -899,14 +899,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) @@ -964,7 +964,7 @@ func (p *Page) Opener() *Page { return p.opener } -func (p *Page) Press(selector string, key string, opts goja.Value) { +func (p *Page) Press(selector string, key string, opts sobek.Value) { p.logger.Debugf("Page:Press", "sid:%v selector:%s", p.sessionID(), selector) p.MainFrame().Press(selector, key, opts) @@ -985,7 +985,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() @@ -1091,13 +1091,13 @@ func (p *Page) Screenshot(opts *PageScreenshotOptions, sp ScreenshotPersister) ( return buf, err } -func (p *Page) SelectOption(selector string, values goja.Value, opts goja.Value) []string { +func (p *Page) SelectOption(selector string, values sobek.Value, opts sobek.Value) []string { p.logger.Debugf("Page:SelectOption", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().SelectOption(selector, values, opts) } -func (p *Page) SetContent(html string, opts goja.Value) { +func (p *Page) SetContent(html string, opts sobek.Value) { p.logger.Debugf("Page:SetContent", "sid:%v", p.sessionID()) p.MainFrame().SetContent(html, opts) @@ -1126,14 +1126,14 @@ func (p *Page) SetExtraHTTPHeaders(headers map[string]string) { } // 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) { +func (p *Page) SetViewportSize(viewportSize sobek.Value) { p.logger.Debugf("Page:SetViewportSize", "sid:%v", p.sessionID()) s := &Size{} @@ -1153,7 +1153,7 @@ func (p *Page) Tap(selector string, opts *FrameTapOptions) error { return p.MainFrame().Tap(selector, opts) } -func (p *Page) TextContent(selector string, opts goja.Value) string { +func (p *Page) TextContent(selector string, opts sobek.Value) string { p.logger.Debugf("Page:TextContent", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().TextContent(selector, opts) @@ -1208,7 +1208,7 @@ func (p *Page) ThrottleNetwork(networkProfile NetworkProfile) error { return nil } -func (p *Page) Type(selector string, text string, opts goja.Value) { +func (p *Page) Type(selector string, text string, opts sobek.Value) { p.logger.Debugf("Page:Type", "sid:%v selector:%s text:%s", p.sessionID(), selector, text) p.MainFrame().Type(selector, text, opts) @@ -1242,7 +1242,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) { +func (p *Page) WaitForLoadState(state string, opts sobek.Value) { p.logger.Debugf("Page:WaitForLoadState", "sid:%v state:%q", p.sessionID(), state) p.frameManager.MainFrame().WaitForLoadState(state, opts) @@ -1264,7 +1264,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..53cacbc4a 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,14 @@ go 1.20 require ( github.com/chromedp/cdproto v0.0.0-20221023212508-67ada9507fb2 - github.com/dop251/goja v0.0.0-20240220182346-e401ed450204 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.20240606120708-bd114fdbd683 go.opentelemetry.io/otel v1.24.0 go.opentelemetry.io/otel/trace v1.24.0 golang.org/x/net v0.23.0 @@ -29,6 +29,7 @@ require ( github.com/chromedp/sysutil v1.0.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.9.0 // indirect + github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 // indirect github.com/evanw/esbuild v0.21.2 // indirect github.com/fatih/color v1.16.0 // indirect github.com/go-logr/logr v1.4.1 // indirect diff --git a/go.sum b/go.sum index eda3c0ba7..786e3171b 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.20240606120708-bd114fdbd683 h1:ockJVj41NNWzadyC3fvlSMRXT8QYxEzo13tVvE/WBEw= +go.k6.io/k6 v0.51.1-0.20240606120708-bd114fdbd683/go.mod h1:jKW0vrZjFqum5UGRPw/38ks4bYEywYuEo8vMccp/0Nc= 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= @@ -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= @@ -212,9 +194,7 @@ 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= @@ -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..df025ba19 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 @@ -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 b3834d7ef..437bc4786 100644 --- a/k6ext/k6test/vu.go +++ b/k6ext/k6test/vu.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/dop251/goja" + "github.com/grafana/sobek" "github.com/stretchr/testify/require" "gopkg.in/guregu/null.v3" @@ -26,7 +26,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 +// ToGojaValue 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,7 +38,7 @@ type VU struct { } // 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) } +func (v *VU) ToGojaValue(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 diff --git a/k6ext/panic.go b/k6ext/panic.go index 53611c88f..36f1522a4 100644 --- a/k6ext/panic.go +++ b/k6ext/panic.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/dop251/goja" + "github.com/grafana/sobek" "go.k6.io/k6/errext" k6common "go.k6.io/k6/js/common" @@ -19,7 +19,7 @@ import ( // 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/locator_test.go b/tests/locator_test.go index 55718953a..2d4e58e43 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" @@ -266,7 +266,7 @@ func TestLocator(t *testing.T) { }) } - timeout := func(tb *testBrowser) goja.Value { + timeout := func(tb *testBrowser) sobek.Value { return tb.toGojaValue(jsFrameBaseOpts{Timeout: "100"}) } sanityTests := []struct { @@ -455,7 +455,7 @@ func TestLocatorElementState(t *testing.T) { }) } - timeout := func(tb *testBrowser) goja.Value { + timeout := func(tb *testBrowser) sobek.Value { return tb.toGojaValue(jsFrameBaseOpts{Timeout: "100"}) } sanityTests := []struct { diff --git a/tests/page_test.go b/tests/page_test.go index bf1797d0a..867ed1168 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" @@ -197,12 +197,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", @@ -825,7 +825,7 @@ func TestPageWaitForFunction(t *testing.T) { // 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...) @@ -1198,12 +1198,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) } diff --git a/tests/setinputfiles_test.go b/tests/setinputfiles_test.go index 8e309b0a1..d4ced0fb0 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/grafana/xk6-browser/common" @@ -15,8 +15,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, @@ -34,10 +34,10 @@ func TestSetInputFiles(t *testing.T) { ` - defaultTestPage := func(tb *testBrowser, page *common.Page, files goja.Value) error { + defaultTestPage := func(tb *testBrowser, page *common.Page, files sobek.Value) error { return page.SetInputFiles("#upload", files, tb.toGojaValue(nil)) } - defaultTestElementHandle := func(tb *testBrowser, page *common.Page, files goja.Value) error { + defaultTestElementHandle := func(tb *testBrowser, page *common.Page, files sobek.Value) error { handle, err := page.WaitForSelector("#upload", tb.toGojaValue(nil)) assert.NoError(t, err) return handle.SetInputFiles(files, tb.toGojaValue(nil)) @@ -51,7 +51,7 @@ func TestSetInputFiles(t *testing.T) { }{ { name: "set_one_file_with_object", - setup: func(tb *testBrowser) (goja.Value, func()) { + setup: func(tb *testBrowser) (sobek.Value, func()) { return tb.toGojaValue(file{"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}), nil }, tests: []testFn{defaultTestPage, defaultTestElementHandle}, @@ -68,7 +68,7 @@ func TestSetInputFiles(t *testing.T) { }, { name: "set_two_files_with_array_of_objects", - setup: func(tb *testBrowser) (goja.Value, func()) { + setup: func(tb *testBrowser) (sobek.Value, func()) { return tb.toGojaValue( []file{ {"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}, @@ -92,7 +92,7 @@ func TestSetInputFiles(t *testing.T) { }, { name: "set_nil", - setup: func(tb *testBrowser) (goja.Value, func()) { + setup: func(tb *testBrowser) (sobek.Value, func()) { return tb.toGojaValue(nil), nil }, tests: []testFn{defaultTestPage, defaultTestElementHandle}, @@ -105,7 +105,7 @@ func TestSetInputFiles(t *testing.T) { }, { name: "set_invalid_parameter", - setup: func(tb *testBrowser) (goja.Value, func()) { + setup: func(tb *testBrowser) (sobek.Value, func()) { return tb.toGojaValue([]int{12345}), nil }, tests: []testFn{defaultTestPage, defaultTestElementHandle}, @@ -118,14 +118,14 @@ func TestSetInputFiles(t *testing.T) { }, { name: "test_injected_script_notinput", - setup: func(tb *testBrowser) (goja.Value, func()) { + setup: func(tb *testBrowser) (sobek.Value, func()) { return tb.toGojaValue(file{"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}), nil }, tests: []testFn{ - func(tb *testBrowser, page *common.Page, files goja.Value) error { + func(tb *testBrowser, page *common.Page, files sobek.Value) error { return page.SetInputFiles("#button1", files, tb.toGojaValue(nil)) }, - func(tb *testBrowser, page *common.Page, files goja.Value) error { + func(tb *testBrowser, page *common.Page, files sobek.Value) error { handle, err := page.WaitForSelector("#button1", tb.toGojaValue(nil)) assert.NoError(t, err) return handle.SetInputFiles(files, tb.toGojaValue(nil)) @@ -141,14 +141,14 @@ func TestSetInputFiles(t *testing.T) { }, { name: "test_injected_script_notfile", - setup: func(tb *testBrowser) (goja.Value, func()) { + setup: func(tb *testBrowser) (sobek.Value, func()) { return tb.toGojaValue(file{"name": "test.json", "mimetype": "text/json", "buffer": "MDEyMzQ1Njc4OQ=="}), nil }, tests: []testFn{ - func(tb *testBrowser, page *common.Page, files goja.Value) error { + func(tb *testBrowser, page *common.Page, files sobek.Value) error { return page.SetInputFiles("#textinput", files, tb.toGojaValue(nil)) }, - func(tb *testBrowser, page *common.Page, files goja.Value) error { + func(tb *testBrowser, page *common.Page, files sobek.Value) error { handle, err := page.WaitForSelector("#textinput", tb.toGojaValue(nil)) assert.NoError(t, err) return handle.SetInputFiles(files, tb.toGojaValue(nil)) diff --git a/tests/test_browser.go b/tests/test_browser.go index aad479a1a..4241f5496 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) } +func (b *testBrowser) toGojaValue(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) { +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 b0bcb8440..1e706869d 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)