github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/html/navigate_forward.go (about) 1 package html 2 3 import ( 4 "context" 5 6 "github.com/MontFerret/ferret/pkg/drivers" 7 "github.com/MontFerret/ferret/pkg/runtime/core" 8 "github.com/MontFerret/ferret/pkg/runtime/values" 9 "github.com/MontFerret/ferret/pkg/runtime/values/types" 10 ) 11 12 // NAVIGATE_FORWARD navigates a given page forward within its navigation history. 13 // The operation blocks the execution until the page gets loaded. 14 // If the history is empty, the function returns FALSE. 15 // @param {HTMLPage} page - Target page. 16 // @param {Int} [entry=1] - An integer value indicating how many pages to skip. 17 // @param {Int} [timeout=5000] - Navigation timeout. 18 // @return {Boolean} - True if history exists and the operation succeeded, otherwise false. 19 func NavigateForward(ctx context.Context, args ...core.Value) (core.Value, error) { 20 err := core.ValidateArgs(args, 1, 3) 21 22 if err != nil { 23 return values.False, err 24 } 25 26 page, err := drivers.ToPage(args[0]) 27 28 if err != nil { 29 return values.None, err 30 } 31 32 skip := values.NewInt(1) 33 timeout := values.NewInt(drivers.DefaultWaitTimeout) 34 35 if len(args) > 1 { 36 err = core.ValidateType(args[1], types.Int) 37 38 if err != nil { 39 return values.None, err 40 } 41 42 skip = args[1].(values.Int) 43 } 44 45 if len(args) > 2 { 46 err = core.ValidateType(args[2], types.Int) 47 48 if err != nil { 49 return values.None, err 50 } 51 52 timeout = args[2].(values.Int) 53 } 54 55 ctx, fn := waitTimeout(ctx, timeout) 56 defer fn() 57 58 return page.NavigateForward(ctx, skip) 59 }