Skip to content

Commit

Permalink
Add Referrer and NavigationTimeout to Page
Browse files Browse the repository at this point in the history
- This prevents the train-of-calls issue.
- It might make it easier to navigate within the code for new
  contributors.
  • Loading branch information
inancgumus committed Jan 23, 2024
1 parent 0bbbab5 commit e04f7be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions browser/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
"goForward": p.GoForward,
"goto": func(url string, opts goja.Value) (*goja.Promise, error) {
gopts := common.NewFrameGotoOptions(
p.MainFrame().Referrer(),
p.MainFrame().NavigationTimeout(),
p.Referrer(),
p.NavigationTimeout(),
)
if err := gopts.Parse(vu.Context(), opts); err != nil {
return nil, fmt.Errorf("parsing page navigation options to %q: %w", url, err)
Expand Down
13 changes: 13 additions & 0 deletions common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,19 @@ func (p *Page) MainFrame() *Frame {
return mf
}

// Referrer returns the page's referrer.
// It's an internal method not to be exposed as a JS API.
func (p *Page) Referrer() string {
nm := p.mainFrameSession.getNetworkManager()
return nm.extraHTTPHeaders["referer"]
}

// NavigationTimeout returns the page's navigation timeout.
// It's an internal method not to be exposed as a JS API.
func (p *Page) NavigationTimeout() time.Duration {
return p.frameManager.timeoutSettings.navigationTimeout()
}

// On subscribes to a page event for which the given handler will be executed
// passing in the ConsoleMessage associated with the event.
// The only accepted event value is 'console'.
Expand Down

0 comments on commit e04f7be

Please sign in to comment.