diff --git a/browser/mapping.go b/browser/mapping.go index 914c23dba..41f27b81f 100644 --- a/browser/mapping.go +++ b/browser/mapping.go @@ -115,7 +115,6 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { rt := vu.Runtime() maps := mapping{ "allHeaders": r.AllHeaders, - "failure": r.Failure, "frame": func() *goja.Object { mf := mapFrame(vu, r.Frame()) return rt.ToValue(mf).ToObject(rt) @@ -127,16 +126,7 @@ func mapRequest(vu moduleVU, r *common.Request) mapping { "method": r.Method, "postData": r.PostData, "postDataBuffer": r.PostDataBuffer, - "postDataJSON": r.PostDataJSON, - "redirectedFrom": func() *goja.Object { - mr := mapRequest(vu, r.RedirectedFrom()) - return rt.ToValue(mr).ToObject(rt) - }, - "redirectedTo": func() *goja.Object { - mr := mapRequest(vu, r.RedirectedTo()) - return rt.ToValue(mr).ToObject(rt) - }, - "resourceType": r.ResourceType, + "resourceType": r.ResourceType, "response": func() *goja.Object { mr := mapResponse(vu, r.Response()) return rt.ToValue(mr).ToObject(rt) @@ -158,7 +148,6 @@ func mapResponse(vu moduleVU, r *common.Response) mapping { maps := mapping{ "allHeaders": r.AllHeaders, "body": r.Body, - "finished": r.Finished, "frame": func() *goja.Object { mf := mapFrame(vu, r.Frame()) return rt.ToValue(mf).ToObject(rt) @@ -219,13 +208,6 @@ func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping { } return dst, nil }, - "getProperty": func(propertyName string) *goja.Object { - var ( - h = jsh.GetProperty(propertyName) - m = mapJSHandle(vu, h) - ) - return rt.ToValue(m).ToObject(rt) - }, "jsonValue": jsh.JSONValue, } } @@ -364,9 +346,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { func mapFrame(vu moduleVU, f *common.Frame) mapping { rt := vu.Runtime() maps := mapping{ - "addScriptTag": f.AddScriptTag, - "addStyleTag": f.AddStyleTag, - "check": f.Check, + "check": f.Check, "childFrames": func() *goja.Object { var ( mcfs []mapping @@ -564,11 +544,8 @@ func parseWaitForFunctionArgs( func mapPage(vu moduleVU, p *common.Page) mapping { rt := vu.Runtime() maps := mapping{ - "addInitScript": p.AddInitScript, - "addScriptTag": p.AddScriptTag, - "addStyleTag": p.AddStyleTag, - "bringToFront": p.BringToFront, - "check": p.Check, + "bringToFront": p.BringToFront, + "check": p.Check, "click": func(selector string, opts goja.Value) (*goja.Promise, error) { popts, err := parseFrameClickOptions(vu.Context(), opts, p.Timeout()) if err != nil { @@ -595,7 +572,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping { } return p.DispatchEvent(selector, typ, exportArg(eventInit), popts) //nolint:wrapcheck }, - "dragAndDrop": p.DragAndDrop, "emulateMedia": p.EmulateMedia, "emulateVisionDeficiency": p.EmulateVisionDeficiency, "evaluate": func(pageFunction goja.Value, gargs ...goja.Value) any { @@ -608,11 +584,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { } return mapJSHandle(vu, jsh), nil }, - "exposeBinding": p.ExposeBinding, - "exposeFunction": p.ExposeFunction, - "fill": p.Fill, - "focus": p.Focus, - "frame": p.Frame, + "fill": p.Fill, + "focus": p.Focus, "frames": func() *goja.Object { var ( mfrs []mapping @@ -624,13 +597,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping { return rt.ToValue(mfrs).ToObject(rt) }, "getAttribute": p.GetAttribute, - "goBack": func(opts goja.Value) *goja.Promise { - return k6ext.Promise(vu.Context(), func() (any, error) { - resp := p.GoBack(opts) - return mapResponse(vu, resp), nil - }) - }, - "goForward": p.GoForward, "goto": func(url string, opts goja.Value) (*goja.Promise, error) { gopts := common.NewFrameGotoOptions( p.Referrer(), @@ -689,8 +655,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping { return p.On(event, runInTaskQueue) //nolint:wrapcheck }, "opener": p.Opener, - "pause": p.Pause, - "pdf": p.Pdf, "press": p.Press, "reload": func(opts goja.Value) (*goja.Object, error) { resp, err := p.Reload(opts) @@ -702,7 +666,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping { return rt.ToValue(r).ToObject(rt), nil }, - "route": p.Route, "screenshot": func(opts goja.Value) (*goja.ArrayBuffer, error) { ctx := vu.Context() @@ -741,11 +704,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { "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..., @@ -773,8 +733,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping { return mapResponse(vu, resp), nil }), nil }, - "waitForRequest": p.WaitForRequest, - "waitForResponse": p.WaitForResponse, "waitForSelector": func(selector string, opts goja.Value) (mapping, error) { eh, err := p.WaitForSelector(selector, opts) if err != nil { @@ -825,15 +783,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping { // mapWorker to the JS module. func mapWorker(vu moduleVU, w *common.Worker) mapping { return mapping{ - "evaluate": w.Evaluate, - "evaluateHandle": func(pageFunc goja.Value, args ...goja.Value) (mapping, error) { - h, err := w.EvaluateHandle(pageFunc, args...) - if err != nil { - panicIfFatalError(vu.Context(), err) - return nil, err //nolint:wrapcheck - } - return mapJSHandle(vu, h), nil - }, "url": w.URL(), } } @@ -875,31 +824,17 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin "clearPermissions": bc.ClearPermissions, "close": bc.Close, "cookies": bc.Cookies, - "exposeBinding": bc.ExposeBinding, - "exposeFunction": bc.ExposeFunction, "grantPermissions": func(permissions []string, opts goja.Value) error { pOpts := common.NewGrantPermissionsOptions() pOpts.Parse(vu.Context(), opts) return bc.GrantPermissions(permissions, pOpts) //nolint:wrapcheck }, - "newCDPSession": bc.NewCDPSession, - "route": bc.Route, "setDefaultNavigationTimeout": bc.SetDefaultNavigationTimeout, "setDefaultTimeout": bc.SetDefaultTimeout, - "setExtraHTTPHeaders": func(headers map[string]string) *goja.Promise { - ctx := vu.Context() - return k6ext.Promise(ctx, func() (result any, reason error) { - err := bc.SetExtraHTTPHeaders(headers) - panicIfFatalError(ctx, err) - return nil, err //nolint:wrapcheck - }) - }, - "setGeolocation": bc.SetGeolocation, - "setHTTPCredentials": bc.SetHTTPCredentials, //nolint:staticcheck - "setOffline": bc.SetOffline, - "storageState": bc.StorageState, - "unroute": bc.Unroute, + "setGeolocation": bc.SetGeolocation, + "setHTTPCredentials": bc.SetHTTPCredentials, //nolint:staticcheck + "setOffline": bc.SetOffline, "waitForEvent": func(event string, optsOrPredicate goja.Value) (*goja.Promise, error) { ctx := vu.Context() popts := common.NewWaitForEventOptions( diff --git a/browser/mapping_test.go b/browser/mapping_test.go index 7c8951b0a..cd813cfe6 100644 --- a/browser/mapping_test.go +++ b/browser/mapping_test.go @@ -262,29 +262,19 @@ type browserContextAPI interface { ClearPermissions() Close() Cookies(urls ...string) ([]*common.Cookie, error) - ExposeBinding(name string, callback goja.Callable, opts goja.Value) - ExposeFunction(name string, callback goja.Callable) GrantPermissions(permissions []string, opts goja.Value) - NewCDPSession() any NewPage() (*common.Page, error) Pages() []*common.Page - Route(url goja.Value, handler goja.Callable) SetDefaultNavigationTimeout(timeout int64) SetDefaultTimeout(timeout int64) - SetExtraHTTPHeaders(headers map[string]string) error SetGeolocation(geolocation goja.Value) SetHTTPCredentials(httpCredentials goja.Value) SetOffline(offline bool) - StorageState(opts goja.Value) - Unroute(url goja.Value, handler goja.Callable) WaitForEvent(event string, optsOrPredicate goja.Value) (any, error) } // pageAPI is the interface of a single browser tab. type pageAPI interface { - AddInitScript(script goja.Value, arg goja.Value) - AddScriptTag(opts goja.Value) - AddStyleTag(opts goja.Value) BringToFront() Check(selector string, opts goja.Value) Click(selector string, opts goja.Value) error @@ -293,23 +283,17 @@ type pageAPI interface { Context() *common.BrowserContext Dblclick(selector string, opts goja.Value) DispatchEvent(selector string, typ string, eventInit goja.Value, opts goja.Value) - DragAndDrop(source string, target string, opts goja.Value) EmulateMedia(opts goja.Value) EmulateVisionDeficiency(typ string) Evaluate(pageFunc goja.Value, arg ...goja.Value) any EvaluateHandle(pageFunc goja.Value, arg ...goja.Value) (common.JSHandleAPI, error) - ExposeBinding(name string, callback goja.Callable, opts goja.Value) - ExposeFunction(name string, callback goja.Callable) Fill(selector string, value string, opts goja.Value) Focus(selector string, opts goja.Value) - Frame(frameSelector goja.Value) *common.Frame Frames() []*common.Frame GetAttribute(selector string, name string, opts goja.Value) goja.Value GetKeyboard() *common.Keyboard GetMouse() *common.Mouse GetTouchscreen() *common.Touchscreen - GoBack(opts goja.Value) *common.Response - GoForward(opts goja.Value) *common.Response Goto(url string, opts goja.Value) (*common.Response, error) Hover(selector string, opts goja.Value) InnerHTML(selector string, opts goja.Value) string @@ -326,13 +310,10 @@ type pageAPI interface { MainFrame() *common.Frame On(event string, handler func(*common.ConsoleMessage) error) error Opener() pageAPI - Pause() - Pdf(opts goja.Value) []byte Press(selector string, key string, opts goja.Value) Query(selector string) (*common.ElementHandle, error) QueryAll(selector string) ([]*common.ElementHandle, error) Reload(opts goja.Value) *common.Response - Route(url goja.Value, handler goja.Callable) Screenshot(opts goja.Value) goja.ArrayBuffer SelectOption(selector string, values goja.Value, opts goja.Value) []string SetContent(html string, opts goja.Value) @@ -348,16 +329,11 @@ type pageAPI interface { Title() string Type(selector string, text string, opts goja.Value) Uncheck(selector string, opts goja.Value) - Unroute(url goja.Value, handler goja.Callable) URL() string - Video() any ViewportSize() map[string]float64 - WaitForEvent(event string, optsOrPredicate goja.Value) any WaitForFunction(fn, opts goja.Value, args ...goja.Value) (any, error) WaitForLoadState(state string, opts goja.Value) WaitForNavigation(opts goja.Value) (*common.Response, error) - WaitForRequest(urlOrPredicate, opts goja.Value) *common.Request - WaitForResponse(urlOrPredicate, opts goja.Value) *common.Response WaitForSelector(selector string, opts goja.Value) (*common.ElementHandle, error) WaitForTimeout(timeout int64) Workers() []*common.Worker @@ -373,8 +349,6 @@ type consoleMessageAPI interface { // frameAPI is the interface of a CDP target frame. type frameAPI interface { - AddScriptTag(opts goja.Value) - AddStyleTag(opts goja.Value) Check(selector string, opts goja.Value) ChildFrames() []*common.Frame Click(selector string, opts goja.Value) error @@ -469,7 +443,6 @@ type elementHandleAPI interface { // requestAPI is the interface of an HTTP request. type requestAPI interface { AllHeaders() map[string]string - Failure() goja.Value Frame() *common.Frame HeaderValue(string) goja.Value Headers() map[string]string @@ -478,9 +451,6 @@ type requestAPI interface { Method() string PostData() string PostDataBuffer() goja.ArrayBuffer - PostDataJSON() string - RedirectedFrom() requestAPI - RedirectedTo() requestAPI ResourceType() string Response() *common.Response Size() common.HTTPMessageSize @@ -492,7 +462,6 @@ type requestAPI interface { type responseAPI interface { AllHeaders() map[string]string Body() goja.ArrayBuffer - Finished() bool Frame() *common.Frame HeaderValue(string) goja.Value HeaderValues(string) []string @@ -573,7 +542,5 @@ type mouseAPI interface { //nolint: unused // workerAPI is the interface of a web worker. type workerAPI interface { - Evaluate(pageFunc goja.Value, args ...goja.Value) any - EvaluateHandle(pageFunc goja.Value, args ...goja.Value) (common.JSHandleAPI, error) URL() string } diff --git a/chromium/browser_type.go b/chromium/browser_type.go index 6a2e38075..40467fa86 100644 --- a/chromium/browser_type.go +++ b/chromium/browser_type.go @@ -18,11 +18,8 @@ import ( "github.com/grafana/xk6-browser/log" "github.com/grafana/xk6-browser/storage" - k6common "go.k6.io/k6/js/common" k6modules "go.k6.io/k6/js/modules" k6lib "go.k6.io/k6/lib" - - "github.com/dop251/goja" ) // BrowserType provides methods to launch a Chrome browser instance or connect to an existing one. @@ -214,13 +211,6 @@ func (b *BrowserType) tmpdir() string { return dir } -// LaunchPersistentContext launches the browser with persistent storage. -func (b *BrowserType) LaunchPersistentContext(_ string, _ goja.Value) *common.Browser { - rt := b.vu.Runtime() - k6common.Throw(rt, errors.New("BrowserType.LaunchPersistentContext(userDataDir, opts) has not been implemented yet")) - return nil -} - // Name returns the name of this browser type. func (b *BrowserType) Name() string { return "chromium" diff --git a/common/browser_context.go b/common/browser_context.go index d497a87ef..d543d20b3 100644 --- a/common/browser_context.go +++ b/common/browser_context.go @@ -172,16 +172,6 @@ func (b *BrowserContext) Close() { } } -// ExposeBinding is not implemented. -func (b *BrowserContext) ExposeBinding(name string, callback goja.Callable, opts goja.Value) { - k6ext.Panic(b.ctx, "BrowserContext.exposeBinding(name, callback, opts) has not been implemented yet") -} - -// ExposeFunction is not implemented. -func (b *BrowserContext) ExposeFunction(name string, callback goja.Callable) { - k6ext.Panic(b.ctx, "BrowserContext.exposeFunction(name, callback) has not been implemented yet") -} - // GrantPermissions enables the specified permissions, all others will be disabled. func (b *BrowserContext) GrantPermissions(permissions []string, opts *GrantPermissionsOptions) error { b.logger.Debugf("BrowserContext:GrantPermissions", "bctxid:%v", b.id) @@ -221,12 +211,6 @@ func (b *BrowserContext) GrantPermissions(permissions []string, opts *GrantPermi return nil } -// NewCDPSession returns a new CDP session attached to this target. -func (b *BrowserContext) NewCDPSession() any { // TODO: implement - k6ext.Panic(b.ctx, "BrowserContext.newCDPSession() has not been implemented yet") - return nil -} - // NewPage creates a new page inside this browser context. func (b *BrowserContext) NewPage() (*Page, error) { b.logger.Debugf("BrowserContext:NewPage", "bctxid:%v", b.id) @@ -258,11 +242,6 @@ func (b *BrowserContext) Pages() []*Page { return append([]*Page{}, b.browser.getPages()...) } -// Route is not implemented. -func (b *BrowserContext) Route(url goja.Value, handler goja.Callable) { - k6ext.Panic(b.ctx, "BrowserContext.route(url, handler) has not been implemented yet") -} - // SetDefaultNavigationTimeout sets the default navigation timeout in milliseconds. func (b *BrowserContext) SetDefaultNavigationTimeout(timeout int64) { b.logger.Debugf("BrowserContext:SetDefaultNavigationTimeout", "bctxid:%v timeout:%d", b.id, timeout) @@ -277,11 +256,6 @@ func (b *BrowserContext) SetDefaultTimeout(timeout int64) { b.timeoutSettings.setDefaultTimeout(time.Duration(timeout) * time.Millisecond) } -// SetExtraHTTPHeaders is not implemented. -func (b *BrowserContext) SetExtraHTTPHeaders(headers map[string]string) error { - return fmt.Errorf("BrowserContext.setExtraHTTPHeaders(headers) has not been implemented yet: %w", k6error.ErrFatal) -} - // SetGeolocation overrides the geo location of the user. func (b *BrowserContext) SetGeolocation(geolocation goja.Value) { b.logger.Debugf("BrowserContext:SetGeolocation", "bctxid:%v", b.id) @@ -331,16 +305,6 @@ func (b *BrowserContext) SetOffline(offline bool) { } } -// StorageState is not implemented. -func (b *BrowserContext) StorageState(opts goja.Value) { - k6ext.Panic(b.ctx, "BrowserContext.storageState(opts) has not been implemented yet") -} - -// Unroute is not implemented. -func (b *BrowserContext) Unroute(url goja.Value, handler goja.Callable) { - k6ext.Panic(b.ctx, "BrowserContext.unroute(url, handler) has not been implemented yet") -} - // Timeout will return the default timeout or the one set by the user. func (b *BrowserContext) Timeout() time.Duration { return b.timeoutSettings.timeout() diff --git a/common/frame.go b/common/frame.go index b6270c46b..c907be9aa 100644 --- a/common/frame.go +++ b/common/frame.go @@ -543,18 +543,6 @@ func (f *Frame) waitFor(selector string, opts *FrameWaitForSelectorOptions) erro return err } -// AddScriptTag is not implemented. -func (f *Frame) AddScriptTag(opts goja.Value) { - k6ext.Panic(f.ctx, "Frame.AddScriptTag() has not been implemented yet") - applySlowMo(f.ctx) -} - -// AddStyleTag is not implemented. -func (f *Frame) AddStyleTag(opts goja.Value) { - k6ext.Panic(f.ctx, "Frame.AddStyleTag() has not been implemented yet") - applySlowMo(f.ctx) -} - // ChildFrames returns a list of child frames. func (f *Frame) ChildFrames() []*Frame { f.childFramesMu.RLock() diff --git a/common/http.go b/common/http.go index ef8960a58..20f5b7655 100644 --- a/common/http.go +++ b/common/http.go @@ -173,12 +173,6 @@ func (r *Request) AllHeaders() map[string]string { return headers } -// Failure returns the error text if the request failed. -func (r *Request) Failure() goja.Value { - k6ext.Panic(r.ctx, "Request.failure() has not been implemented yet") - return nil -} - // Frame returns the frame within which the request was made. func (r *Request) Frame() *Frame { return r.frame @@ -236,24 +230,6 @@ func (r *Request) PostDataBuffer() goja.ArrayBuffer { return rt.NewArrayBuffer([]byte(r.postData)) } -// PostDataJSON returns the request post data as a JS object. -func (r *Request) PostDataJSON() string { - k6ext.Panic(r.ctx, "Request.postDataJSON() has not been implemented yet") - return "" -} - -// RedirectedFrom returns the request that redirected to this one, if any. -func (r *Request) RedirectedFrom() *Request { - k6ext.Panic(r.ctx, "Request.redirectedFrom() has not been implemented yet") - return nil -} - -// RedirectedTo returns the request that this one redirected to, if any. -func (r *Request) RedirectedTo() *Request { - k6ext.Panic(r.ctx, "Request.redirectedTo() has not been implemented yet") - return nil -} - // ResourceType returns the request resource type. func (r *Request) ResourceType() string { return r.resourceType @@ -475,13 +451,6 @@ func (r *Response) bodySize() int64 { return int64(len(r.body)) } -// Finished waits for response to finish, return error if request failed. -func (r *Response) Finished() bool { - // TODO: should return nil|Error - k6ext.Panic(r.ctx, "Response.finished() has not been implemented yet") - return false -} - // Frame returns the frame within which the response was received. func (r *Response) Frame() *Frame { return r.request.frame diff --git a/common/js_handle.go b/common/js_handle.go index 097ebd476..d9e20e691 100644 --- a/common/js_handle.go +++ b/common/js_handle.go @@ -23,7 +23,6 @@ type JSHandleAPI interface { Evaluate(pageFunc string, args ...any) any EvaluateHandle(pageFunc string, args ...any) (JSHandleAPI, error) GetProperties() (map[string]JSHandleAPI, error) - GetProperty(propertyName string) JSHandleAPI JSONValue() (string, error) ObjectID() cdpruntime.RemoteObjectID } @@ -156,11 +155,6 @@ func (h *BaseJSHandle) getProperties() (map[string]jsHandle, error) { return props, nil } -// GetProperty retreves a single property of the JS handle. -func (h *BaseJSHandle) GetProperty(_ string) JSHandleAPI { - return nil -} - // JSONValue returns a JSON version of this JS handle. func (h *BaseJSHandle) JSONValue() (string, error) { remoteObject := h.remoteObject diff --git a/common/page.go b/common/page.go index 766710b19..3c9074a6a 100644 --- a/common/page.go +++ b/common/page.go @@ -601,21 +601,6 @@ func (p *Page) viewportSize() Size { } } -// AddInitScript adds script to run in all new frames. -func (p *Page) AddInitScript(script goja.Value, arg goja.Value) { - k6ext.Panic(p.ctx, "Page.addInitScript(script, arg) has not been implemented yet") -} - -// AddScriptTag is not implemented. -func (p *Page) AddScriptTag(opts goja.Value) { - k6ext.Panic(p.ctx, "Page.addScriptTag(opts) has not been implemented yet") -} - -// AddStyleTag is not implemented. -func (p *Page) AddStyleTag(opts goja.Value) { - k6ext.Panic(p.ctx, "Page.addStyleTag(opts) has not been implemented yet") -} - // BringToFront activates the browser tab for this page. func (p *Page) BringToFront() { p.logger.Debugf("Page:BringToFront", "sid:%v", p.sessionID()) @@ -723,11 +708,6 @@ func (p *Page) DispatchEvent(selector string, typ string, eventInit any, opts *F return p.MainFrame().DispatchEvent(selector, typ, eventInit, opts) } -// DragAndDrop is not implemented. -func (p *Page) DragAndDrop(source string, target string, opts goja.Value) { - k6ext.Panic(p.ctx, "Page.DragAndDrop(source, target, opts) has not been implemented yet") -} - func (p *Page) EmulateMedia(opts goja.Value) { p.logger.Debugf("Page:EmulateMedia", "sid:%v", p.sessionID()) @@ -795,16 +775,6 @@ func (p *Page) EvaluateHandle(pageFunc string, args ...any) (JSHandleAPI, error) return h, nil } -// ExposeBinding is not implemented. -func (p *Page) ExposeBinding(name string, callback goja.Callable, opts goja.Value) { - k6ext.Panic(p.ctx, "Page.exposeBinding(name, callback) has not been implemented yet") -} - -// ExposeFunction is not implemented. -func (p *Page) ExposeFunction(name string, callback goja.Callable) { - k6ext.Panic(p.ctx, "Page.exposeFunction(name, callback) has not been implemented yet") -} - func (p *Page) Fill(selector string, value string, opts goja.Value) { p.logger.Debugf("Page:Fill", "sid:%v selector:%s", p.sessionID(), selector) @@ -817,12 +787,6 @@ func (p *Page) Focus(selector string, opts goja.Value) { p.MainFrame().Focus(selector, opts) } -// Frame is not implemented. -func (p *Page) Frame(_ goja.Value) *Frame { - k6ext.Panic(p.ctx, "Page.frame(frameSelector) has not been implemented yet") - return nil -} - // Frames returns a list of frames on the page. func (p *Page) Frames() []*Frame { return p.frameManager.Frames() @@ -851,18 +815,6 @@ func (p *Page) GetTouchscreen() *Touchscreen { return p.Touchscreen } -// GoBack is not implemented. -func (p *Page) GoBack(_ goja.Value) *Response { - k6ext.Panic(p.ctx, "Page.goBack(opts) has not been implemented yet") - return nil -} - -// GoForward is not implemented. -func (p *Page) GoForward(_ goja.Value) *Response { - k6ext.Panic(p.ctx, "Page.goForward(opts) has not been implemented yet") - return nil -} - // Goto will navigate the page to the specified URL and return a HTTP response object. func (p *Page) Goto(url string, opts *FrameGotoOptions) (*Response, error) { p.logger.Debugf("Page:Goto", "sid:%v url:%q", p.sessionID(), url) @@ -1002,17 +954,6 @@ func (p *Page) Opener() *Page { return p.opener } -// Pause is not implemented. -func (p *Page) Pause() { - k6ext.Panic(p.ctx, "Page.pause() has not been implemented yet") -} - -// Pdf is not implemented. -func (p *Page) Pdf(opts goja.Value) []byte { - k6ext.Panic(p.ctx, "Page.pdf(opts) has not been implemented yet") - return nil -} - func (p *Page) Press(selector string, key string, opts goja.Value) { p.logger.Debugf("Page:Press", "sid:%v selector:%s", p.sessionID(), selector) @@ -1114,11 +1055,6 @@ func (p *Page) Reload(opts goja.Value) (*Response, error) { //nolint:funlen,cycl return resp, nil } -// Route is not implemented. -func (p *Page) Route(url goja.Value, handler goja.Callable) { - k6ext.Panic(p.ctx, "Page.route(url, handler) has not been implemented yet") -} - // Screenshot will instruct Chrome to save a screenshot of the current page and save it to specified file. func (p *Page) Screenshot(opts *PageScreenshotOptions, sp ScreenshotPersister) ([]byte, error) { spanCtx, span := TraceAPICall(p.ctx, p.targetID.String(), "page.screenshot") @@ -1258,11 +1194,6 @@ func (p *Page) Type(selector string, text string, opts goja.Value) { p.MainFrame().Type(selector, text, opts) } -// Unroute is not implemented. -func (p *Page) Unroute(url goja.Value, handler goja.Callable) { - k6ext.Panic(p.ctx, "Page.unroute(url, handler) has not been implemented yet") -} - // URL returns the location of the page. func (p *Page) URL() string { p.logger.Debugf("Page:URL", "sid:%v", p.sessionID()) @@ -1273,12 +1204,6 @@ func (p *Page) URL() string { return p.Evaluate(v).(string) //nolint:forcetypeassert } -// Video returns information of recorded video. -func (p *Page) Video() any { // TODO: implement - k6ext.Panic(p.ctx, "Page.video() has not been implemented yet") - return nil -} - // ViewportSize will return information on the viewport width and height. func (p *Page) ViewportSize() map[string]float64 { p.logger.Debugf("Page:ViewportSize", "sid:%v", p.sessionID()) @@ -1290,12 +1215,6 @@ func (p *Page) ViewportSize() map[string]float64 { } } -// WaitForEvent waits for the specified event to trigger. -func (p *Page) WaitForEvent(event string, optsOrPredicate goja.Value) any { - k6ext.Panic(p.ctx, "Page.waitForEvent(event, optsOrPredicate) has not been implemented yet") - return nil -} - // WaitForFunction waits for the given predicate to return a truthy value. func (p *Page) WaitForFunction(js string, opts *FrameWaitForFunctionOptions, jsArgs ...any) (any, error) { p.logger.Debugf("Page:WaitForFunction", "sid:%v", p.sessionID()) @@ -1318,18 +1237,6 @@ func (p *Page) WaitForNavigation(opts *FrameWaitForNavigationOptions) (*Response return p.frameManager.MainFrame().WaitForNavigation(opts) } -// WaitForRequest is not implemented. -func (p *Page) WaitForRequest(_, _ goja.Value) *Request { - k6ext.Panic(p.ctx, "Page.waitForRequest(urlOrPredicate, opts) has not been implemented yet") - return nil -} - -// WaitForResponse is not implemented. -func (p *Page) WaitForResponse(_, _ goja.Value) *Response { - k6ext.Panic(p.ctx, "Page.waitForResponse(urlOrPredicate, opts) has not been implemented yet") - return nil -} - // WaitForSelector waits for the given selector to match the waiting criteria. func (p *Page) WaitForSelector(selector string, opts goja.Value) (*ElementHandle, error) { p.logger.Debugf("Page:WaitForSelector", diff --git a/common/worker.go b/common/worker.go index 7b714e659..85140c9b8 100644 --- a/common/worker.go +++ b/common/worker.go @@ -4,14 +4,11 @@ import ( "context" "fmt" - "github.com/grafana/xk6-browser/k6error" - "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/log" "github.com/chromedp/cdproto/network" "github.com/chromedp/cdproto/runtime" "github.com/chromedp/cdproto/target" - "github.com/dop251/goja" ) type Worker struct { @@ -58,18 +55,6 @@ func (w *Worker) initEvents() error { return nil } -// Evaluate evaluates a page function in the context of the web worker. -func (w *Worker) Evaluate(pageFunc goja.Value, args ...goja.Value) any { - // TODO: implement - return nil -} - -// EvaluateHandle evaluates a page function in the context of the web worker and returns a JS handle. -func (w *Worker) EvaluateHandle(_ goja.Value, _ ...goja.Value) (JSHandleAPI, error) { - // TODO: implement - return nil, fmt.Errorf("Worker.EvaluateHandle has not been implemented yet: %w", k6error.ErrFatal) -} - // URL returns the URL of the web worker. func (w *Worker) URL() string { return w.url diff --git a/tests/browser_test.go b/tests/browser_test.go index 0fb42a0b0..8f3f150e0 100644 --- a/tests/browser_test.go +++ b/tests/browser_test.go @@ -18,6 +18,7 @@ import ( "github.com/grafana/xk6-browser/browser" "github.com/grafana/xk6-browser/common" "github.com/grafana/xk6-browser/env" + "github.com/grafana/xk6-browser/k6ext" "github.com/grafana/xk6-browser/k6ext/k6test" ) @@ -278,14 +279,9 @@ func TestMultiBrowserPanic(t *testing.T) { b1 = newTestBrowser(t) b2 = newTestBrowser(t) - bctx, err := b1.NewContext(nil) - require.NoError(t, err) - p1, err := bctx.NewPage() - require.NoError(t, err, "failed to create page #1") - func() { defer func() { _ = recover() }() - p1.GoBack(nil) + k6ext.Panic(b1.ctx, "forcing a panic") }() })