Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Address review comments for #211
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Feb 3, 2022
1 parent 0f5948a commit 1f9c569
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions chromium/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ readLoop:
}

// Allocate starts a new local browser process
func (a *Allocator) Allocate(ctx context.Context, launchOpts *common.LaunchOptions) (_ *common.BrowserProcess, err error) {
func (a *Allocator) Allocate(ctx context.Context, launchOpts *common.LaunchOptions) (_ *common.BrowserProcess, rerr error) {
// Create cancelable context for the browser process
ctx, cancel := context.WithCancel(ctx)
defer func() {
if err != nil {
if rerr != nil {
cancel()
}
}()
Expand Down
2 changes: 1 addition & 1 deletion common/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (b *BrowserContext) SetGeolocation(geolocation goja.Value) {

g := NewGeolocation()
if err := g.Parse(b.ctx, geolocation); err != nil {
k6Throw(b.ctx, "cannot parse geo location: %w", err)
k6Throw(b.ctx, "cannot parse geo location: %v", err)
}

b.opts.Geolocation = g
Expand Down
4 changes: 2 additions & 2 deletions common/element_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,15 +1144,15 @@ func (h *ElementHandle) OwnerFrame() api.Frame {
func (h *ElementHandle) Press(key string, opts goja.Value) {
parsedOpts := NewElementHandlePressOptions(h.defaultTimeout())
if err := parsedOpts.Parse(h.ctx, opts); err != nil {
k6Throw(h.ctx, "cannot parse element handle press options: %w", err)
k6Throw(h.ctx, "cannot parse press options: %v", err)
}
fn := func(apiCtx context.Context, handle *ElementHandle) (interface{}, error) {
return nil, handle.press(apiCtx, key, NewKeyboardOptions())
}
actFn := elementHandleActionFn(h, []string{}, fn, false, parsedOpts.NoWaitAfter, parsedOpts.Timeout)
_, err := callApiWithTimeout(h.ctx, actFn, parsedOpts.Timeout)
if err != nil {
k6Throw(h.ctx, "cannot handle element key (%q) press: %w", key, err)
k6Throw(h.ctx, "cannot handle element key (%q) press: %v", key, err)
}
applySlowMo(h.ctx)
}
Expand Down
4 changes: 2 additions & 2 deletions common/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ func (f *Frame) WaitForLoadState(state string, opts goja.Value) {
parsedOpts := NewFrameWaitForLoadStateOptions(f.defaultTimeout())
err := parsedOpts.Parse(f.ctx, opts)
if err != nil {
k6Throw(f.ctx, "failed parsing wait for load state options: %v", err)
k6Throw(f.ctx, "cannot parse waitForLoadState options: %v", err)
}

waitUntil := LifecycleEventLoad
Expand All @@ -1424,7 +1424,7 @@ func (f *Frame) WaitForLoadState(state string, opts goja.Value) {
return data.(LifecycleEvent) == waitUntil
}, parsedOpts.Timeout)
if err != nil {
k6Throw(f.ctx, "cannot wait for event: %v", err)
k6Throw(f.ctx, "cannot waitForEvent: %v", err)
}
}

Expand Down
6 changes: 3 additions & 3 deletions common/frame_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func (m *FrameManager) WaitForFrameNavigation(frame *Frame, opts goja.Value) api

parsedOpts := NewFrameWaitForNavigationOptions(time.Duration(m.timeoutSettings.timeout()) * time.Second)
if err := parsedOpts.Parse(m.ctx, opts); err != nil {
k6Throw(m.ctx, "wait for frame navigation failed to parse options: %v", err)
k6Throw(m.ctx, "cannot parse waitForNavigation options: %v", err)
}

ch, evCancelFn := createWaitForEventHandler(m.ctx, frame, []string{EventFrameNavigation}, func(data interface{}) bool {
Expand All @@ -716,7 +716,7 @@ func (m *FrameManager) WaitForFrameNavigation(frame *Frame, opts goja.Value) api
m.ID(), frame.URL(), m.ctx.Err())
return nil
case <-time.After(parsedOpts.Timeout):
k6Throw(m.ctx, "wait for frame navigation err: %v", ErrTimedOut)
k6Throw(m.ctx, "waitForFrameNavigation timed out after %s", parsedOpts.Timeout)
case data := <-ch:
event = data.(*NavigationEvent)
}
Expand All @@ -730,7 +730,7 @@ func (m *FrameManager) WaitForFrameNavigation(frame *Frame, opts goja.Value) api
return data.(LifecycleEvent) == parsedOpts.WaitUntil
}, parsedOpts.Timeout)
if err != nil {
k6Throw(m.ctx, "wait for frame navigation err: %v", err)
k6Throw(m.ctx, "waitForFrameNavigation cannot wait for event (EventFrameAddLifecycle): %v", err)
}
}

Expand Down
18 changes: 9 additions & 9 deletions common/frame_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,15 @@ func (fs *FrameSession) initIsolatedWorld(name string) error {
}
for _, frame := range frames {
// A frame could have been removed before we execute this, so don't wait around for a reply.
err := fs.session.ExecuteWithoutExpectationOnReply(fs.ctx, cdppage.CommandCreateIsolatedWorld, &cdppage.CreateIsolatedWorldParams{
FrameID: cdp.FrameID(frame.ID()),
WorldName: name,
GrantUniveralAccess: true,
}, nil)
if err != nil {
return fmt.Errorf("frame session: cannot init isolated world (%q) in frame (%q)",
name, frame.ID())
}
_ = fs.session.ExecuteWithoutExpectationOnReply(
fs.ctx,
cdppage.CommandCreateIsolatedWorld,
&cdppage.CreateIsolatedWorldParams{
FrameID: cdp.FrameID(frame.ID()),
WorldName: name,
GrantUniveralAccess: true,
},
nil)
}

fs.logger.Debugf("NewFrameSession:initIsolatedWorld:AddScriptToEvaluateOnNewDocument",
Expand Down

0 comments on commit 1f9c569

Please sign in to comment.