From 446ffc07e301fb3cf6fdc68cb6497325af0d24de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 18 Apr 2024 11:58:21 +0300 Subject: [PATCH] Degojaify Page|Frame.Tap --- browser/mapping.go | 50 ++++++++++++++++++++++++++++------------------ common/frame.go | 8 ++------ common/page.go | 2 +- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/browser/mapping.go b/browser/mapping.go index d8ef075f7..4b3614480 100644 --- a/browser/mapping.go +++ b/browser/mapping.go @@ -456,12 +456,18 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { "selectOption": f.SelectOption, "setContent": f.SetContent, "setInputFiles": f.SetInputFiles, - "tap": f.Tap, - "textContent": f.TextContent, - "title": f.Title, - "type": f.Type, - "uncheck": f.Uncheck, - "url": f.URL, + "tap": func(selector string, opts goja.Value) error { + popts := common.NewFrameTapOptions(f.Timeout()) + if err := popts.Parse(vu.Context(), opts); err != nil { + return fmt.Errorf("parsing frame tap options: %w", err) + } + return f.Tap(selector, popts) //nolint:wrapcheck + }, + "textContent": f.TextContent, + "title": f.Title, + "type": f.Type, + "uncheck": f.Uncheck, + "url": f.URL, "waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( vu.Context(), f.Timeout(), pageFunc, opts, args..., @@ -709,19 +715,25 @@ func mapPage(vu moduleVU, p *common.Page) mapping { "setExtraHTTPHeaders": p.SetExtraHTTPHeaders, "setInputFiles": p.SetInputFiles, "setViewportSize": p.SetViewportSize, - "tap": p.Tap, - "textContent": p.TextContent, - "throttleCPU": p.ThrottleCPU, - "throttleNetwork": p.ThrottleNetwork, - "title": p.Title, - "touchscreen": rt.ToValue(p.GetTouchscreen()).ToObject(rt), - "type": p.Type, - "uncheck": p.Uncheck, - "unroute": p.Unroute, - "url": p.URL, - "video": p.Video, - "viewportSize": p.ViewportSize, - "waitForEvent": p.WaitForEvent, + "tap": func(selector string, opts goja.Value) error { + popts := common.NewFrameTapOptions(p.Timeout()) + if err := popts.Parse(vu.Context(), opts); err != nil { + return fmt.Errorf("parsing page tap options: %w", err) + } + return p.Tap(selector, popts) //nolint:wrapcheck + }, + "textContent": p.TextContent, + "throttleCPU": p.ThrottleCPU, + "throttleNetwork": p.ThrottleNetwork, + "title": p.Title, + "touchscreen": rt.ToValue(p.GetTouchscreen()).ToObject(rt), + "type": p.Type, + "uncheck": p.Uncheck, + "unroute": p.Unroute, + "url": p.URL, + "video": p.Video, + "viewportSize": p.ViewportSize, + "waitForEvent": p.WaitForEvent, "waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( vu.Context(), p.Timeout(), pageFunc, opts, args..., diff --git a/common/frame.go b/common/frame.go index bd580f03a..b6270c46b 100644 --- a/common/frame.go +++ b/common/frame.go @@ -1549,14 +1549,10 @@ func (f *Frame) SetInputFiles(selector string, files goja.Value, opts goja.Value } // Tap the first element that matches the selector. -func (f *Frame) Tap(selector string, opts goja.Value) error { +func (f *Frame) Tap(selector string, opts *FrameTapOptions) error { f.log.Debugf("Frame:Tap", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) - popts := NewFrameTapOptions(f.defaultTimeout()) - if err := popts.Parse(f.ctx, opts); err != nil { - return fmt.Errorf("parsing tap options: %w", err) - } - if err := f.tap(selector, popts); err != nil { + if err := f.tap(selector, opts); err != nil { return fmt.Errorf("tapping on %q: %w", selector, err) } diff --git a/common/page.go b/common/page.go index 1c93eb17a..db547acbe 100644 --- a/common/page.go +++ b/common/page.go @@ -1191,7 +1191,7 @@ func (p *Page) SetViewportSize(viewportSize goja.Value) { } // Tap will tap the element matching the provided selector. -func (p *Page) Tap(selector string, opts goja.Value) error { +func (p *Page) Tap(selector string, opts *FrameTapOptions) error { p.logger.Debugf("Page:SetViewportSize", "sid:%v selector:%s", p.sessionID(), selector) return p.MainFrame().Tap(selector, opts)