diff --git a/nav.go b/nav.go index 13f7c5a..6904e11 100644 --- a/nav.go +++ b/nav.go @@ -41,31 +41,35 @@ func NavigateToHistoryEntry(entryID int64) Action { } // NavigateBack navigates the current frame backwards in its history. -func NavigateBack(ctxt context.Context, h cdp.Handler) error { - cur, entries, err := page.GetNavigationHistory().Do(ctxt, h) - if err != nil { - return err - } +func NavigateBack() Action { + return ActionFunc(func(ctxt context.Context, h cdp.Handler) error { + cur, entries, err := page.GetNavigationHistory().Do(ctxt, h) + if err != nil { + return err + } - if cur <= 0 || cur > int64(len(entries)-1) { - return errors.New("invalid navigation entry") - } + if cur <= 0 || cur > int64(len(entries)-1) { + 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. -func NavigateForward(ctxt context.Context, h cdp.Handler) error { - cur, entries, err := page.GetNavigationHistory().Do(ctxt, h) - if err != nil { - return err - } +func NavigateForward() Action { + return ActionFunc(func(ctxt context.Context, h cdp.Handler) error { + cur, entries, err := page.GetNavigationHistory().Do(ctxt, h) + if err != nil { + return err + } - if cur < 0 || cur >= int64(len(entries)-1) { - return errors.New("invalid navigation entry") - } + if cur < 0 || cur >= int64(len(entries)-1) { + 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.