From 982cab91cfa423a6b6a32fedcc57d84ffcb209c6 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Mon, 11 Nov 2024 14:32:42 +0000 Subject: [PATCH] Fix waitForSelector by calling waitFor The fix is in waitFor, and waitForSelector just needs to call waitFor to enable the fix. It basically will auto retry up to 20 times when certain errors are received from chrome. This can happens when the underlying DOM is changing due to a navigation, and the expected element that matches the selector is in the newly navigated DOM. --- common/frame.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/common/frame.go b/common/frame.go index 4e3cbe950..390f85e09 100644 --- a/common/frame.go +++ b/common/frame.go @@ -523,15 +523,16 @@ func (f *Frame) waitForSelectorRetry( return nil, err } +// waitForSelector will wait for the given selector to reach a defined state in +// opts. +// +// It will auto retry on certain errors until the retryCount is below 0. The +// retry workaround is needed since the underlying DOM can change when the +// wait action is performed during a navigation. func (f *Frame) waitForSelector(selector string, opts *FrameWaitForSelectorOptions) (_ *ElementHandle, rerr error) { f.log.Debugf("Frame:waitForSelector", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) - document, err := f.document() - if err != nil { - return nil, err - } - - handle, err := document.waitForSelector(f.ctx, selector, opts) + handle, err := f.waitFor(selector, opts, 20) if err != nil { return nil, err }