2018-10-12 16:02:53 -04:00
|
|
|
package html
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-06-19 17:58:56 -04:00
|
|
|
|
|
|
|
"github.com/MontFerret/ferret/pkg/drivers"
|
2018-10-12 16:02:53 -04:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
2019-02-13 12:31:18 -05:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
2018-10-12 16:02:53 -04:00
|
|
|
)
|
|
|
|
|
2019-09-07 14:03:17 -04:00
|
|
|
// NAVIGATE_BACK navigates a given page back within its navigation history.
|
2018-10-14 20:06:27 +03:00
|
|
|
// The operation blocks the execution until the page gets loaded.
|
|
|
|
// If the history is empty, the function returns FALSE.
|
2020-08-07 21:49:29 -04:00
|
|
|
// @param {HTMLPage} page - Target page.
|
|
|
|
// @param {Int} [entry=1] - An integer value indicating how many pages to skip.
|
|
|
|
// @param {Int} [timeout=5000] - Navigation timeout.
|
|
|
|
// @return {Boolean} - True if history exists and the operation succeeded, otherwise false.
|
2019-02-20 21:24:05 -05:00
|
|
|
func NavigateBack(ctx context.Context, args ...core.Value) (core.Value, error) {
|
2018-10-12 16:02:53 -04:00
|
|
|
err := core.ValidateArgs(args, 1, 3)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.False, err
|
|
|
|
}
|
|
|
|
|
2019-06-19 17:58:56 -04:00
|
|
|
page, err := drivers.ToPage(args[0])
|
2018-10-12 16:02:53 -04:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, err
|
|
|
|
}
|
|
|
|
|
|
|
|
skip := values.NewInt(1)
|
2019-09-05 12:17:22 -04:00
|
|
|
timeout := values.NewInt(drivers.DefaultWaitTimeout)
|
2018-10-12 16:02:53 -04:00
|
|
|
|
|
|
|
if len(args) > 1 {
|
2019-02-13 12:31:18 -05:00
|
|
|
err = core.ValidateType(args[1], types.Int)
|
2018-10-12 16:02:53 -04:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, err
|
|
|
|
}
|
|
|
|
|
|
|
|
skip = args[1].(values.Int)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(args) > 2 {
|
2019-02-13 12:31:18 -05:00
|
|
|
err = core.ValidateType(args[2], types.Int)
|
2018-10-12 16:02:53 -04:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, err
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout = args[2].(values.Int)
|
|
|
|
}
|
|
|
|
|
2019-02-20 21:24:05 -05:00
|
|
|
ctx, fn := waitTimeout(ctx, timeout)
|
|
|
|
defer fn()
|
|
|
|
|
2019-06-19 17:58:56 -04:00
|
|
|
return page.NavigateBack(ctx, skip)
|
2018-10-12 16:02:53 -04:00
|
|
|
}
|