|
6 | 6 | "fmt"
|
7 | 7 | "os"
|
8 | 8 | "sync"
|
9 |
| - "time" |
10 | 9 |
|
11 | 10 | "golang.org/x/exp/slices"
|
12 | 11 | )
|
@@ -543,52 +542,10 @@ func (p *pageImpl) ExpectEvent(event string, cb func() error, options ...PageExp
|
543 | 542 | }
|
544 | 543 |
|
545 | 544 | func (p *pageImpl) ExpectNavigation(cb func() error, options ...PageExpectNavigationOptions) (Response, error) {
|
546 |
| - option := PageExpectNavigationOptions{} |
547 | 545 | if len(options) == 1 {
|
548 |
| - option = options[0] |
549 |
| - } |
550 |
| - if option.WaitUntil == nil { |
551 |
| - option.WaitUntil = WaitUntilStateLoad |
552 |
| - } |
553 |
| - if option.Timeout == nil { |
554 |
| - option.Timeout = Float(p.timeoutSettings.NavigationTimeout()) |
555 |
| - } |
556 |
| - deadline := time.Now().Add(time.Duration(*option.Timeout) * time.Millisecond) |
557 |
| - var matcher *urlMatcher |
558 |
| - if option.URL != nil { |
559 |
| - matcher = newURLMatcher(option.URL, p.browserContext.options.BaseURL) |
560 |
| - } |
561 |
| - predicate := func(events ...interface{}) bool { |
562 |
| - ev := events[0].(map[string]interface{}) |
563 |
| - if ev["error"] != nil { |
564 |
| - print("error") |
565 |
| - } |
566 |
| - return matcher == nil || matcher.Matches(ev["url"].(string)) |
567 |
| - } |
568 |
| - waiter, err := p.mainFrame.(*frameImpl).setNavigationWaiter(option.Timeout) |
569 |
| - if err != nil { |
570 |
| - return nil, err |
571 |
| - } |
572 |
| - |
573 |
| - eventData, err := waiter.WaitForEvent(p.mainFrame.(*frameImpl), "navigated", predicate).RunAndWait(cb) |
574 |
| - if err != nil || eventData == nil { |
575 |
| - return nil, err |
576 |
| - } |
577 |
| - |
578 |
| - t := time.Until(deadline).Milliseconds() |
579 |
| - if t > 0 { |
580 |
| - err = p.mainFrame.(*frameImpl).waitForLoadStateImpl(string(*option.WaitUntil), Float(float64(t)), nil) |
581 |
| - if err != nil { |
582 |
| - return nil, err |
583 |
| - } |
584 |
| - } |
585 |
| - |
586 |
| - event := eventData.(map[string]interface{}) |
587 |
| - if event["newDocument"] != nil && event["newDocument"].(map[string]interface{})["request"] != nil { |
588 |
| - request := fromChannel(event["newDocument"].(map[string]interface{})["request"]).(*requestImpl) |
589 |
| - return request.Response() |
| 546 | + return p.mainFrame.ExpectNavigation(cb, FrameExpectNavigationOptions(options[0])) |
590 | 547 | }
|
591 |
| - return nil, nil |
| 548 | + return p.mainFrame.ExpectNavigation(cb) |
592 | 549 | }
|
593 | 550 |
|
594 | 551 | func (p *pageImpl) ExpectConsoleMessage(cb func() error, options ...PageExpectConsoleMessageOptions) (ConsoleMessage, error) {
|
|
0 commit comments