mirror of
https://github.com/MontFerret/ferret.git
synced 2025-07-03 00:46:51 +02:00
Bugfix/#399 navigation (#432)
* Refactored networking * Some work * Added event loop * Renamed EventHandler to Handler * wip * Removed console logs * Added DOMManager * Refactored frame managment * Fixes * Fixed concurrency issues * Fixed unit tests * Improved EventLoop api * Some fixes * Refactored event loop. * Improved logic of initial page load * Cleaned up * Fixed linting issues * Fixed dom.Manager.Close * SOme works * Fixes * Removed fmt.Println statements * Refactored WaitForNavigation * Removed filter for e2e tests * Made Cookies Measurable * Made Cookies KeyedCollection * Fixes after code review * Updated e2e tests for iframes * Fixed iframe lookup in e2e tests * Added comments
This commit is contained in:
@ -2,6 +2,7 @@ package html
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/drivers"
|
||||
"github.com/MontFerret/ferret/pkg/runtime/core"
|
||||
@ -9,6 +10,11 @@ import (
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
||||
)
|
||||
|
||||
type WaitNavigationParams struct {
|
||||
TargetURL values.String
|
||||
Timeout values.Int
|
||||
}
|
||||
|
||||
// WAIT_NAVIGATION waits for a given page to navigate to a new url.
|
||||
// Stops the execution until the navigation ends or operation times out.
|
||||
// @param page (HTMLPage) - Target page.
|
||||
@ -26,20 +32,67 @@ func WaitNavigation(ctx context.Context, args ...core.Value) (core.Value, error)
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
timeout := values.NewInt(drivers.DefaultWaitTimeout)
|
||||
var params WaitNavigationParams
|
||||
|
||||
if len(args) > 1 {
|
||||
err = core.ValidateType(args[1], types.Int)
|
||||
p, err := parseWaitNavigationParams(args[1])
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
timeout = args[1].(values.Int)
|
||||
params = p
|
||||
} else {
|
||||
params = defaultWaitNavigationParams()
|
||||
}
|
||||
|
||||
ctx, fn := waitTimeout(ctx, timeout)
|
||||
ctx, fn := waitTimeout(ctx, params.Timeout)
|
||||
defer fn()
|
||||
|
||||
return values.None, doc.WaitForNavigation(ctx)
|
||||
return values.None, doc.WaitForNavigation(ctx, params.TargetURL)
|
||||
}
|
||||
|
||||
func parseWaitNavigationParams(arg core.Value) (WaitNavigationParams, error) {
|
||||
params := defaultWaitNavigationParams()
|
||||
err := core.ValidateType(arg, types.Int, types.Object)
|
||||
|
||||
if err != nil {
|
||||
return params, err
|
||||
}
|
||||
|
||||
if arg.Type() == types.Int {
|
||||
params.Timeout = arg.(values.Int)
|
||||
|
||||
} else {
|
||||
obj := arg.(*values.Object)
|
||||
|
||||
if v, exists := obj.Get("timeout"); exists {
|
||||
err := core.ValidateType(v, types.Int)
|
||||
|
||||
if err != nil {
|
||||
return params, errors.Wrap(err, "navigation parameters: timeout")
|
||||
}
|
||||
|
||||
params.Timeout = v.(values.Int)
|
||||
}
|
||||
|
||||
if v, exists := obj.Get("target"); exists {
|
||||
err := core.ValidateType(v, types.String)
|
||||
|
||||
if err != nil {
|
||||
return params, errors.Wrap(err, "navigation parameters: url")
|
||||
}
|
||||
|
||||
params.TargetURL = v.(values.String)
|
||||
}
|
||||
}
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
||||
func defaultWaitNavigationParams() WaitNavigationParams {
|
||||
return WaitNavigationParams{
|
||||
TargetURL: "",
|
||||
Timeout: values.NewInt(drivers.DefaultWaitTimeout),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user