Skip to content

Commit

Permalink
Add retry count for max waitFor call stack
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Oct 10, 2024
1 parent fa6d966 commit f51abb3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions common/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,27 +564,32 @@ func (f *Frame) waitForSelector(selector string, opts *FrameWaitForSelectorOptio
return handle, nil
}

func (f *Frame) waitFor(selector string, opts *FrameWaitForSelectorOptions) error {
func (f *Frame) waitFor(selector string, opts *FrameWaitForSelectorOptions, retryCount int) error {
f.log.Debugf("Frame:waitFor", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)

retryCount--
if retryCount < 0 {
return errors.New("waitFor retry threshold reached")
}

document, err := f.document()
if err != nil {
if strings.Contains(err.Error(), "Cannot find context with specified id") {
return f.waitFor(selector, opts)
return f.waitFor(selector, opts, retryCount)
}
return err
}

_, err = document.waitForSelector(f.ctx, selector, opts)
if err != nil {
if strings.Contains(err.Error(), "Inspected target navigated or closed") {
return f.waitFor(selector, opts)
return f.waitFor(selector, opts, retryCount)
}
if strings.Contains(err.Error(), "Cannot find context with specified id") {
return f.waitFor(selector, opts)
return f.waitFor(selector, opts, retryCount)
}
if strings.Contains(err.Error(), "Execution context was destroyed") {
return f.waitFor(selector, opts)
return f.waitFor(selector, opts, retryCount)
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/locator.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ func (l *Locator) WaitFor(opts sobek.Value) error {

func (l *Locator) waitFor(opts *FrameWaitForSelectorOptions) error {
opts.Strict = true
return l.frame.waitFor(l.selector, opts)
return l.frame.waitFor(l.selector, opts, 20)
}

// DefaultTimeout returns the default timeout for the locator.
Expand Down

0 comments on commit f51abb3

Please sign in to comment.