Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround to retry waitFor until it is success or retry count is 0 #1469

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion common/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -563,15 +564,35 @@ 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, 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, retryCount)
}
if strings.Contains(err.Error(), "Cannot find context with specified id") {
return f.waitFor(selector, opts, retryCount)
}
if strings.Contains(err.Error(), "Execution context was destroyed") {
return f.waitFor(selector, opts, retryCount)
}
}

return err
}

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
Loading