mirror of
https://github.com/MontFerret/ferret.git
synced 2025-08-13 19:52:52 +02:00
Removed redundant element value caching
This commit is contained in:
@@ -268,7 +268,7 @@ func (doc *HTMLDocument) ExistsBySelector(ctx context.Context, selector values.S
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (doc *HTMLDocument) GetTitle() values.String {
|
func (doc *HTMLDocument) GetTitle() values.String {
|
||||||
value, err := doc.exec.ReadProperty(context.Background(), doc.element.id.objectID, "title")
|
value, err := doc.exec.ReadProperty(context.Background(), doc.element.id.ObjectID, "title")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
doc.logError(errors.Wrap(err, "failed to read document title"))
|
doc.logError(errors.Wrap(err, "failed to read document title"))
|
||||||
|
@@ -10,6 +10,13 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mafredri/cdp"
|
||||||
|
"github.com/mafredri/cdp/protocol/dom"
|
||||||
|
"github.com/mafredri/cdp/protocol/runtime"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"golang.org/x/net/html"
|
||||||
|
|
||||||
"github.com/MontFerret/ferret/pkg/drivers"
|
"github.com/MontFerret/ferret/pkg/drivers"
|
||||||
"github.com/MontFerret/ferret/pkg/drivers/cdp/eval"
|
"github.com/MontFerret/ferret/pkg/drivers/cdp/eval"
|
||||||
"github.com/MontFerret/ferret/pkg/drivers/cdp/events"
|
"github.com/MontFerret/ferret/pkg/drivers/cdp/events"
|
||||||
@@ -19,21 +26,14 @@ import (
|
|||||||
"github.com/MontFerret/ferret/pkg/runtime/core"
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
||||||
"github.com/MontFerret/ferret/pkg/runtime/values"
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
||||||
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
||||||
|
|
||||||
"github.com/mafredri/cdp"
|
|
||||||
"github.com/mafredri/cdp/protocol/dom"
|
|
||||||
"github.com/mafredri/cdp/protocol/runtime"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/rs/zerolog"
|
|
||||||
"golang.org/x/net/html"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var emptyNodeID = dom.NodeID(0)
|
var emptyNodeID = dom.NodeID(0)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
HTMLElementIdentity struct {
|
HTMLElementIdentity struct {
|
||||||
nodeID dom.NodeID
|
NodeID dom.NodeID
|
||||||
objectID runtime.RemoteObjectID
|
ObjectID runtime.RemoteObjectID
|
||||||
}
|
}
|
||||||
|
|
||||||
HTMLElement struct {
|
HTMLElement struct {
|
||||||
@@ -49,7 +49,6 @@ type (
|
|||||||
nodeName values.String
|
nodeName values.String
|
||||||
innerHTML *common.LazyValue
|
innerHTML *common.LazyValue
|
||||||
innerText *common.LazyValue
|
innerText *common.LazyValue
|
||||||
value core.Value
|
|
||||||
attributes *common.LazyValue
|
attributes *common.LazyValue
|
||||||
style *common.LazyValue
|
style *common.LazyValue
|
||||||
children []HTMLElementIdentity
|
children []HTMLElementIdentity
|
||||||
@@ -83,10 +82,6 @@ func LoadHTMLElement(
|
|||||||
return nil, core.Error(core.ErrNotFound, fmt.Sprintf("element %d", nodeID))
|
return nil, core.Error(core.ErrNotFound, fmt.Sprintf("element %d", nodeID))
|
||||||
}
|
}
|
||||||
|
|
||||||
id := HTMLElementIdentity{}
|
|
||||||
id.nodeID = nodeID
|
|
||||||
id.objectID = *obj.Object.ObjectID
|
|
||||||
|
|
||||||
return LoadHTMLElementWithID(
|
return LoadHTMLElementWithID(
|
||||||
ctx,
|
ctx,
|
||||||
logger,
|
logger,
|
||||||
@@ -94,7 +89,10 @@ func LoadHTMLElement(
|
|||||||
broker,
|
broker,
|
||||||
input,
|
input,
|
||||||
exec,
|
exec,
|
||||||
id,
|
HTMLElementIdentity{
|
||||||
|
NodeID: nodeID,
|
||||||
|
ObjectID: *obj.Object.ObjectID,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,18 +109,12 @@ func LoadHTMLElementWithID(
|
|||||||
ctx,
|
ctx,
|
||||||
dom.
|
dom.
|
||||||
NewDescribeNodeArgs().
|
NewDescribeNodeArgs().
|
||||||
SetObjectID(id.objectID).
|
SetObjectID(id.ObjectID).
|
||||||
SetDepth(1),
|
SetDepth(1),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, core.Error(err, strconv.Itoa(int(id.nodeID)))
|
return nil, core.Error(err, strconv.Itoa(int(id.NodeID)))
|
||||||
}
|
|
||||||
|
|
||||||
var val string
|
|
||||||
|
|
||||||
if node.Node.Value != nil {
|
|
||||||
val = *node.Node.Value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewHTMLElement(
|
return NewHTMLElement(
|
||||||
@@ -134,7 +126,6 @@ func LoadHTMLElementWithID(
|
|||||||
id,
|
id,
|
||||||
node.Node.NodeType,
|
node.Node.NodeType,
|
||||||
node.Node.NodeName,
|
node.Node.NodeName,
|
||||||
val,
|
|
||||||
createChildrenArray(node.Node.Children),
|
createChildrenArray(node.Node.Children),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
@@ -148,7 +139,6 @@ func NewHTMLElement(
|
|||||||
id HTMLElementIdentity,
|
id HTMLElementIdentity,
|
||||||
nodeType int,
|
nodeType int,
|
||||||
nodeName string,
|
nodeName string,
|
||||||
value string,
|
|
||||||
children []HTMLElementIdentity,
|
children []HTMLElementIdentity,
|
||||||
) *HTMLElement {
|
) *HTMLElement {
|
||||||
el := new(HTMLElement)
|
el := new(HTMLElement)
|
||||||
@@ -165,9 +155,7 @@ func NewHTMLElement(
|
|||||||
el.innerText = common.NewLazyValue(el.loadInnerText)
|
el.innerText = common.NewLazyValue(el.loadInnerText)
|
||||||
el.attributes = common.NewLazyValue(el.loadAttrs)
|
el.attributes = common.NewLazyValue(el.loadAttrs)
|
||||||
el.style = common.NewLazyValue(el.parseStyle)
|
el.style = common.NewLazyValue(el.parseStyle)
|
||||||
el.value = values.EmptyString
|
|
||||||
el.loadedChildren = common.NewLazyValue(el.loadChildren)
|
el.loadedChildren = common.NewLazyValue(el.loadChildren)
|
||||||
el.value = values.NewString(value)
|
|
||||||
el.children = children
|
el.children = children
|
||||||
|
|
||||||
broker.AddEventListener(events.EventReload, el.handlePageReload)
|
broker.AddEventListener(events.EventReload, el.handlePageReload)
|
||||||
@@ -243,7 +231,7 @@ func (el *HTMLElement) Hash() uint64 {
|
|||||||
|
|
||||||
h.Write([]byte(el.Type().String()))
|
h.Write([]byte(el.Type().String()))
|
||||||
h.Write([]byte(":"))
|
h.Write([]byte(":"))
|
||||||
h.Write([]byte(strconv.Itoa(int(el.id.nodeID))))
|
h.Write([]byte(strconv.Itoa(int(el.id.NodeID))))
|
||||||
|
|
||||||
return h.Sum64()
|
return h.Sum64()
|
||||||
}
|
}
|
||||||
@@ -269,15 +257,7 @@ func (el *HTMLElement) GetValue(ctx context.Context) (core.Value, error) {
|
|||||||
return values.None, drivers.ErrDetached
|
return values.None, drivers.ErrDetached
|
||||||
}
|
}
|
||||||
|
|
||||||
val, err := el.exec.ReadProperty(ctx, el.id.objectID, "value")
|
return el.exec.ReadProperty(ctx, el.id.ObjectID, "value")
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return values.None, err
|
|
||||||
}
|
|
||||||
|
|
||||||
el.value = val
|
|
||||||
|
|
||||||
return val, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) SetValue(ctx context.Context, value core.Value) error {
|
func (el *HTMLElement) SetValue(ctx context.Context, value core.Value) error {
|
||||||
@@ -285,7 +265,7 @@ func (el *HTMLElement) SetValue(ctx context.Context, value core.Value) error {
|
|||||||
return drivers.ErrDetached
|
return drivers.ErrDetached
|
||||||
}
|
}
|
||||||
|
|
||||||
return el.client.DOM.SetNodeValue(ctx, dom.NewSetNodeValueArgs(el.id.nodeID, value.String()))
|
return el.client.DOM.SetNodeValue(ctx, dom.NewSetNodeValueArgs(el.id.NodeID, value.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) GetNodeType() values.Int {
|
func (el *HTMLElement) GetNodeType() values.Int {
|
||||||
@@ -437,7 +417,7 @@ func (el *HTMLElement) SetAttributes(ctx context.Context, attrs *values.Object)
|
|||||||
func (el *HTMLElement) SetAttribute(ctx context.Context, name, value values.String) error {
|
func (el *HTMLElement) SetAttribute(ctx context.Context, name, value values.String) error {
|
||||||
return el.client.DOM.SetAttributeValue(
|
return el.client.DOM.SetAttributeValue(
|
||||||
ctx,
|
ctx,
|
||||||
dom.NewSetAttributeValueArgs(el.id.nodeID, string(name), string(value)),
|
dom.NewSetAttributeValueArgs(el.id.NodeID, string(name), string(value)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,7 +425,7 @@ func (el *HTMLElement) RemoveAttribute(ctx context.Context, names ...values.Stri
|
|||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
err := el.client.DOM.RemoveAttribute(
|
err := el.client.DOM.RemoveAttribute(
|
||||||
ctx,
|
ctx,
|
||||||
dom.NewRemoveAttributeArgs(el.id.nodeID, name.String()),
|
dom.NewRemoveAttributeArgs(el.id.NodeID, name.String()),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -481,7 +461,7 @@ func (el *HTMLElement) QuerySelector(ctx context.Context, selector values.String
|
|||||||
return values.None, drivers.ErrDetached
|
return values.None, drivers.ErrDetached
|
||||||
}
|
}
|
||||||
|
|
||||||
selectorArgs := dom.NewQuerySelectorArgs(el.id.nodeID, selector.String())
|
selectorArgs := dom.NewQuerySelectorArgs(el.id.NodeID, selector.String())
|
||||||
found, err := el.client.DOM.QuerySelector(ctx, selectorArgs)
|
found, err := el.client.DOM.QuerySelector(ctx, selectorArgs)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -506,7 +486,7 @@ func (el *HTMLElement) QuerySelectorAll(ctx context.Context, selector values.Str
|
|||||||
return values.NewArray(0), drivers.ErrDetached
|
return values.NewArray(0), drivers.ErrDetached
|
||||||
}
|
}
|
||||||
|
|
||||||
selectorArgs := dom.NewQuerySelectorAllArgs(el.id.nodeID, selector.String())
|
selectorArgs := dom.NewQuerySelectorAllArgs(el.id.NodeID, selector.String())
|
||||||
res, err := el.client.DOM.QuerySelectorAll(ctx, selectorArgs)
|
res, err := el.client.DOM.QuerySelectorAll(ctx, selectorArgs)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -554,7 +534,7 @@ func (el *HTMLElement) XPath(ctx context.Context, expression values.String) (res
|
|||||||
|
|
||||||
out, err := el.exec.EvalWithArgumentsAndReturnReference(ctx, templates.XPath(),
|
out, err := el.exec.EvalWithArgumentsAndReturnReference(ctx, templates.XPath(),
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
ObjectID: &el.id.objectID,
|
ObjectID: &el.id.ObjectID,
|
||||||
},
|
},
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
Value: json.RawMessage(exp),
|
Value: json.RawMessage(exp),
|
||||||
@@ -633,8 +613,8 @@ func (el *HTMLElement) XPath(ctx context.Context, expression values.String) (res
|
|||||||
el.input,
|
el.input,
|
||||||
el.exec,
|
el.exec,
|
||||||
HTMLElementIdentity{
|
HTMLElementIdentity{
|
||||||
nodeID: repl.NodeID,
|
NodeID: repl.NodeID,
|
||||||
objectID: *descr.Value.ObjectID,
|
ObjectID: *descr.Value.ObjectID,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -665,8 +645,8 @@ func (el *HTMLElement) XPath(ctx context.Context, expression values.String) (res
|
|||||||
el.input,
|
el.input,
|
||||||
el.exec,
|
el.exec,
|
||||||
HTMLElementIdentity{
|
HTMLElementIdentity{
|
||||||
nodeID: repl.NodeID,
|
NodeID: repl.NodeID,
|
||||||
objectID: *out.ObjectID,
|
ObjectID: *out.ObjectID,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
@@ -713,7 +693,7 @@ func (el *HTMLElement) GetInnerTextBySelector(ctx context.Context, selector valu
|
|||||||
ctx,
|
ctx,
|
||||||
templates.GetInnerTextBySelector(),
|
templates.GetInnerTextBySelector(),
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
ObjectID: &el.id.objectID,
|
ObjectID: &el.id.ObjectID,
|
||||||
},
|
},
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
Value: sel,
|
Value: sel,
|
||||||
@@ -748,7 +728,7 @@ func (el *HTMLElement) SetInnerTextBySelector(ctx context.Context, selector, inn
|
|||||||
ctx,
|
ctx,
|
||||||
templates.SetInnerTextBySelector(),
|
templates.SetInnerTextBySelector(),
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
ObjectID: &el.id.objectID,
|
ObjectID: &el.id.ObjectID,
|
||||||
},
|
},
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
Value: sel,
|
Value: sel,
|
||||||
@@ -774,7 +754,7 @@ func (el *HTMLElement) GetInnerTextBySelectorAll(ctx context.Context, selector v
|
|||||||
ctx,
|
ctx,
|
||||||
templates.GetInnerTextBySelectorAll(),
|
templates.GetInnerTextBySelectorAll(),
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
ObjectID: &el.id.objectID,
|
ObjectID: &el.id.ObjectID,
|
||||||
},
|
},
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
Value: sel,
|
Value: sel,
|
||||||
@@ -833,7 +813,7 @@ func (el *HTMLElement) GetInnerHTMLBySelector(ctx context.Context, selector valu
|
|||||||
ctx,
|
ctx,
|
||||||
templates.GetInnerHTMLBySelector(),
|
templates.GetInnerHTMLBySelector(),
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
ObjectID: &el.id.objectID,
|
ObjectID: &el.id.ObjectID,
|
||||||
},
|
},
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
Value: sel,
|
Value: sel,
|
||||||
@@ -868,7 +848,7 @@ func (el *HTMLElement) SetInnerHTMLBySelector(ctx context.Context, selector, inn
|
|||||||
ctx,
|
ctx,
|
||||||
templates.SetInnerHTMLBySelector(),
|
templates.SetInnerHTMLBySelector(),
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
ObjectID: &el.id.objectID,
|
ObjectID: &el.id.ObjectID,
|
||||||
},
|
},
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
Value: sel,
|
Value: sel,
|
||||||
@@ -894,7 +874,7 @@ func (el *HTMLElement) GetInnerHTMLBySelectorAll(ctx context.Context, selector v
|
|||||||
ctx,
|
ctx,
|
||||||
templates.GetInnerHTMLBySelectorAll(),
|
templates.GetInnerHTMLBySelectorAll(),
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
ObjectID: &el.id.objectID,
|
ObjectID: &el.id.ObjectID,
|
||||||
},
|
},
|
||||||
runtime.CallArgument{
|
runtime.CallArgument{
|
||||||
Value: sel,
|
Value: sel,
|
||||||
@@ -919,7 +899,7 @@ func (el *HTMLElement) CountBySelector(ctx context.Context, selector values.Stri
|
|||||||
return values.ZeroInt, drivers.ErrDetached
|
return values.ZeroInt, drivers.ErrDetached
|
||||||
}
|
}
|
||||||
|
|
||||||
selectorArgs := dom.NewQuerySelectorAllArgs(el.id.nodeID, selector.String())
|
selectorArgs := dom.NewQuerySelectorAllArgs(el.id.NodeID, selector.String())
|
||||||
res, err := el.client.DOM.QuerySelectorAll(ctx, selectorArgs)
|
res, err := el.client.DOM.QuerySelectorAll(ctx, selectorArgs)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -935,7 +915,7 @@ func (el *HTMLElement) ExistsBySelector(ctx context.Context, selector values.Str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Can we use RemoteObjectID or BackendID instead of NodeId?
|
// TODO: Can we use RemoteObjectID or BackendID instead of NodeId?
|
||||||
selectorArgs := dom.NewQuerySelectorArgs(el.id.nodeID, selector.String())
|
selectorArgs := dom.NewQuerySelectorArgs(el.id.NodeID, selector.String())
|
||||||
res, err := el.client.DOM.QuerySelector(ctx, selectorArgs)
|
res, err := el.client.DOM.QuerySelector(ctx, selectorArgs)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1027,15 +1007,15 @@ func (el *HTMLElement) WaitForStyle(ctx context.Context, name values.String, val
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) Click(ctx context.Context, count values.Int) error {
|
func (el *HTMLElement) Click(ctx context.Context, count values.Int) error {
|
||||||
return el.input.Click(ctx, el.id.objectID, int(count))
|
return el.input.Click(ctx, el.id.ObjectID, int(count))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) ClickBySelector(ctx context.Context, selector values.String, count values.Int) error {
|
func (el *HTMLElement) ClickBySelector(ctx context.Context, selector values.String, count values.Int) error {
|
||||||
return el.input.ClickBySelector(ctx, el.id.nodeID, selector.String(), int(count))
|
return el.input.ClickBySelector(ctx, el.id.NodeID, selector.String(), int(count))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) ClickBySelectorAll(ctx context.Context, selector values.String, count values.Int) error {
|
func (el *HTMLElement) ClickBySelectorAll(ctx context.Context, selector values.String, count values.Int) error {
|
||||||
return el.input.ClickBySelectorAll(ctx, el.id.nodeID, selector.String(), int(count))
|
return el.input.ClickBySelectorAll(ctx, el.id.NodeID, selector.String(), int(count))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) Input(ctx context.Context, value core.Value, delay values.Int) error {
|
func (el *HTMLElement) Input(ctx context.Context, value core.Value, delay values.Int) error {
|
||||||
@@ -1043,7 +1023,7 @@ func (el *HTMLElement) Input(ctx context.Context, value core.Value, delay values
|
|||||||
return core.Error(core.ErrInvalidOperation, "element is not an <input> element.")
|
return core.Error(core.ErrInvalidOperation, "element is not an <input> element.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return el.input.Type(ctx, el.id.objectID, input.TypeParams{
|
return el.input.Type(ctx, el.id.ObjectID, input.TypeParams{
|
||||||
Text: value.String(),
|
Text: value.String(),
|
||||||
Clear: false,
|
Clear: false,
|
||||||
Delay: time.Duration(delay) * time.Millisecond,
|
Delay: time.Duration(delay) * time.Millisecond,
|
||||||
@@ -1051,7 +1031,7 @@ func (el *HTMLElement) Input(ctx context.Context, value core.Value, delay values
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) InputBySelector(ctx context.Context, selector values.String, value core.Value, delay values.Int) error {
|
func (el *HTMLElement) InputBySelector(ctx context.Context, selector values.String, value core.Value, delay values.Int) error {
|
||||||
return el.input.TypeBySelector(ctx, el.id.nodeID, selector.String(), input.TypeParams{
|
return el.input.TypeBySelector(ctx, el.id.NodeID, selector.String(), input.TypeParams{
|
||||||
Text: value.String(),
|
Text: value.String(),
|
||||||
Clear: false,
|
Clear: false,
|
||||||
Delay: time.Duration(delay) * time.Millisecond,
|
Delay: time.Duration(delay) * time.Millisecond,
|
||||||
@@ -1059,39 +1039,39 @@ func (el *HTMLElement) InputBySelector(ctx context.Context, selector values.Stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) Clear(ctx context.Context) error {
|
func (el *HTMLElement) Clear(ctx context.Context) error {
|
||||||
return el.input.Clear(ctx, el.id.objectID)
|
return el.input.Clear(ctx, el.id.ObjectID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) ClearBySelector(ctx context.Context, selector values.String) error {
|
func (el *HTMLElement) ClearBySelector(ctx context.Context, selector values.String) error {
|
||||||
return el.input.ClearBySelector(ctx, el.id.nodeID, selector.String())
|
return el.input.ClearBySelector(ctx, el.id.NodeID, selector.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) Select(ctx context.Context, value *values.Array) (*values.Array, error) {
|
func (el *HTMLElement) Select(ctx context.Context, value *values.Array) (*values.Array, error) {
|
||||||
return el.input.Select(ctx, el.id.objectID, value)
|
return el.input.Select(ctx, el.id.ObjectID, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) SelectBySelector(ctx context.Context, selector values.String, value *values.Array) (*values.Array, error) {
|
func (el *HTMLElement) SelectBySelector(ctx context.Context, selector values.String, value *values.Array) (*values.Array, error) {
|
||||||
return el.input.SelectBySelector(ctx, el.id.nodeID, selector.String(), value)
|
return el.input.SelectBySelector(ctx, el.id.NodeID, selector.String(), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) ScrollIntoView(ctx context.Context) error {
|
func (el *HTMLElement) ScrollIntoView(ctx context.Context) error {
|
||||||
return el.input.ScrollIntoView(ctx, el.id.objectID)
|
return el.input.ScrollIntoView(ctx, el.id.ObjectID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) Focus(ctx context.Context) error {
|
func (el *HTMLElement) Focus(ctx context.Context) error {
|
||||||
return el.input.Focus(ctx, el.id.objectID)
|
return el.input.Focus(ctx, el.id.ObjectID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) FocusBySelector(ctx context.Context, selector values.String) error {
|
func (el *HTMLElement) FocusBySelector(ctx context.Context, selector values.String) error {
|
||||||
return el.input.FocusBySelector(ctx, el.id.nodeID, selector.String())
|
return el.input.FocusBySelector(ctx, el.id.NodeID, selector.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) Hover(ctx context.Context) error {
|
func (el *HTMLElement) Hover(ctx context.Context) error {
|
||||||
return el.input.MoveMouse(ctx, el.id.objectID)
|
return el.input.MoveMouse(ctx, el.id.ObjectID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) HoverBySelector(ctx context.Context, selector values.String) error {
|
func (el *HTMLElement) HoverBySelector(ctx context.Context, selector values.String) error {
|
||||||
return el.input.MoveMouseBySelector(ctx, el.id.nodeID, selector.String())
|
return el.input.MoveMouseBySelector(ctx, el.id.NodeID, selector.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) IsDetached() values.Boolean {
|
func (el *HTMLElement) IsDetached() values.Boolean {
|
||||||
@@ -1146,7 +1126,7 @@ func (el *HTMLElement) loadInnerText(ctx context.Context) (core.Value, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) loadAttrs(ctx context.Context) (core.Value, error) {
|
func (el *HTMLElement) loadAttrs(ctx context.Context) (core.Value, error) {
|
||||||
repl, err := el.client.DOM.GetAttributes(ctx, dom.NewGetAttributesArgs(el.id.nodeID))
|
repl, err := el.client.DOM.GetAttributes(ctx, dom.NewGetAttributesArgs(el.id.NodeID))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.None, err
|
return values.None, err
|
||||||
@@ -1170,7 +1150,7 @@ func (el *HTMLElement) loadChildren(ctx context.Context) (core.Value, error) {
|
|||||||
el.events,
|
el.events,
|
||||||
el.input,
|
el.input,
|
||||||
el.exec,
|
el.exec,
|
||||||
childID.nodeID,
|
childID.NodeID,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1216,7 +1196,7 @@ func (el *HTMLElement) handleAttrModified(ctx context.Context, message interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// it's not for this el
|
// it's not for this el
|
||||||
if reply.NodeID != el.id.nodeID {
|
if reply.NodeID != el.id.NodeID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1260,7 +1240,7 @@ func (el *HTMLElement) handleAttrRemoved(ctx context.Context, message interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// it's not for this el
|
// it's not for this el
|
||||||
if reply.NodeID != el.id.nodeID {
|
if reply.NodeID != el.id.NodeID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1302,7 +1282,7 @@ func (el *HTMLElement) handleChildrenCountChanged(ctx context.Context, message i
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if reply.NodeID != el.id.nodeID {
|
if reply.NodeID != el.id.NodeID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1315,7 +1295,7 @@ func (el *HTMLElement) handleChildrenCountChanged(ctx context.Context, message i
|
|||||||
|
|
||||||
node, err := el.client.DOM.DescribeNode(
|
node, err := el.client.DOM.DescribeNode(
|
||||||
ctx,
|
ctx,
|
||||||
dom.NewDescribeNodeArgs().SetObjectID(el.id.objectID),
|
dom.NewDescribeNodeArgs().SetObjectID(el.id.ObjectID),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1334,7 +1314,7 @@ func (el *HTMLElement) handleChildInserted(ctx context.Context, message interfac
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if reply.ParentNodeID != el.id.nodeID {
|
if reply.ParentNodeID != el.id.NodeID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1350,7 +1330,7 @@ func (el *HTMLElement) handleChildInserted(ctx context.Context, message interfac
|
|||||||
defer el.mu.Unlock()
|
defer el.mu.Unlock()
|
||||||
|
|
||||||
for idx, id := range el.children {
|
for idx, id := range el.children {
|
||||||
if id.nodeID == prevID {
|
if id.NodeID == prevID {
|
||||||
targetIDx = idx
|
targetIDx = idx
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -1361,7 +1341,7 @@ func (el *HTMLElement) handleChildInserted(ctx context.Context, message interfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
nextIdentity := HTMLElementIdentity{
|
nextIdentity := HTMLElementIdentity{
|
||||||
nodeID: reply.Node.NodeID,
|
NodeID: reply.Node.NodeID,
|
||||||
}
|
}
|
||||||
|
|
||||||
arr := el.children
|
arr := el.children
|
||||||
@@ -1395,7 +1375,7 @@ func (el *HTMLElement) handleChildRemoved(ctx context.Context, message interface
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if reply.ParentNodeID != el.id.nodeID {
|
if reply.ParentNodeID != el.id.NodeID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1410,7 +1390,7 @@ func (el *HTMLElement) handleChildRemoved(ctx context.Context, message interface
|
|||||||
defer el.mu.Unlock()
|
defer el.mu.Unlock()
|
||||||
|
|
||||||
for idx, id := range el.children {
|
for idx, id := range el.children {
|
||||||
if id.nodeID == targetID {
|
if id.NodeID == targetID {
|
||||||
targetIDx = idx
|
targetIDx = idx
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -1432,7 +1412,7 @@ func (el *HTMLElement) handleChildRemoved(ctx context.Context, message interface
|
|||||||
el.logger.Error().
|
el.logger.Error().
|
||||||
Timestamp().
|
Timestamp().
|
||||||
Err(err).
|
Err(err).
|
||||||
Int("nodeID", int(el.id.nodeID)).
|
Int("nodeID", int(el.id.NodeID)).
|
||||||
Msg("failed to update element")
|
Msg("failed to update element")
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -1450,7 +1430,7 @@ func (el *HTMLElement) logError(err error) *zerolog.Event {
|
|||||||
return el.logger.
|
return el.logger.
|
||||||
Error().
|
Error().
|
||||||
Timestamp().
|
Timestamp().
|
||||||
Int("nodeID", int(el.id.nodeID)).
|
Int("nodeID", int(el.id.NodeID)).
|
||||||
Str("objectID", string(el.id.objectID)).
|
Str("objectID", string(el.id.ObjectID)).
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
|
@@ -71,10 +71,10 @@ func parseAttrs(attrs []string) *values.Object {
|
|||||||
func setInnerHTML(ctx context.Context, client *cdp.Client, exec *eval.ExecutionContext, id HTMLElementIdentity, innerHTML values.String) error {
|
func setInnerHTML(ctx context.Context, client *cdp.Client, exec *eval.ExecutionContext, id HTMLElementIdentity, innerHTML values.String) error {
|
||||||
var objID *runtime.RemoteObjectID
|
var objID *runtime.RemoteObjectID
|
||||||
|
|
||||||
if id.objectID != "" {
|
if id.ObjectID != "" {
|
||||||
objID = &id.objectID
|
objID = &id.ObjectID
|
||||||
} else {
|
} else {
|
||||||
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.nodeID))
|
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.NodeID))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -110,10 +110,10 @@ func getInnerHTML(ctx context.Context, client *cdp.Client, exec *eval.ExecutionC
|
|||||||
if nodeType != html.DocumentNode {
|
if nodeType != html.DocumentNode {
|
||||||
var objID runtime.RemoteObjectID
|
var objID runtime.RemoteObjectID
|
||||||
|
|
||||||
if id.objectID != "" {
|
if id.ObjectID != "" {
|
||||||
objID = id.objectID
|
objID = id.ObjectID
|
||||||
} else {
|
} else {
|
||||||
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.nodeID))
|
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.NodeID))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -147,10 +147,10 @@ func getInnerHTML(ctx context.Context, client *cdp.Client, exec *eval.ExecutionC
|
|||||||
func setInnerText(ctx context.Context, client *cdp.Client, exec *eval.ExecutionContext, id HTMLElementIdentity, innerText values.String) error {
|
func setInnerText(ctx context.Context, client *cdp.Client, exec *eval.ExecutionContext, id HTMLElementIdentity, innerText values.String) error {
|
||||||
var objID *runtime.RemoteObjectID
|
var objID *runtime.RemoteObjectID
|
||||||
|
|
||||||
if id.objectID != "" {
|
if id.ObjectID != "" {
|
||||||
objID = &id.objectID
|
objID = &id.ObjectID
|
||||||
} else {
|
} else {
|
||||||
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.nodeID))
|
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.NodeID))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -186,10 +186,10 @@ func getInnerText(ctx context.Context, client *cdp.Client, exec *eval.ExecutionC
|
|||||||
if nodeType != html.DocumentNode {
|
if nodeType != html.DocumentNode {
|
||||||
var objID runtime.RemoteObjectID
|
var objID runtime.RemoteObjectID
|
||||||
|
|
||||||
if id.objectID != "" {
|
if id.ObjectID != "" {
|
||||||
objID = id.objectID
|
objID = id.ObjectID
|
||||||
} else {
|
} else {
|
||||||
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.nodeID))
|
repl, err := client.DOM.ResolveNode(ctx, dom.NewResolveNodeArgs().SetNodeID(id.NodeID))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -238,7 +238,7 @@ func createChildrenArray(nodes []dom.Node) []HTMLElementIdentity {
|
|||||||
for idx, child := range nodes {
|
for idx, child := range nodes {
|
||||||
child := child
|
child := child
|
||||||
children[idx] = HTMLElementIdentity{
|
children[idx] = HTMLElementIdentity{
|
||||||
nodeID: child.NodeID,
|
NodeID: child.NodeID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user