Merging changes from ranch/hotfix/navigate-back-and-forward
This commit is contained in:
commit
35dfe7af26
16
nav.go
16
nav.go
|
@ -41,35 +41,31 @@ func NavigateToHistoryEntry(entryID int64) Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NavigateBack navigates the current frame backwards in its history.
|
// NavigateBack navigates the current frame backwards in its history.
|
||||||
func NavigateBack() Action {
|
func NavigateBack(ctxt context.Context, h cdp.Handler) error {
|
||||||
return ActionFunc(func(ctxt context.Context, h cdp.Handler) error {
|
|
||||||
cur, entries, err := page.GetNavigationHistory().Do(ctxt, h)
|
cur, entries, err := page.GetNavigationHistory().Do(ctxt, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cur == 0 {
|
if cur <= 0 || cur > int64(len(entries)-1) {
|
||||||
return errors.New("already on oldest navigation entry")
|
return errors.New("invalid navigation entry")
|
||||||
}
|
}
|
||||||
|
|
||||||
return page.NavigateToHistoryEntry(entries[cur-1].ID).Do(ctxt, h)
|
return page.NavigateToHistoryEntry(entries[cur-1].ID).Do(ctxt, h)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NavigateForward navigates the current frame forwards in its history.
|
// NavigateForward navigates the current frame forwards in its history.
|
||||||
func NavigateForward() Action {
|
func NavigateForward(ctxt context.Context, h cdp.Handler) error {
|
||||||
return ActionFunc(func(ctxt context.Context, h cdp.Handler) error {
|
|
||||||
cur, entries, err := page.GetNavigationHistory().Do(ctxt, h)
|
cur, entries, err := page.GetNavigationHistory().Do(ctxt, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cur == int64(len(entries)-1) {
|
if cur < 0 || cur >= int64(len(entries)-1) {
|
||||||
return errors.New("already on newest navigation entry")
|
return errors.New("invalid navigation entry")
|
||||||
}
|
}
|
||||||
|
|
||||||
return page.NavigateToHistoryEntry(entries[cur+1].ID).Do(ctxt, h)
|
return page.NavigateToHistoryEntry(entries[cur+1].ID).Do(ctxt, h)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop stops all navigation and pending resource retrieval.
|
// Stop stops all navigation and pending resource retrieval.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user