mirror of
https://github.com/MontFerret/ferret.git
synced 2025-07-05 00:49:00 +02:00
Feature/#220 iframe support (#315)
* Refactored Virtual DOM structure * Added new E2E tests * Updated E2E Test Runner
This commit is contained in:
@ -12,22 +12,22 @@ import (
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
||||
)
|
||||
|
||||
type DocumentLoadParams struct {
|
||||
drivers.LoadDocumentParams
|
||||
type PageLoadParams struct {
|
||||
drivers.OpenPageParams
|
||||
Driver string
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// Document loads a HTML document by a given url.
|
||||
// Open opens an HTML page by a given url.
|
||||
// By default, loads a document by http call - resulted document does not support any interactions.
|
||||
// If passed "true" as a second argument, headless browser is used for loading the document which support interactions.
|
||||
// @param url (String) - Target url string. If passed "about:blank" for dynamic document - it will open an empty page.
|
||||
// @param isDynamicOrParams (Boolean|DocumentLoadParams) - Either a boolean value that indicates whether to use dynamic page
|
||||
// @param isDynamicOrParams (Boolean|PageLoadParams) - Either a boolean value that indicates whether to use dynamic page
|
||||
// or an object with the following properties :
|
||||
// dynamic (Boolean) - Optional, indicates whether to use dynamic page.
|
||||
// timeout (Int) - Optional, Document load timeout.
|
||||
// timeout (Int) - Optional, Open load timeout.
|
||||
// @returns (HTMLDocument) - Returns loaded HTML document.
|
||||
func Document(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
func Open(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
err := core.ValidateArgs(args, 1, 2)
|
||||
|
||||
if err != nil {
|
||||
@ -42,12 +42,12 @@ func Document(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
|
||||
url := args[0].(values.String)
|
||||
|
||||
var params DocumentLoadParams
|
||||
var params PageLoadParams
|
||||
|
||||
if len(args) == 1 {
|
||||
params = newDefaultDocLoadParams(url)
|
||||
} else {
|
||||
p, err := newDocLoadParams(url, args[1])
|
||||
p, err := newPageLoadParams(url, args[1])
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
@ -65,19 +65,19 @@ func Document(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
return drv.LoadDocument(ctx, params.LoadDocumentParams)
|
||||
return drv.Open(ctx, params.OpenPageParams)
|
||||
}
|
||||
|
||||
func newDefaultDocLoadParams(url values.String) DocumentLoadParams {
|
||||
return DocumentLoadParams{
|
||||
LoadDocumentParams: drivers.LoadDocumentParams{
|
||||
func newDefaultDocLoadParams(url values.String) PageLoadParams {
|
||||
return PageLoadParams{
|
||||
OpenPageParams: drivers.OpenPageParams{
|
||||
URL: url.String(),
|
||||
},
|
||||
Timeout: time.Second * 30,
|
||||
}
|
||||
}
|
||||
|
||||
func newDocLoadParams(url values.String, arg core.Value) (DocumentLoadParams, error) {
|
||||
func newPageLoadParams(url values.String, arg core.Value) (PageLoadParams, error) {
|
||||
res := newDefaultDocLoadParams(url)
|
||||
|
||||
if err := core.ValidateType(arg, types.Boolean, types.String, types.Object); err != nil {
|
||||
|
Reference in New Issue
Block a user