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

Commit 9b0423f

Browse files
committed
Use EvaluateWithContext from page.close
Now we can use the EvaluateWithContext from page.close when we call evaluate to hide the page. We're going to rely on the default timeout for now, and refine the timeout if we see this occurring too often -- if we see this occur too often this will affect the test result depending on the default timeout (which is 30 seconds unless overridden by the user).
1 parent bc90dd1 commit 9b0423f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

common/page.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,20 @@ func (p *Page) Close(opts goja.Value) error {
427427

428428
// forcing the pagehide event to trigger web vitals metrics.
429429
v := p.vu.Runtime().ToValue(`() => window.dispatchEvent(new Event('pagehide'))`)
430-
_ = p.Evaluate(v)
430+
ctx, cancel := context.WithTimeout(p.ctx, p.defaultTimeout())
431+
defer cancel()
432+
_, err := p.MainFrame().EvaluateWithContext(ctx, v)
433+
if err != nil {
434+
p.logger.Warnf("Page:Close", "failed to hide page: %v", err)
435+
}
431436

432437
add := runtime.RemoveBinding(webVitalBinding)
433438
if err := add.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil {
434439
return fmt.Errorf("internal error while removing binding from page: %w", err)
435440
}
436441

437442
action := target.CloseTarget(p.targetID)
438-
err := action.Do(cdp.WithExecutor(p.ctx, p.session))
443+
err = action.Do(cdp.WithExecutor(p.ctx, p.session))
439444
if err != nil {
440445
// When a close target command is sent to the browser via CDP,
441446
// the browser will start to cleanup and the first thing it

0 commit comments

Comments
 (0)