mirror of
https://github.com/MontFerret/ferret.git
synced 2025-07-13 01:20:35 +02:00
Feature/425 iframe navigation (#535)
* Updated navigation logic * Fixed goroutine deadlock * Fixed closing chan * Added support of waiting for individual frame navigation * Updated EventLoop API in order to avoid double closing of event sources * Fixed attr retrieval * Removed redundant println * Updated DOM Readiness check
This commit is contained in:
58
pkg/stdlib/html/find_frames.go
Normal file
58
pkg/stdlib/html/find_frames.go
Normal file
@ -0,0 +1,58 @@
|
||||
package html
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/MontFerret/ferret/pkg/drivers"
|
||||
"github.com/MontFerret/ferret/pkg/runtime/core"
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values"
|
||||
)
|
||||
|
||||
// FRAMES finds HTML frames by a given property selector.
|
||||
// Returns an empty array if frames not found.
|
||||
// @param page (HTMLPage) - HTML page.
|
||||
// @param prop (String) - Property selector.
|
||||
// @param value (Any) - Property value.
|
||||
// @returns (Array) - Returns an array of found HTML frames.
|
||||
func Frames(ctx context.Context, args ...core.Value) (core.Value, error) {
|
||||
err := core.ValidateArgs(args, 3, 3)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
page, err := drivers.ToPage(args[0])
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
frames, err := page.GetFrames(ctx)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
propName := values.ToString(args[1])
|
||||
propValue := args[2]
|
||||
|
||||
result, _ := frames.Find(func(value core.Value, idx int) bool {
|
||||
doc, e := drivers.ToDocument(value)
|
||||
|
||||
if e != nil {
|
||||
err = e
|
||||
return false
|
||||
}
|
||||
|
||||
currentPropValue, e := doc.GetIn(ctx, []core.Value{propName})
|
||||
|
||||
if e != nil {
|
||||
err = e
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return currentPropValue.Compare(propValue) == 0
|
||||
})
|
||||
|
||||
return result, err
|
||||
}
|
Reference in New Issue
Block a user