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

Commit 3a1e01b

Browse files
author
Ivan Mirić
authored
Fix concurrent usage of goja.Runtime in waitForNavigation (#508)
* Fix concurrent usage of goja.Runtime in waitForNavigation This is a functional change from before, since the iteration won't be interrupted by a timeout error anymore, and the promise will be rejected instead. This might be an acceptable tradeoff for using a lock, but it would be better if there was a way of interrupting the iteration if the promise is rejected. Fixes #506 * Return all timeout context errors from waitForNavigation promise Resolves #508 (comment) * Move debug log of waitForNavigation timeout done error Partly resolves #508 (comment)
1 parent 67499f7 commit 3a1e01b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

common/frame.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,17 +1849,18 @@ func (f *Frame) WaitForNavigation(opts goja.Value) *goja.Promise {
18491849
return false
18501850
})
18511851

1852-
handleTimeoutError := func(err error) {
1853-
if errors.Is(err, context.DeadlineExceeded) {
1854-
err = &k6ext.UserFriendlyError{
1852+
handleTimeoutError := func(err error) error {
1853+
f.log.Debugf("Frame:WaitForNavigation",
1854+
"fid:%v furl:%s timeoutCtx done: %v", f.ID(), f.URL(), err)
1855+
if err != nil {
1856+
e := &k6ext.UserFriendlyError{
18551857
Err: err,
18561858
Timeout: parsedOpts.Timeout,
18571859
}
1858-
k6ext.Panic(f.ctx, "waiting for navigation: %w", err)
1860+
return fmt.Errorf("waiting for navigation: %w", e)
18591861
}
1860-
f.log.Debugf("Frame:WaitForNavigation",
1861-
"fid:%v furl:%s timeoutCtx done: %v",
1862-
f.ID(), f.URL(), err)
1862+
1863+
return nil
18631864
}
18641865

18651866
return k6ext.Promise(f.ctx, func() (result interface{}, reason error) {
@@ -1889,8 +1890,7 @@ func (f *Frame) WaitForNavigation(opts goja.Value) *goja.Promise {
18891890
}
18901891
}
18911892
case <-timeoutCtx.Done():
1892-
handleTimeoutError(timeoutCtx.Err())
1893-
return nil, nil
1893+
return nil, handleTimeoutError(timeoutCtx.Err())
18941894
}
18951895

18961896
// A lifecycle event won't be received when navigating within the same
@@ -1900,7 +1900,7 @@ func (f *Frame) WaitForNavigation(opts goja.Value) *goja.Promise {
19001900
select {
19011901
case <-lifecycleEvtCh:
19021902
case <-timeoutCtx.Done():
1903-
handleTimeoutError(timeoutCtx.Err())
1903+
return nil, handleTimeoutError(timeoutCtx.Err())
19041904
}
19051905
}
19061906

0 commit comments

Comments
 (0)