chromedp/cdp/dom/dom.go

2739 lines
66 KiB
Go
Raw Normal View History

2017-01-24 15:09:23 +00:00
// Package dom provides the Chrome Debugging Protocol
// commands, types, and events for the DOM domain.
2017-01-24 15:09:23 +00:00
//
// This domain exposes DOM read/write operations. Each DOM Node is
// represented with its mirror object that has an id. This id can be used to get
// additional information on the Node, resolve it into the JavaScript object
// wrapper, etc. It is important that client receives DOM events only for the
// nodes that are known to the client. Backend keeps track of the nodes that
// were sent to the client and never sends the same node twice. It is client's
// responsibility to collect information about the nodes that were sent to the
// client.<p>Note that iframe owner elements will return corresponding document
// elements as their child nodes.</p>.
//
// Generated by the chromedp-gen command.
package dom
// AUTOGENERATED. DO NOT EDIT.
import (
"context"
2017-01-26 07:28:34 +00:00
cdp "github.com/knq/chromedp/cdp"
2017-01-24 15:09:23 +00:00
"github.com/knq/chromedp/cdp/runtime"
"github.com/mailru/easyjson"
)
// EnableParams enables DOM agent for the given page.
type EnableParams struct{}
// Enable enables DOM agent for the given page.
func Enable() *EnableParams {
return &EnableParams{}
}
// Do executes DOM.enable against the provided context and
// target handler.
func (p *EnableParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMEnable, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// DisableParams disables DOM agent for the given page.
type DisableParams struct{}
// Disable disables DOM agent for the given page.
func Disable() *DisableParams {
return &DisableParams{}
}
// Do executes DOM.disable against the provided context and
// target handler.
func (p *DisableParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMDisable, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// GetDocumentParams returns the root DOM node (and optionally the subtree)
// to the caller.
type GetDocumentParams struct {
Depth int64 `json:"depth,omitempty"` // The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
Pierce bool `json:"pierce,omitempty"` // Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
}
// GetDocument returns the root DOM node (and optionally the subtree) to the
// caller.
//
// parameters:
func GetDocument() *GetDocumentParams {
return &GetDocumentParams{}
}
// WithDepth the maximum depth at which children should be retrieved,
// defaults to 1. Use -1 for the entire subtree or provide an integer larger
// than 0.
func (p GetDocumentParams) WithDepth(depth int64) *GetDocumentParams {
p.Depth = depth
return &p
}
// WithPierce whether or not iframes and shadow roots should be traversed
// when returning the subtree (default is false).
func (p GetDocumentParams) WithPierce(pierce bool) *GetDocumentParams {
p.Pierce = pierce
return &p
}
// GetDocumentReturns return values.
type GetDocumentReturns struct {
2017-01-26 07:28:34 +00:00
Root *cdp.Node `json:"root,omitempty"` // Resulting node.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.getDocument against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// root - Resulting node.
func (p *GetDocumentParams) Do(ctxt context.Context, h cdp.Handler) (root *cdp.Node, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMGetDocument, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetDocumentReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.Root, nil
case error:
return nil, v
}
case <-ctxt.Done():
return nil, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// GetFlattenedDocumentParams returns the root DOM node (and optionally the
// subtree) to the caller.
type GetFlattenedDocumentParams struct {
Depth int64 `json:"depth,omitempty"` // The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
Pierce bool `json:"pierce,omitempty"` // Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
}
// GetFlattenedDocument returns the root DOM node (and optionally the
// subtree) to the caller.
//
// parameters:
func GetFlattenedDocument() *GetFlattenedDocumentParams {
return &GetFlattenedDocumentParams{}
}
// WithDepth the maximum depth at which children should be retrieved,
// defaults to 1. Use -1 for the entire subtree or provide an integer larger
// than 0.
func (p GetFlattenedDocumentParams) WithDepth(depth int64) *GetFlattenedDocumentParams {
p.Depth = depth
return &p
}
// WithPierce whether or not iframes and shadow roots should be traversed
// when returning the subtree (default is false).
func (p GetFlattenedDocumentParams) WithPierce(pierce bool) *GetFlattenedDocumentParams {
p.Pierce = pierce
return &p
}
// GetFlattenedDocumentReturns return values.
type GetFlattenedDocumentReturns struct {
Nodes []*cdp.Node `json:"nodes,omitempty"` // Resulting node.
}
// Do executes DOM.getFlattenedDocument against the provided context and
// target handler.
//
// returns:
// nodes - Resulting node.
func (p *GetFlattenedDocumentParams) Do(ctxt context.Context, h cdp.Handler) (nodes []*cdp.Node, err error) {
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
ch := h.Execute(ctxt, cdp.CommandDOMGetFlattenedDocument, easyjson.RawMessage(buf))
// read response
select {
case res := <-ch:
if res == nil {
return nil, cdp.ErrChannelClosed
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetFlattenedDocumentReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
return nil, cdp.ErrInvalidResult
}
return r.Nodes, nil
case error:
return nil, v
}
case <-ctxt.Done():
return nil, ctxt.Err()
}
return nil, cdp.ErrUnknownResult
}
2017-01-24 15:09:23 +00:00
// CollectClassNamesFromSubtreeParams collects class names for the node with
// given id and all of it's child nodes.
type CollectClassNamesFromSubtreeParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to collect class names.
2017-01-24 15:09:23 +00:00
}
// CollectClassNamesFromSubtree collects class names for the node with given
// id and all of it's child nodes.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to collect class names.
func CollectClassNamesFromSubtree(nodeID cdp.NodeID) *CollectClassNamesFromSubtreeParams {
2017-01-24 15:09:23 +00:00
return &CollectClassNamesFromSubtreeParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// CollectClassNamesFromSubtreeReturns return values.
type CollectClassNamesFromSubtreeReturns struct {
ClassNames []string `json:"classNames,omitempty"` // Class name list.
}
// Do executes DOM.collectClassNamesFromSubtree against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// classNames - Class name list.
func (p *CollectClassNamesFromSubtreeParams) Do(ctxt context.Context, h cdp.Handler) (classNames []string, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMCollectClassNamesFromSubtree, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r CollectClassNamesFromSubtreeReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.ClassNames, nil
case error:
return nil, v
}
case <-ctxt.Done():
return nil, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// RequestChildNodesParams requests that children of the node with given id
// are returned to the caller in form of setChildNodes events where not only
// immediate children are retrieved, but all children down to the specified
// depth.
type RequestChildNodesParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to get children for.
Depth int64 `json:"depth,omitempty"` // The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
Pierce bool `json:"pierce,omitempty"` // Whether or not iframes and shadow roots should be traversed when returning the sub-tree (default is false).
2017-01-24 15:09:23 +00:00
}
// RequestChildNodes requests that children of the node with given id are
// returned to the caller in form of setChildNodes events where not only
// immediate children are retrieved, but all children down to the specified
// depth.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to get children for.
func RequestChildNodes(nodeID cdp.NodeID) *RequestChildNodesParams {
2017-01-24 15:09:23 +00:00
return &RequestChildNodesParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// WithDepth the maximum depth at which children should be retrieved,
// defaults to 1. Use -1 for the entire subtree or provide an integer larger
// than 0.
func (p RequestChildNodesParams) WithDepth(depth int64) *RequestChildNodesParams {
p.Depth = depth
return &p
}
// WithPierce whether or not iframes and shadow roots should be traversed
// when returning the sub-tree (default is false).
func (p RequestChildNodesParams) WithPierce(pierce bool) *RequestChildNodesParams {
p.Pierce = pierce
return &p
}
// Do executes DOM.requestChildNodes against the provided context and
// target handler.
func (p *RequestChildNodesParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMRequestChildNodes, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// QuerySelectorParams executes querySelector on a given node.
type QuerySelectorParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to query upon.
Selector string `json:"selector"` // Selector string.
2017-01-24 15:09:23 +00:00
}
// QuerySelector executes querySelector on a given node.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to query upon.
2017-01-24 15:09:23 +00:00
// selector - Selector string.
2017-01-26 07:28:34 +00:00
func QuerySelector(nodeID cdp.NodeID, selector string) *QuerySelectorParams {
2017-01-24 15:09:23 +00:00
return &QuerySelectorParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
Selector: selector,
}
}
// QuerySelectorReturns return values.
type QuerySelectorReturns struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Query selector result.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.querySelector against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-01-26 07:28:34 +00:00
// nodeID - Query selector result.
func (p *QuerySelectorParams) Do(ctxt context.Context, h cdp.Handler) (nodeID cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return 0, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMQuerySelector, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r QuerySelectorReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeID, nil
case error:
return 0, v
}
case <-ctxt.Done():
return 0, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// QuerySelectorAllParams executes querySelectorAll on a given node.
type QuerySelectorAllParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to query upon.
Selector string `json:"selector"` // Selector string.
2017-01-24 15:09:23 +00:00
}
// QuerySelectorAll executes querySelectorAll on a given node.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to query upon.
2017-01-24 15:09:23 +00:00
// selector - Selector string.
2017-01-26 07:28:34 +00:00
func QuerySelectorAll(nodeID cdp.NodeID, selector string) *QuerySelectorAllParams {
2017-01-24 15:09:23 +00:00
return &QuerySelectorAllParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
Selector: selector,
}
}
// QuerySelectorAllReturns return values.
type QuerySelectorAllReturns struct {
2017-01-26 07:28:34 +00:00
NodeIds []cdp.NodeID `json:"nodeIds,omitempty"` // Query selector result.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.querySelectorAll against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// nodeIds - Query selector result.
func (p *QuerySelectorAllParams) Do(ctxt context.Context, h cdp.Handler) (nodeIds []cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMQuerySelectorAll, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r QuerySelectorAllReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeIds, nil
case error:
return nil, v
}
case <-ctxt.Done():
return nil, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SetNodeNameParams sets node name for a node with given id.
type SetNodeNameParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to set name for.
Name string `json:"name"` // New node's name.
2017-01-24 15:09:23 +00:00
}
// SetNodeName sets node name for a node with given id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to set name for.
2017-01-24 15:09:23 +00:00
// name - New node's name.
2017-01-26 07:28:34 +00:00
func SetNodeName(nodeID cdp.NodeID, name string) *SetNodeNameParams {
2017-01-24 15:09:23 +00:00
return &SetNodeNameParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
Name: name,
}
}
// SetNodeNameReturns return values.
type SetNodeNameReturns struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId,omitempty"` // New node's id.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.setNodeName against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-01-26 07:28:34 +00:00
// nodeID - New node's id.
func (p *SetNodeNameParams) Do(ctxt context.Context, h cdp.Handler) (nodeID cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return 0, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMSetNodeName, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r SetNodeNameReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeID, nil
case error:
return 0, v
}
case <-ctxt.Done():
return 0, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SetNodeValueParams sets node value for a node with given id.
type SetNodeValueParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to set value for.
Value string `json:"value"` // New node's value.
2017-01-24 15:09:23 +00:00
}
// SetNodeValue sets node value for a node with given id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to set value for.
2017-01-24 15:09:23 +00:00
// value - New node's value.
2017-01-26 07:28:34 +00:00
func SetNodeValue(nodeID cdp.NodeID, value string) *SetNodeValueParams {
2017-01-24 15:09:23 +00:00
return &SetNodeValueParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
Value: value,
}
}
// Do executes DOM.setNodeValue against the provided context and
// target handler.
func (p *SetNodeValueParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMSetNodeValue, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// RemoveNodeParams removes node with given id.
type RemoveNodeParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to remove.
2017-01-24 15:09:23 +00:00
}
// RemoveNode removes node with given id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to remove.
func RemoveNode(nodeID cdp.NodeID) *RemoveNodeParams {
2017-01-24 15:09:23 +00:00
return &RemoveNodeParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// Do executes DOM.removeNode against the provided context and
// target handler.
func (p *RemoveNodeParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMRemoveNode, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SetAttributeValueParams sets attribute for an element with given id.
type SetAttributeValueParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the element to set attribute for.
Name string `json:"name"` // Attribute name.
Value string `json:"value"` // Attribute value.
2017-01-24 15:09:23 +00:00
}
// SetAttributeValue sets attribute for an element with given id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the element to set attribute for.
2017-01-24 15:09:23 +00:00
// name - Attribute name.
// value - Attribute value.
2017-01-26 07:28:34 +00:00
func SetAttributeValue(nodeID cdp.NodeID, name string, value string) *SetAttributeValueParams {
2017-01-24 15:09:23 +00:00
return &SetAttributeValueParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
Name: name,
Value: value,
}
}
// Do executes DOM.setAttributeValue against the provided context and
// target handler.
func (p *SetAttributeValueParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMSetAttributeValue, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SetAttributesAsTextParams sets attributes on element with given id. This
// method is useful when user edits some existing attribute value and types in
// several attribute name/value pairs.
type SetAttributesAsTextParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the element to set attributes for.
Text string `json:"text"` // Text with a number of attributes. Will parse this text using HTML parser.
Name string `json:"name,omitempty"` // Attribute name to replace with new attributes derived from text in case text parsed successfully.
2017-01-24 15:09:23 +00:00
}
// SetAttributesAsText sets attributes on element with given id. This method
// is useful when user edits some existing attribute value and types in several
// attribute name/value pairs.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the element to set attributes for.
2017-01-24 15:09:23 +00:00
// text - Text with a number of attributes. Will parse this text using HTML parser.
2017-01-26 07:28:34 +00:00
func SetAttributesAsText(nodeID cdp.NodeID, text string) *SetAttributesAsTextParams {
2017-01-24 15:09:23 +00:00
return &SetAttributesAsTextParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
Text: text,
}
}
// WithName attribute name to replace with new attributes derived from text
// in case text parsed successfully.
func (p SetAttributesAsTextParams) WithName(name string) *SetAttributesAsTextParams {
p.Name = name
return &p
}
// Do executes DOM.setAttributesAsText against the provided context and
// target handler.
func (p *SetAttributesAsTextParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMSetAttributesAsText, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// RemoveAttributeParams removes attribute with given name from an element
// with given id.
type RemoveAttributeParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the element to remove attribute from.
Name string `json:"name"` // Name of the attribute to remove.
2017-01-24 15:09:23 +00:00
}
// RemoveAttribute removes attribute with given name from an element with
// given id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the element to remove attribute from.
2017-01-24 15:09:23 +00:00
// name - Name of the attribute to remove.
2017-01-26 07:28:34 +00:00
func RemoveAttribute(nodeID cdp.NodeID, name string) *RemoveAttributeParams {
2017-01-24 15:09:23 +00:00
return &RemoveAttributeParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
Name: name,
}
}
// Do executes DOM.removeAttribute against the provided context and
// target handler.
func (p *RemoveAttributeParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMRemoveAttribute, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// GetOuterHTMLParams returns node's HTML markup.
type GetOuterHTMLParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to get markup for.
2017-01-24 15:09:23 +00:00
}
// GetOuterHTML returns node's HTML markup.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to get markup for.
func GetOuterHTML(nodeID cdp.NodeID) *GetOuterHTMLParams {
2017-01-24 15:09:23 +00:00
return &GetOuterHTMLParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// GetOuterHTMLReturns return values.
type GetOuterHTMLReturns struct {
OuterHTML string `json:"outerHTML,omitempty"` // Outer HTML markup.
}
// Do executes DOM.getOuterHTML against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// outerHTML - Outer HTML markup.
func (p *GetOuterHTMLParams) Do(ctxt context.Context, h cdp.Handler) (outerHTML string, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return "", err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMGetOuterHTML, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return "", cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetOuterHTMLReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return "", cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.OuterHTML, nil
case error:
return "", v
}
case <-ctxt.Done():
return "", ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return "", cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SetOuterHTMLParams sets node HTML markup, returns new node id.
type SetOuterHTMLParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to set markup for.
OuterHTML string `json:"outerHTML"` // Outer HTML markup to set.
2017-01-24 15:09:23 +00:00
}
// SetOuterHTML sets node HTML markup, returns new node id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to set markup for.
2017-01-24 15:09:23 +00:00
// outerHTML - Outer HTML markup to set.
2017-01-26 07:28:34 +00:00
func SetOuterHTML(nodeID cdp.NodeID, outerHTML string) *SetOuterHTMLParams {
2017-01-24 15:09:23 +00:00
return &SetOuterHTMLParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
OuterHTML: outerHTML,
}
}
// Do executes DOM.setOuterHTML against the provided context and
// target handler.
func (p *SetOuterHTMLParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMSetOuterHTML, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// PerformSearchParams searches for a given string in the DOM tree. Use
// getSearchResults to access search results or cancelSearch to end this search
// session.
type PerformSearchParams struct {
Query string `json:"query"` // Plain text or query selector or XPath search query.
IncludeUserAgentShadowDOM bool `json:"includeUserAgentShadowDOM,omitempty"` // True to search in user agent shadow DOM.
}
// PerformSearch searches for a given string in the DOM tree. Use
// getSearchResults to access search results or cancelSearch to end this search
// session.
//
// parameters:
// query - Plain text or query selector or XPath search query.
func PerformSearch(query string) *PerformSearchParams {
return &PerformSearchParams{
Query: query,
}
}
// WithIncludeUserAgentShadowDOM true to search in user agent shadow DOM.
func (p PerformSearchParams) WithIncludeUserAgentShadowDOM(includeUserAgentShadowDOM bool) *PerformSearchParams {
p.IncludeUserAgentShadowDOM = includeUserAgentShadowDOM
return &p
}
// PerformSearchReturns return values.
type PerformSearchReturns struct {
SearchID string `json:"searchId,omitempty"` // Unique search session identifier.
ResultCount int64 `json:"resultCount,omitempty"` // Number of search results.
}
// Do executes DOM.performSearch against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-01-26 07:28:34 +00:00
// searchID - Unique search session identifier.
2017-01-24 15:09:23 +00:00
// resultCount - Number of search results.
func (p *PerformSearchParams) Do(ctxt context.Context, h cdp.Handler) (searchID string, resultCount int64, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return "", 0, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMPerformSearch, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return "", 0, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r PerformSearchReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return "", 0, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.SearchID, r.ResultCount, nil
case error:
return "", 0, v
}
case <-ctxt.Done():
return "", 0, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return "", 0, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// GetSearchResultsParams returns search results from given fromIndex to
// given toIndex from the sarch with the given identifier.
type GetSearchResultsParams struct {
SearchID string `json:"searchId"` // Unique search session identifier.
FromIndex int64 `json:"fromIndex"` // Start index of the search result to be returned.
ToIndex int64 `json:"toIndex"` // End index of the search result to be returned.
}
// GetSearchResults returns search results from given fromIndex to given
// toIndex from the sarch with the given identifier.
//
// parameters:
2017-01-26 07:28:34 +00:00
// searchID - Unique search session identifier.
2017-01-24 15:09:23 +00:00
// fromIndex - Start index of the search result to be returned.
// toIndex - End index of the search result to be returned.
2017-01-26 07:28:34 +00:00
func GetSearchResults(searchID string, fromIndex int64, toIndex int64) *GetSearchResultsParams {
2017-01-24 15:09:23 +00:00
return &GetSearchResultsParams{
2017-01-26 07:28:34 +00:00
SearchID: searchID,
2017-01-24 15:09:23 +00:00
FromIndex: fromIndex,
ToIndex: toIndex,
}
}
// GetSearchResultsReturns return values.
type GetSearchResultsReturns struct {
2017-01-26 07:28:34 +00:00
NodeIds []cdp.NodeID `json:"nodeIds,omitempty"` // Ids of the search result nodes.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.getSearchResults against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// nodeIds - Ids of the search result nodes.
func (p *GetSearchResultsParams) Do(ctxt context.Context, h cdp.Handler) (nodeIds []cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMGetSearchResults, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetSearchResultsReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeIds, nil
case error:
return nil, v
}
case <-ctxt.Done():
return nil, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// DiscardSearchResultsParams discards search results from the session with
// the given id. getSearchResults should no longer be called for that search.
type DiscardSearchResultsParams struct {
SearchID string `json:"searchId"` // Unique search session identifier.
}
// DiscardSearchResults discards search results from the session with the
// given id. getSearchResults should no longer be called for that search.
//
// parameters:
2017-01-26 07:28:34 +00:00
// searchID - Unique search session identifier.
func DiscardSearchResults(searchID string) *DiscardSearchResultsParams {
2017-01-24 15:09:23 +00:00
return &DiscardSearchResultsParams{
2017-01-26 07:28:34 +00:00
SearchID: searchID,
2017-01-24 15:09:23 +00:00
}
}
// Do executes DOM.discardSearchResults against the provided context and
// target handler.
func (p *DiscardSearchResultsParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMDiscardSearchResults, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// RequestNodeParams requests that the node is sent to the caller given the
// JavaScript node object reference. All nodes that form the path from the node
// to the root are also sent to the client as a series of setChildNodes
// notifications.
type RequestNodeParams struct {
ObjectID runtime.RemoteObjectID `json:"objectId"` // JavaScript object id to convert into node.
}
// RequestNode requests that the node is sent to the caller given the
// JavaScript node object reference. All nodes that form the path from the node
// to the root are also sent to the client as a series of setChildNodes
// notifications.
//
// parameters:
2017-01-26 07:28:34 +00:00
// objectID - JavaScript object id to convert into node.
func RequestNode(objectID runtime.RemoteObjectID) *RequestNodeParams {
2017-01-24 15:09:23 +00:00
return &RequestNodeParams{
2017-01-26 07:28:34 +00:00
ObjectID: objectID,
2017-01-24 15:09:23 +00:00
}
}
// RequestNodeReturns return values.
type RequestNodeReturns struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Node id for given object.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.requestNode against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-01-26 07:28:34 +00:00
// nodeID - Node id for given object.
func (p *RequestNodeParams) Do(ctxt context.Context, h cdp.Handler) (nodeID cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return 0, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMRequestNode, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r RequestNodeReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeID, nil
case error:
return 0, v
}
case <-ctxt.Done():
return 0, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SetInspectModeParams enters the 'inspect' mode. In this mode, elements
// that user is hovering over are highlighted. Backend then generates
// 'inspectNodeRequested' event upon element selection.
type SetInspectModeParams struct {
Mode InspectMode `json:"mode"` // Set an inspection mode.
HighlightConfig *HighlightConfig `json:"highlightConfig,omitempty"` // A descriptor for the highlight appearance of hovered-over nodes. May be omitted if enabled == false.
}
// SetInspectMode enters the 'inspect' mode. In this mode, elements that user
// is hovering over are highlighted. Backend then generates
// 'inspectNodeRequested' event upon element selection.
//
// parameters:
// mode - Set an inspection mode.
func SetInspectMode(mode InspectMode) *SetInspectModeParams {
return &SetInspectModeParams{
Mode: mode,
}
}
// WithHighlightConfig a descriptor for the highlight appearance of
// hovered-over nodes. May be omitted if enabled == false.
func (p SetInspectModeParams) WithHighlightConfig(highlightConfig *HighlightConfig) *SetInspectModeParams {
p.HighlightConfig = highlightConfig
return &p
}
// Do executes DOM.setInspectMode against the provided context and
// target handler.
func (p *SetInspectModeParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMSetInspectMode, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// HighlightRectParams highlights given rectangle. Coordinates are absolute
// with respect to the main frame viewport.
type HighlightRectParams struct {
2017-01-26 07:28:34 +00:00
X int64 `json:"x"` // X coordinate
Y int64 `json:"y"` // Y coordinate
Width int64 `json:"width"` // Rectangle width
Height int64 `json:"height"` // Rectangle height
Color *cdp.RGBA `json:"color,omitempty"` // The highlight fill color (default: transparent).
OutlineColor *cdp.RGBA `json:"outlineColor,omitempty"` // The highlight outline color (default: transparent).
2017-01-24 15:09:23 +00:00
}
// HighlightRect highlights given rectangle. Coordinates are absolute with
// respect to the main frame viewport.
//
// parameters:
// x - X coordinate
// y - Y coordinate
// width - Rectangle width
// height - Rectangle height
func HighlightRect(x int64, y int64, width int64, height int64) *HighlightRectParams {
return &HighlightRectParams{
X: x,
Y: y,
Width: width,
Height: height,
}
}
// WithColor the highlight fill color (default: transparent).
2017-01-26 07:28:34 +00:00
func (p HighlightRectParams) WithColor(color *cdp.RGBA) *HighlightRectParams {
2017-01-24 15:09:23 +00:00
p.Color = color
return &p
}
// WithOutlineColor the highlight outline color (default: transparent).
2017-01-26 07:28:34 +00:00
func (p HighlightRectParams) WithOutlineColor(outlineColor *cdp.RGBA) *HighlightRectParams {
2017-01-24 15:09:23 +00:00
p.OutlineColor = outlineColor
return &p
}
// Do executes DOM.highlightRect against the provided context and
// target handler.
func (p *HighlightRectParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMHighlightRect, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// HighlightQuadParams highlights given quad. Coordinates are absolute with
// respect to the main frame viewport.
type HighlightQuadParams struct {
2017-01-26 07:28:34 +00:00
Quad Quad `json:"quad"` // Quad to highlight
Color *cdp.RGBA `json:"color,omitempty"` // The highlight fill color (default: transparent).
OutlineColor *cdp.RGBA `json:"outlineColor,omitempty"` // The highlight outline color (default: transparent).
2017-01-24 15:09:23 +00:00
}
// HighlightQuad highlights given quad. Coordinates are absolute with respect
// to the main frame viewport.
//
// parameters:
// quad - Quad to highlight
func HighlightQuad(quad Quad) *HighlightQuadParams {
return &HighlightQuadParams{
Quad: quad,
}
}
// WithColor the highlight fill color (default: transparent).
2017-01-26 07:28:34 +00:00
func (p HighlightQuadParams) WithColor(color *cdp.RGBA) *HighlightQuadParams {
2017-01-24 15:09:23 +00:00
p.Color = color
return &p
}
// WithOutlineColor the highlight outline color (default: transparent).
2017-01-26 07:28:34 +00:00
func (p HighlightQuadParams) WithOutlineColor(outlineColor *cdp.RGBA) *HighlightQuadParams {
2017-01-24 15:09:23 +00:00
p.OutlineColor = outlineColor
return &p
}
// Do executes DOM.highlightQuad against the provided context and
// target handler.
func (p *HighlightQuadParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMHighlightQuad, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// HighlightNodeParams highlights DOM node with given id or with the given
// JavaScript object wrapper. Either nodeId or objectId must be specified.
type HighlightNodeParams struct {
HighlightConfig *HighlightConfig `json:"highlightConfig"` // A descriptor for the highlight appearance.
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node to highlight.
BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node to highlight.
2017-01-24 15:09:23 +00:00
ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node to be highlighted.
}
// HighlightNode highlights DOM node with given id or with the given
// JavaScript object wrapper. Either nodeId or objectId must be specified.
//
// parameters:
// highlightConfig - A descriptor for the highlight appearance.
func HighlightNode(highlightConfig *HighlightConfig) *HighlightNodeParams {
return &HighlightNodeParams{
HighlightConfig: highlightConfig,
}
}
// WithNodeID identifier of the node to highlight.
2017-01-26 07:28:34 +00:00
func (p HighlightNodeParams) WithNodeID(nodeID cdp.NodeID) *HighlightNodeParams {
p.NodeID = nodeID
2017-01-24 15:09:23 +00:00
return &p
}
// WithBackendNodeID identifier of the backend node to highlight.
2017-01-26 07:28:34 +00:00
func (p HighlightNodeParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *HighlightNodeParams {
p.BackendNodeID = backendNodeID
2017-01-24 15:09:23 +00:00
return &p
}
// WithObjectID javaScript object id of the node to be highlighted.
2017-01-26 07:28:34 +00:00
func (p HighlightNodeParams) WithObjectID(objectID runtime.RemoteObjectID) *HighlightNodeParams {
p.ObjectID = objectID
2017-01-24 15:09:23 +00:00
return &p
}
// Do executes DOM.highlightNode against the provided context and
// target handler.
func (p *HighlightNodeParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMHighlightNode, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// HideHighlightParams hides DOM node highlight.
type HideHighlightParams struct{}
// HideHighlight hides DOM node highlight.
func HideHighlight() *HideHighlightParams {
return &HideHighlightParams{}
}
// Do executes DOM.hideHighlight against the provided context and
// target handler.
func (p *HideHighlightParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMHideHighlight, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// HighlightFrameParams highlights owner element of the frame with given id.
type HighlightFrameParams struct {
2017-01-26 07:28:34 +00:00
FrameID cdp.FrameID `json:"frameId"` // Identifier of the frame to highlight.
ContentColor *cdp.RGBA `json:"contentColor,omitempty"` // The content box highlight fill color (default: transparent).
ContentOutlineColor *cdp.RGBA `json:"contentOutlineColor,omitempty"` // The content box highlight outline color (default: transparent).
2017-01-24 15:09:23 +00:00
}
// HighlightFrame highlights owner element of the frame with given id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// frameID - Identifier of the frame to highlight.
func HighlightFrame(frameID cdp.FrameID) *HighlightFrameParams {
2017-01-24 15:09:23 +00:00
return &HighlightFrameParams{
2017-01-26 07:28:34 +00:00
FrameID: frameID,
2017-01-24 15:09:23 +00:00
}
}
// WithContentColor the content box highlight fill color (default:
// transparent).
2017-01-26 07:28:34 +00:00
func (p HighlightFrameParams) WithContentColor(contentColor *cdp.RGBA) *HighlightFrameParams {
2017-01-24 15:09:23 +00:00
p.ContentColor = contentColor
return &p
}
// WithContentOutlineColor the content box highlight outline color (default:
// transparent).
2017-01-26 07:28:34 +00:00
func (p HighlightFrameParams) WithContentOutlineColor(contentOutlineColor *cdp.RGBA) *HighlightFrameParams {
2017-01-24 15:09:23 +00:00
p.ContentOutlineColor = contentOutlineColor
return &p
}
// Do executes DOM.highlightFrame against the provided context and
// target handler.
func (p *HighlightFrameParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMHighlightFrame, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// PushNodeByPathToFrontendParams requests that the node is sent to the
// caller given its path. // FIXME, use XPath.
type PushNodeByPathToFrontendParams struct {
Path string `json:"path"` // Path to node in the proprietary format.
}
// PushNodeByPathToFrontend requests that the node is sent to the caller
// given its path. // FIXME, use XPath.
//
// parameters:
// path - Path to node in the proprietary format.
func PushNodeByPathToFrontend(path string) *PushNodeByPathToFrontendParams {
return &PushNodeByPathToFrontendParams{
Path: path,
}
}
// PushNodeByPathToFrontendReturns return values.
type PushNodeByPathToFrontendReturns struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node for given path.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.pushNodeByPathToFrontend against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node for given path.
func (p *PushNodeByPathToFrontendParams) Do(ctxt context.Context, h cdp.Handler) (nodeID cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return 0, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMPushNodeByPathToFrontend, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r PushNodeByPathToFrontendReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeID, nil
case error:
return 0, v
}
case <-ctxt.Done():
return 0, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// PushNodesByBackendIdsToFrontendParams requests that a batch of nodes is
// sent to the caller given their backend node ids.
type PushNodesByBackendIdsToFrontendParams struct {
2017-01-26 07:28:34 +00:00
BackendNodeIds []cdp.BackendNodeID `json:"backendNodeIds"` // The array of backend node ids.
2017-01-24 15:09:23 +00:00
}
// PushNodesByBackendIdsToFrontend requests that a batch of nodes is sent to
// the caller given their backend node ids.
//
// parameters:
// backendNodeIds - The array of backend node ids.
2017-01-26 07:28:34 +00:00
func PushNodesByBackendIdsToFrontend(backendNodeIds []cdp.BackendNodeID) *PushNodesByBackendIdsToFrontendParams {
2017-01-24 15:09:23 +00:00
return &PushNodesByBackendIdsToFrontendParams{
BackendNodeIds: backendNodeIds,
}
}
// PushNodesByBackendIdsToFrontendReturns return values.
type PushNodesByBackendIdsToFrontendReturns struct {
2017-01-26 07:28:34 +00:00
NodeIds []cdp.NodeID `json:"nodeIds,omitempty"` // The array of ids of pushed nodes that correspond to the backend ids specified in backendNodeIds.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.pushNodesByBackendIdsToFrontend against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// nodeIds - The array of ids of pushed nodes that correspond to the backend ids specified in backendNodeIds.
func (p *PushNodesByBackendIdsToFrontendParams) Do(ctxt context.Context, h cdp.Handler) (nodeIds []cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMPushNodesByBackendIdsToFrontend, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r PushNodesByBackendIdsToFrontendReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeIds, nil
case error:
return nil, v
}
case <-ctxt.Done():
return nil, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SetInspectedNodeParams enables console to refer to the node with given id
// via $x (see Command Line API for more details $x functions).
type SetInspectedNodeParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // DOM node id to be accessible by means of $x command line API.
2017-01-24 15:09:23 +00:00
}
// SetInspectedNode enables console to refer to the node with given id via $x
// (see Command Line API for more details $x functions).
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - DOM node id to be accessible by means of $x command line API.
func SetInspectedNode(nodeID cdp.NodeID) *SetInspectedNodeParams {
2017-01-24 15:09:23 +00:00
return &SetInspectedNodeParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// Do executes DOM.setInspectedNode against the provided context and
// target handler.
func (p *SetInspectedNodeParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMSetInspectedNode, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// ResolveNodeParams resolves JavaScript node object for given node id.
type ResolveNodeParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to resolve.
ObjectGroup string `json:"objectGroup,omitempty"` // Symbolic group name that can be used to release multiple objects.
2017-01-24 15:09:23 +00:00
}
// ResolveNode resolves JavaScript node object for given node id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to resolve.
func ResolveNode(nodeID cdp.NodeID) *ResolveNodeParams {
2017-01-24 15:09:23 +00:00
return &ResolveNodeParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// WithObjectGroup symbolic group name that can be used to release multiple
// objects.
func (p ResolveNodeParams) WithObjectGroup(objectGroup string) *ResolveNodeParams {
p.ObjectGroup = objectGroup
return &p
}
// ResolveNodeReturns return values.
type ResolveNodeReturns struct {
Object *runtime.RemoteObject `json:"object,omitempty"` // JavaScript object wrapper for given node.
}
// Do executes DOM.resolveNode against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// object - JavaScript object wrapper for given node.
func (p *ResolveNodeParams) Do(ctxt context.Context, h cdp.Handler) (object *runtime.RemoteObject, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMResolveNode, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r ResolveNodeReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.Object, nil
case error:
return nil, v
}
case <-ctxt.Done():
return nil, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// GetAttributesParams returns attributes for the specified node.
type GetAttributesParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to retrieve attibutes for.
2017-01-24 15:09:23 +00:00
}
// GetAttributes returns attributes for the specified node.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to retrieve attibutes for.
func GetAttributes(nodeID cdp.NodeID) *GetAttributesParams {
2017-01-24 15:09:23 +00:00
return &GetAttributesParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// GetAttributesReturns return values.
type GetAttributesReturns struct {
Attributes []string `json:"attributes,omitempty"` // An interleaved array of node attribute names and values.
}
// Do executes DOM.getAttributes against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// attributes - An interleaved array of node attribute names and values.
func (p *GetAttributesParams) Do(ctxt context.Context, h cdp.Handler) (attributes []string, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMGetAttributes, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetAttributesReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.Attributes, nil
case error:
return nil, v
}
case <-ctxt.Done():
return nil, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// CopyToParams creates a deep copy of the specified node and places it into
// the target container before the given anchor.
type CopyToParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to copy.
TargetNodeID cdp.NodeID `json:"targetNodeId"` // Id of the element to drop the copy into.
InsertBeforeNodeID cdp.NodeID `json:"insertBeforeNodeId,omitempty"` // Drop the copy before this node (if absent, the copy becomes the last child of targetNodeId).
2017-01-24 15:09:23 +00:00
}
// CopyTo creates a deep copy of the specified node and places it into the
// target container before the given anchor.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to copy.
// targetNodeID - Id of the element to drop the copy into.
func CopyTo(nodeID cdp.NodeID, targetNodeID cdp.NodeID) *CopyToParams {
2017-01-24 15:09:23 +00:00
return &CopyToParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
TargetNodeID: targetNodeID,
2017-01-24 15:09:23 +00:00
}
}
// WithInsertBeforeNodeID drop the copy before this node (if absent, the copy
// becomes the last child of targetNodeId).
2017-01-26 07:28:34 +00:00
func (p CopyToParams) WithInsertBeforeNodeID(insertBeforeNodeID cdp.NodeID) *CopyToParams {
p.InsertBeforeNodeID = insertBeforeNodeID
2017-01-24 15:09:23 +00:00
return &p
}
// CopyToReturns return values.
type CopyToReturns struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node clone.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.copyTo against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node clone.
func (p *CopyToParams) Do(ctxt context.Context, h cdp.Handler) (nodeID cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return 0, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMCopyTo, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r CopyToReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeID, nil
case error:
return 0, v
}
case <-ctxt.Done():
return 0, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// MoveToParams moves node into the new container, places it before the given
// anchor.
type MoveToParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to move.
TargetNodeID cdp.NodeID `json:"targetNodeId"` // Id of the element to drop the moved node into.
InsertBeforeNodeID cdp.NodeID `json:"insertBeforeNodeId,omitempty"` // Drop node before this one (if absent, the moved node becomes the last child of targetNodeId).
2017-01-24 15:09:23 +00:00
}
// MoveTo moves node into the new container, places it before the given
// anchor.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to move.
// targetNodeID - Id of the element to drop the moved node into.
func MoveTo(nodeID cdp.NodeID, targetNodeID cdp.NodeID) *MoveToParams {
2017-01-24 15:09:23 +00:00
return &MoveToParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
TargetNodeID: targetNodeID,
2017-01-24 15:09:23 +00:00
}
}
// WithInsertBeforeNodeID drop node before this one (if absent, the moved
// node becomes the last child of targetNodeId).
2017-01-26 07:28:34 +00:00
func (p MoveToParams) WithInsertBeforeNodeID(insertBeforeNodeID cdp.NodeID) *MoveToParams {
p.InsertBeforeNodeID = insertBeforeNodeID
2017-01-24 15:09:23 +00:00
return &p
}
// MoveToReturns return values.
type MoveToReturns struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId,omitempty"` // New id of the moved node.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.moveTo against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-01-26 07:28:34 +00:00
// nodeID - New id of the moved node.
func (p *MoveToParams) Do(ctxt context.Context, h cdp.Handler) (nodeID cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return 0, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMMoveTo, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r MoveToReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeID, nil
case error:
return 0, v
}
case <-ctxt.Done():
return 0, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// UndoParams undoes the last performed action.
type UndoParams struct{}
// Undo undoes the last performed action.
func Undo() *UndoParams {
return &UndoParams{}
}
// Do executes DOM.undo against the provided context and
// target handler.
func (p *UndoParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMUndo, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// RedoParams re-does the last undone action.
type RedoParams struct{}
// Redo re-does the last undone action.
func Redo() *RedoParams {
return &RedoParams{}
}
// Do executes DOM.redo against the provided context and
// target handler.
func (p *RedoParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMRedo, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// MarkUndoableStateParams marks last undoable state.
type MarkUndoableStateParams struct{}
// MarkUndoableState marks last undoable state.
func MarkUndoableState() *MarkUndoableStateParams {
return &MarkUndoableStateParams{}
}
// Do executes DOM.markUndoableState against the provided context and
// target handler.
func (p *MarkUndoableStateParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMMarkUndoableState, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// FocusParams focuses the given element.
type FocusParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to focus.
2017-01-24 15:09:23 +00:00
}
// Focus focuses the given element.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to focus.
func Focus(nodeID cdp.NodeID) *FocusParams {
2017-01-24 15:09:23 +00:00
return &FocusParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// Do executes DOM.focus against the provided context and
// target handler.
func (p *FocusParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMFocus, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SetFileInputFilesParams sets files for the given file input element.
type SetFileInputFilesParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the file input node to set files for.
Files []string `json:"files"` // Array of file paths to set.
2017-01-24 15:09:23 +00:00
}
// SetFileInputFiles sets files for the given file input element.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the file input node to set files for.
2017-01-24 15:09:23 +00:00
// files - Array of file paths to set.
2017-01-26 07:28:34 +00:00
func SetFileInputFiles(nodeID cdp.NodeID, files []string) *SetFileInputFilesParams {
2017-01-24 15:09:23 +00:00
return &SetFileInputFilesParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
Files: files,
}
}
// Do executes DOM.setFileInputFiles against the provided context and
// target handler.
func (p *SetFileInputFilesParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMSetFileInputFiles, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
return ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// GetBoxModelParams returns boxes for the currently selected nodes.
type GetBoxModelParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to get box model for.
2017-01-24 15:09:23 +00:00
}
// GetBoxModel returns boxes for the currently selected nodes.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to get box model for.
func GetBoxModel(nodeID cdp.NodeID) *GetBoxModelParams {
2017-01-24 15:09:23 +00:00
return &GetBoxModelParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// GetBoxModelReturns return values.
type GetBoxModelReturns struct {
Model *BoxModel `json:"model,omitempty"` // Box model for the node.
}
// Do executes DOM.getBoxModel against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// model - Box model for the node.
func (p *GetBoxModelParams) Do(ctxt context.Context, h cdp.Handler) (model *BoxModel, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMGetBoxModel, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetBoxModelReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.Model, nil
case error:
return nil, v
}
case <-ctxt.Done():
return nil, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// GetNodeForLocationParams returns node id at given location.
type GetNodeForLocationParams struct {
X int64 `json:"x"` // X coordinate.
Y int64 `json:"y"` // Y coordinate.
}
// GetNodeForLocation returns node id at given location.
//
// parameters:
// x - X coordinate.
// y - Y coordinate.
func GetNodeForLocation(x int64, y int64) *GetNodeForLocationParams {
return &GetNodeForLocationParams{
X: x,
Y: y,
}
}
// GetNodeForLocationReturns return values.
type GetNodeForLocationReturns struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node at given coordinates.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.getNodeForLocation against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node at given coordinates.
func (p *GetNodeForLocationParams) Do(ctxt context.Context, h cdp.Handler) (nodeID cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return 0, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMGetNodeForLocation, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetNodeForLocationReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeID, nil
case error:
return 0, v
}
case <-ctxt.Done():
return 0, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// GetRelayoutBoundaryParams returns the id of the nearest ancestor that is a
// relayout boundary.
type GetRelayoutBoundaryParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node.
2017-01-24 15:09:23 +00:00
}
// GetRelayoutBoundary returns the id of the nearest ancestor that is a
// relayout boundary.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node.
func GetRelayoutBoundary(nodeID cdp.NodeID) *GetRelayoutBoundaryParams {
2017-01-24 15:09:23 +00:00
return &GetRelayoutBoundaryParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// GetRelayoutBoundaryReturns return values.
type GetRelayoutBoundaryReturns struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Relayout boundary node id for the given node.
2017-01-24 15:09:23 +00:00
}
// Do executes DOM.getRelayoutBoundary against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-01-26 07:28:34 +00:00
// nodeID - Relayout boundary node id for the given node.
func (p *GetRelayoutBoundaryParams) Do(ctxt context.Context, h cdp.Handler) (nodeID cdp.NodeID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return 0, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMGetRelayoutBoundary, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetRelayoutBoundaryReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.NodeID, nil
case error:
return 0, v
}
case <-ctxt.Done():
return 0, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return 0, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// GetHighlightObjectForTestParams for testing.
type GetHighlightObjectForTestParams struct {
2017-01-26 07:28:34 +00:00
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to get highlight object for.
2017-01-24 15:09:23 +00:00
}
// GetHighlightObjectForTest for testing.
//
// parameters:
2017-01-26 07:28:34 +00:00
// nodeID - Id of the node to get highlight object for.
func GetHighlightObjectForTest(nodeID cdp.NodeID) *GetHighlightObjectForTestParams {
2017-01-24 15:09:23 +00:00
return &GetHighlightObjectForTestParams{
2017-01-26 07:28:34 +00:00
NodeID: nodeID,
2017-01-24 15:09:23 +00:00
}
}
// GetHighlightObjectForTestReturns return values.
type GetHighlightObjectForTestReturns struct {
Highlight easyjson.RawMessage `json:"highlight,omitempty"`
}
// Do executes DOM.getHighlightObjectForTest against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// highlight - Highlight data for the node.
func (p *GetHighlightObjectForTestParams) Do(ctxt context.Context, h cdp.Handler) (highlight easyjson.RawMessage, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandDOMGetHighlightObjectForTest, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetHighlightObjectForTestReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.Highlight, nil
case error:
return nil, v
}
case <-ctxt.Done():
return nil, ctxt.Err()
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}