mirror of
https://github.com/MontFerret/ferret.git
synced 2025-03-19 21:28:32 +02:00
* 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
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
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
|
|
}
|