/
dom.go
1947 lines (1706 loc) · 66.3 KB
/
dom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Package dom provides the Chrome DevTools Protocol
// commands, types, and events for the DOM domain.
//
// 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. Note that iframe owner elements will return corresponding document
// elements as their child nodes.
//
// Generated by the cdproto-gen command.
package dom
// Code generated by cdproto-gen. DO NOT EDIT.
import (
"context"
"github.com/chromedp/cdproto/cdp"
"github.com/chromedp/cdproto/runtime"
)
// CollectClassNamesFromSubtreeParams collects class names for the node with
// given id and all of it's child nodes.
type CollectClassNamesFromSubtreeParams struct {
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to collect class names.
}
// CollectClassNamesFromSubtree collects class names for the node with given
// id and all of it's child nodes.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-collectClassNamesFromSubtree
//
// parameters:
//
// nodeID - Id of the node to collect class names.
func CollectClassNamesFromSubtree(nodeID cdp.NodeID) *CollectClassNamesFromSubtreeParams {
return &CollectClassNamesFromSubtreeParams{
NodeID: nodeID,
}
}
// CollectClassNamesFromSubtreeReturns return values.
type CollectClassNamesFromSubtreeReturns struct {
ClassNames []string `json:"classNames,omitempty"` // Class name list.
}
// Do executes DOM.collectClassNamesFromSubtree against the provided context.
//
// returns:
//
// classNames - Class name list.
func (p *CollectClassNamesFromSubtreeParams) Do(ctx context.Context) (classNames []string, err error) {
// execute
var res CollectClassNamesFromSubtreeReturns
err = cdp.Execute(ctx, CommandCollectClassNamesFromSubtree, p, &res)
if err != nil {
return nil, err
}
return res.ClassNames, nil
}
// CopyToParams creates a deep copy of the specified node and places it into
// the target container before the given anchor.
type CopyToParams struct {
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).
}
// CopyTo creates a deep copy of the specified node and places it into the
// target container before the given anchor.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-copyTo
//
// parameters:
//
// 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 {
return &CopyToParams{
NodeID: nodeID,
TargetNodeID: targetNodeID,
}
}
// WithInsertBeforeNodeID drop the copy before this node (if absent, the copy
// becomes the last child of targetNodeId).
func (p CopyToParams) WithInsertBeforeNodeID(insertBeforeNodeID cdp.NodeID) *CopyToParams {
p.InsertBeforeNodeID = insertBeforeNodeID
return &p
}
// CopyToReturns return values.
type CopyToReturns struct {
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node clone.
}
// Do executes DOM.copyTo against the provided context.
//
// returns:
//
// nodeID - Id of the node clone.
func (p *CopyToParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
// execute
var res CopyToReturns
err = cdp.Execute(ctx, CommandCopyTo, p, &res)
if err != nil {
return 0, err
}
return res.NodeID, nil
}
// DescribeNodeParams describes node given its id, does not require domain to
// be enabled. Does not start tracking any objects, can be used for automation.
type DescribeNodeParams struct {
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
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).
}
// DescribeNode describes node given its id, does not require domain to be
// enabled. Does not start tracking any objects, can be used for automation.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-describeNode
//
// parameters:
func DescribeNode() *DescribeNodeParams {
return &DescribeNodeParams{}
}
// WithNodeID identifier of the node.
func (p DescribeNodeParams) WithNodeID(nodeID cdp.NodeID) *DescribeNodeParams {
p.NodeID = nodeID
return &p
}
// WithBackendNodeID identifier of the backend node.
func (p DescribeNodeParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *DescribeNodeParams {
p.BackendNodeID = backendNodeID
return &p
}
// WithObjectID JavaScript object id of the node wrapper.
func (p DescribeNodeParams) WithObjectID(objectID runtime.RemoteObjectID) *DescribeNodeParams {
p.ObjectID = objectID
return &p
}
// 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 DescribeNodeParams) WithDepth(depth int64) *DescribeNodeParams {
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 DescribeNodeParams) WithPierce(pierce bool) *DescribeNodeParams {
p.Pierce = pierce
return &p
}
// DescribeNodeReturns return values.
type DescribeNodeReturns struct {
Node *cdp.Node `json:"node,omitempty"` // Node description.
}
// Do executes DOM.describeNode against the provided context.
//
// returns:
//
// node - Node description.
func (p *DescribeNodeParams) Do(ctx context.Context) (node *cdp.Node, err error) {
// execute
var res DescribeNodeReturns
err = cdp.Execute(ctx, CommandDescribeNode, p, &res)
if err != nil {
return nil, err
}
return res.Node, nil
}
// ScrollIntoViewIfNeededParams scrolls the specified rect of the given node
// into view if not already visible. Note: exactly one between nodeId,
// backendNodeId and objectId should be passed to identify the node.
type ScrollIntoViewIfNeededParams struct {
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
Rect *Rect `json:"rect,omitempty"` // The rect to be scrolled into view, relative to the node's border box, in CSS pixels. When omitted, center of the node will be used, similar to Element.scrollIntoView.
}
// ScrollIntoViewIfNeeded scrolls the specified rect of the given node into
// view if not already visible. Note: exactly one between nodeId, backendNodeId
// and objectId should be passed to identify the node.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-scrollIntoViewIfNeeded
//
// parameters:
func ScrollIntoViewIfNeeded() *ScrollIntoViewIfNeededParams {
return &ScrollIntoViewIfNeededParams{}
}
// WithNodeID identifier of the node.
func (p ScrollIntoViewIfNeededParams) WithNodeID(nodeID cdp.NodeID) *ScrollIntoViewIfNeededParams {
p.NodeID = nodeID
return &p
}
// WithBackendNodeID identifier of the backend node.
func (p ScrollIntoViewIfNeededParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *ScrollIntoViewIfNeededParams {
p.BackendNodeID = backendNodeID
return &p
}
// WithObjectID JavaScript object id of the node wrapper.
func (p ScrollIntoViewIfNeededParams) WithObjectID(objectID runtime.RemoteObjectID) *ScrollIntoViewIfNeededParams {
p.ObjectID = objectID
return &p
}
// WithRect the rect to be scrolled into view, relative to the node's border
// box, in CSS pixels. When omitted, center of the node will be used, similar to
// Element.scrollIntoView.
func (p ScrollIntoViewIfNeededParams) WithRect(rect *Rect) *ScrollIntoViewIfNeededParams {
p.Rect = rect
return &p
}
// Do executes DOM.scrollIntoViewIfNeeded against the provided context.
func (p *ScrollIntoViewIfNeededParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandScrollIntoViewIfNeeded, p, nil)
}
// DisableParams disables DOM agent for the given page.
type DisableParams struct{}
// Disable disables DOM agent for the given page.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-disable
func Disable() *DisableParams {
return &DisableParams{}
}
// Do executes DOM.disable against the provided context.
func (p *DisableParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandDisable, nil, nil)
}
// 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.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-discardSearchResults
//
// parameters:
//
// searchID - Unique search session identifier.
func DiscardSearchResults(searchID string) *DiscardSearchResultsParams {
return &DiscardSearchResultsParams{
SearchID: searchID,
}
}
// Do executes DOM.discardSearchResults against the provided context.
func (p *DiscardSearchResultsParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandDiscardSearchResults, p, nil)
}
// EnableParams enables DOM agent for the given page.
type EnableParams struct {
IncludeWhitespace EnableIncludeWhitespace `json:"includeWhitespace,omitempty"` // Whether to include whitespaces in the children array of returned Nodes.
}
// Enable enables DOM agent for the given page.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-enable
//
// parameters:
func Enable() *EnableParams {
return &EnableParams{}
}
// WithIncludeWhitespace whether to include whitespaces in the children array
// of returned Nodes.
func (p EnableParams) WithIncludeWhitespace(includeWhitespace EnableIncludeWhitespace) *EnableParams {
p.IncludeWhitespace = includeWhitespace
return &p
}
// Do executes DOM.enable against the provided context.
func (p *EnableParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandEnable, p, nil)
}
// FocusParams focuses the given element.
type FocusParams struct {
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
}
// Focus focuses the given element.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-focus
//
// parameters:
func Focus() *FocusParams {
return &FocusParams{}
}
// WithNodeID identifier of the node.
func (p FocusParams) WithNodeID(nodeID cdp.NodeID) *FocusParams {
p.NodeID = nodeID
return &p
}
// WithBackendNodeID identifier of the backend node.
func (p FocusParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *FocusParams {
p.BackendNodeID = backendNodeID
return &p
}
// WithObjectID JavaScript object id of the node wrapper.
func (p FocusParams) WithObjectID(objectID runtime.RemoteObjectID) *FocusParams {
p.ObjectID = objectID
return &p
}
// Do executes DOM.focus against the provided context.
func (p *FocusParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandFocus, p, nil)
}
// GetAttributesParams returns attributes for the specified node.
type GetAttributesParams struct {
NodeID cdp.NodeID `json:"nodeId"` // Id of the node to retrieve attributes for.
}
// GetAttributes returns attributes for the specified node.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getAttributes
//
// parameters:
//
// nodeID - Id of the node to retrieve attributes for.
func GetAttributes(nodeID cdp.NodeID) *GetAttributesParams {
return &GetAttributesParams{
NodeID: nodeID,
}
}
// 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.
//
// returns:
//
// attributes - An interleaved array of node attribute names and values.
func (p *GetAttributesParams) Do(ctx context.Context) (attributes []string, err error) {
// execute
var res GetAttributesReturns
err = cdp.Execute(ctx, CommandGetAttributes, p, &res)
if err != nil {
return nil, err
}
return res.Attributes, nil
}
// GetBoxModelParams returns boxes for the given node.
type GetBoxModelParams struct {
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
}
// GetBoxModel returns boxes for the given node.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getBoxModel
//
// parameters:
func GetBoxModel() *GetBoxModelParams {
return &GetBoxModelParams{}
}
// WithNodeID identifier of the node.
func (p GetBoxModelParams) WithNodeID(nodeID cdp.NodeID) *GetBoxModelParams {
p.NodeID = nodeID
return &p
}
// WithBackendNodeID identifier of the backend node.
func (p GetBoxModelParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *GetBoxModelParams {
p.BackendNodeID = backendNodeID
return &p
}
// WithObjectID JavaScript object id of the node wrapper.
func (p GetBoxModelParams) WithObjectID(objectID runtime.RemoteObjectID) *GetBoxModelParams {
p.ObjectID = objectID
return &p
}
// GetBoxModelReturns return values.
type GetBoxModelReturns struct {
Model *BoxModel `json:"model,omitempty"` // Box model for the node.
}
// Do executes DOM.getBoxModel against the provided context.
//
// returns:
//
// model - Box model for the node.
func (p *GetBoxModelParams) Do(ctx context.Context) (model *BoxModel, err error) {
// execute
var res GetBoxModelReturns
err = cdp.Execute(ctx, CommandGetBoxModel, p, &res)
if err != nil {
return nil, err
}
return res.Model, nil
}
// GetContentQuadsParams returns quads that describe node position on the
// page. This method might return multiple quads for inline nodes.
type GetContentQuadsParams struct {
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
}
// GetContentQuads returns quads that describe node position on the page.
// This method might return multiple quads for inline nodes.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getContentQuads
//
// parameters:
func GetContentQuads() *GetContentQuadsParams {
return &GetContentQuadsParams{}
}
// WithNodeID identifier of the node.
func (p GetContentQuadsParams) WithNodeID(nodeID cdp.NodeID) *GetContentQuadsParams {
p.NodeID = nodeID
return &p
}
// WithBackendNodeID identifier of the backend node.
func (p GetContentQuadsParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *GetContentQuadsParams {
p.BackendNodeID = backendNodeID
return &p
}
// WithObjectID JavaScript object id of the node wrapper.
func (p GetContentQuadsParams) WithObjectID(objectID runtime.RemoteObjectID) *GetContentQuadsParams {
p.ObjectID = objectID
return &p
}
// GetContentQuadsReturns return values.
type GetContentQuadsReturns struct {
Quads []Quad `json:"quads,omitempty"` // Quads that describe node layout relative to viewport.
}
// Do executes DOM.getContentQuads against the provided context.
//
// returns:
//
// quads - Quads that describe node layout relative to viewport.
func (p *GetContentQuadsParams) Do(ctx context.Context) (quads []Quad, err error) {
// execute
var res GetContentQuadsReturns
err = cdp.Execute(ctx, CommandGetContentQuads, p, &res)
if err != nil {
return nil, err
}
return res.Quads, nil
}
// GetDocumentParams returns the root DOM node (and optionally the subtree)
// to the caller. Implicitly enables the DOM domain events for the current
// target.
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. Implicitly enables the DOM domain events for the current target.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getDocument
//
// 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 {
Root *cdp.Node `json:"root,omitempty"` // Resulting node.
}
// Do executes DOM.getDocument against the provided context.
//
// returns:
//
// root - Resulting node.
func (p *GetDocumentParams) Do(ctx context.Context) (root *cdp.Node, err error) {
// execute
var res GetDocumentReturns
err = cdp.Execute(ctx, CommandGetDocument, p, &res)
if err != nil {
return nil, err
}
return res.Root, nil
}
// GetNodesForSubtreeByStyleParams finds nodes with a given computed style in
// a subtree.
type GetNodesForSubtreeByStyleParams struct {
NodeID cdp.NodeID `json:"nodeId"` // Node ID pointing to the root of a subtree.
ComputedStyles []*CSSComputedStyleProperty `json:"computedStyles"` // The style to filter nodes by (includes nodes if any of properties matches).
Pierce bool `json:"pierce,omitempty"` // Whether or not iframes and shadow roots in the same target should be traversed when returning the results (default is false).
}
// GetNodesForSubtreeByStyle finds nodes with a given computed style in a
// subtree.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getNodesForSubtreeByStyle
//
// parameters:
//
// nodeID - Node ID pointing to the root of a subtree.
// computedStyles - The style to filter nodes by (includes nodes if any of properties matches).
func GetNodesForSubtreeByStyle(nodeID cdp.NodeID, computedStyles []*CSSComputedStyleProperty) *GetNodesForSubtreeByStyleParams {
return &GetNodesForSubtreeByStyleParams{
NodeID: nodeID,
ComputedStyles: computedStyles,
}
}
// WithPierce whether or not iframes and shadow roots in the same target
// should be traversed when returning the results (default is false).
func (p GetNodesForSubtreeByStyleParams) WithPierce(pierce bool) *GetNodesForSubtreeByStyleParams {
p.Pierce = pierce
return &p
}
// GetNodesForSubtreeByStyleReturns return values.
type GetNodesForSubtreeByStyleReturns struct {
NodeIDs []cdp.NodeID `json:"nodeIds,omitempty"` // Resulting nodes.
}
// Do executes DOM.getNodesForSubtreeByStyle against the provided context.
//
// returns:
//
// nodeIDs - Resulting nodes.
func (p *GetNodesForSubtreeByStyleParams) Do(ctx context.Context) (nodeIDs []cdp.NodeID, err error) {
// execute
var res GetNodesForSubtreeByStyleReturns
err = cdp.Execute(ctx, CommandGetNodesForSubtreeByStyle, p, &res)
if err != nil {
return nil, err
}
return res.NodeIDs, nil
}
// GetNodeForLocationParams returns node id at given location. Depending on
// whether DOM domain is enabled, nodeId is either returned or not.
type GetNodeForLocationParams struct {
X int64 `json:"x"` // X coordinate.
Y int64 `json:"y"` // Y coordinate.
IncludeUserAgentShadowDOM bool `json:"includeUserAgentShadowDOM,omitempty"` // False to skip to the nearest non-UA shadow root ancestor (default: false).
IgnorePointerEventsNone bool `json:"ignorePointerEventsNone,omitempty"` // Whether to ignore pointer-events: none on elements and hit test them.
}
// GetNodeForLocation returns node id at given location. Depending on whether
// DOM domain is enabled, nodeId is either returned or not.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getNodeForLocation
//
// parameters:
//
// x - X coordinate.
// y - Y coordinate.
func GetNodeForLocation(x int64, y int64) *GetNodeForLocationParams {
return &GetNodeForLocationParams{
X: x,
Y: y,
}
}
// WithIncludeUserAgentShadowDOM false to skip to the nearest non-UA shadow
// root ancestor (default: false).
func (p GetNodeForLocationParams) WithIncludeUserAgentShadowDOM(includeUserAgentShadowDOM bool) *GetNodeForLocationParams {
p.IncludeUserAgentShadowDOM = includeUserAgentShadowDOM
return &p
}
// WithIgnorePointerEventsNone whether to ignore pointer-events: none on
// elements and hit test them.
func (p GetNodeForLocationParams) WithIgnorePointerEventsNone(ignorePointerEventsNone bool) *GetNodeForLocationParams {
p.IgnorePointerEventsNone = ignorePointerEventsNone
return &p
}
// GetNodeForLocationReturns return values.
type GetNodeForLocationReturns struct {
BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Resulting node.
FrameID cdp.FrameID `json:"frameId,omitempty"` // Frame this node belongs to.
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node at given coordinates, only when enabled and requested document.
}
// Do executes DOM.getNodeForLocation against the provided context.
//
// returns:
//
// backendNodeID - Resulting node.
// frameID - Frame this node belongs to.
// nodeID - Id of the node at given coordinates, only when enabled and requested document.
func (p *GetNodeForLocationParams) Do(ctx context.Context) (backendNodeID cdp.BackendNodeID, frameID cdp.FrameID, nodeID cdp.NodeID, err error) {
// execute
var res GetNodeForLocationReturns
err = cdp.Execute(ctx, CommandGetNodeForLocation, p, &res)
if err != nil {
return 0, "", 0, err
}
return res.BackendNodeID, res.FrameID, res.NodeID, nil
}
// GetOuterHTMLParams returns node's HTML markup.
type GetOuterHTMLParams struct {
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
}
// GetOuterHTML returns node's HTML markup.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getOuterHTML
//
// parameters:
func GetOuterHTML() *GetOuterHTMLParams {
return &GetOuterHTMLParams{}
}
// WithNodeID identifier of the node.
func (p GetOuterHTMLParams) WithNodeID(nodeID cdp.NodeID) *GetOuterHTMLParams {
p.NodeID = nodeID
return &p
}
// WithBackendNodeID identifier of the backend node.
func (p GetOuterHTMLParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *GetOuterHTMLParams {
p.BackendNodeID = backendNodeID
return &p
}
// WithObjectID JavaScript object id of the node wrapper.
func (p GetOuterHTMLParams) WithObjectID(objectID runtime.RemoteObjectID) *GetOuterHTMLParams {
p.ObjectID = objectID
return &p
}
// GetOuterHTMLReturns return values.
type GetOuterHTMLReturns struct {
OuterHTML string `json:"outerHTML,omitempty"` // Outer HTML markup.
}
// Do executes DOM.getOuterHTML against the provided context.
//
// returns:
//
// outerHTML - Outer HTML markup.
func (p *GetOuterHTMLParams) Do(ctx context.Context) (outerHTML string, err error) {
// execute
var res GetOuterHTMLReturns
err = cdp.Execute(ctx, CommandGetOuterHTML, p, &res)
if err != nil {
return "", err
}
return res.OuterHTML, nil
}
// GetRelayoutBoundaryParams returns the id of the nearest ancestor that is a
// relayout boundary.
type GetRelayoutBoundaryParams struct {
NodeID cdp.NodeID `json:"nodeId"` // Id of the node.
}
// GetRelayoutBoundary returns the id of the nearest ancestor that is a
// relayout boundary.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getRelayoutBoundary
//
// parameters:
//
// nodeID - Id of the node.
func GetRelayoutBoundary(nodeID cdp.NodeID) *GetRelayoutBoundaryParams {
return &GetRelayoutBoundaryParams{
NodeID: nodeID,
}
}
// GetRelayoutBoundaryReturns return values.
type GetRelayoutBoundaryReturns struct {
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Relayout boundary node id for the given node.
}
// Do executes DOM.getRelayoutBoundary against the provided context.
//
// returns:
//
// nodeID - Relayout boundary node id for the given node.
func (p *GetRelayoutBoundaryParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
// execute
var res GetRelayoutBoundaryReturns
err = cdp.Execute(ctx, CommandGetRelayoutBoundary, p, &res)
if err != nil {
return 0, err
}
return res.NodeID, nil
}
// GetSearchResultsParams returns search results from given fromIndex to
// given toIndex from the search 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 search with the given identifier.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getSearchResults
//
// parameters:
//
// searchID - Unique search session identifier.
// fromIndex - Start index of the search result to be returned.
// toIndex - End index of the search result to be returned.
func GetSearchResults(searchID string, fromIndex int64, toIndex int64) *GetSearchResultsParams {
return &GetSearchResultsParams{
SearchID: searchID,
FromIndex: fromIndex,
ToIndex: toIndex,
}
}
// GetSearchResultsReturns return values.
type GetSearchResultsReturns struct {
NodeIDs []cdp.NodeID `json:"nodeIds,omitempty"` // Ids of the search result nodes.
}
// Do executes DOM.getSearchResults against the provided context.
//
// returns:
//
// nodeIDs - Ids of the search result nodes.
func (p *GetSearchResultsParams) Do(ctx context.Context) (nodeIDs []cdp.NodeID, err error) {
// execute
var res GetSearchResultsReturns
err = cdp.Execute(ctx, CommandGetSearchResults, p, &res)
if err != nil {
return nil, err
}
return res.NodeIDs, nil
}
// MarkUndoableStateParams marks last undoable state.
type MarkUndoableStateParams struct{}
// MarkUndoableState marks last undoable state.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-markUndoableState
func MarkUndoableState() *MarkUndoableStateParams {
return &MarkUndoableStateParams{}
}
// Do executes DOM.markUndoableState against the provided context.
func (p *MarkUndoableStateParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandMarkUndoableState, nil, nil)
}
// MoveToParams moves node into the new container, places it before the given
// anchor.
type MoveToParams struct {
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).
}
// MoveTo moves node into the new container, places it before the given
// anchor.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-moveTo
//
// parameters:
//
// 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 {
return &MoveToParams{
NodeID: nodeID,
TargetNodeID: targetNodeID,
}
}
// WithInsertBeforeNodeID drop node before this one (if absent, the moved
// node becomes the last child of targetNodeId).
func (p MoveToParams) WithInsertBeforeNodeID(insertBeforeNodeID cdp.NodeID) *MoveToParams {
p.InsertBeforeNodeID = insertBeforeNodeID
return &p
}
// MoveToReturns return values.
type MoveToReturns struct {
NodeID cdp.NodeID `json:"nodeId,omitempty"` // New id of the moved node.
}
// Do executes DOM.moveTo against the provided context.
//
// returns:
//
// nodeID - New id of the moved node.
func (p *MoveToParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
// execute
var res MoveToReturns
err = cdp.Execute(ctx, CommandMoveTo, p, &res)
if err != nil {
return 0, err
}
return res.NodeID, nil
}
// 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.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-performSearch
//
// 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.
//
// returns:
//
// searchID - Unique search session identifier.
// resultCount - Number of search results.
func (p *PerformSearchParams) Do(ctx context.Context) (searchID string, resultCount int64, err error) {
// execute
var res PerformSearchReturns
err = cdp.Execute(ctx, CommandPerformSearch, p, &res)
if err != nil {
return "", 0, err
}
return res.SearchID, res.ResultCount, nil
}
// 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.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-pushNodeByPathToFrontend
//
// parameters:
//
// path - Path to node in the proprietary format.
func PushNodeByPathToFrontend(path string) *PushNodeByPathToFrontendParams {
return &PushNodeByPathToFrontendParams{
Path: path,
}
}
// PushNodeByPathToFrontendReturns return values.
type PushNodeByPathToFrontendReturns struct {
NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node for given path.
}
// Do executes DOM.pushNodeByPathToFrontend against the provided context.
//
// returns:
//
// nodeID - Id of the node for given path.
func (p *PushNodeByPathToFrontendParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
// execute
var res PushNodeByPathToFrontendReturns
err = cdp.Execute(ctx, CommandPushNodeByPathToFrontend, p, &res)
if err != nil {
return 0, err
}
return res.NodeID, nil
}
// PushNodesByBackendIDsToFrontendParams requests that a batch of nodes is
// sent to the caller given their backend node ids.
type PushNodesByBackendIDsToFrontendParams struct {
BackendNodeIDs []cdp.BackendNodeID `json:"backendNodeIds"` // The array of backend node ids.
}
// PushNodesByBackendIDsToFrontend requests that a batch of nodes is sent to
// the caller given their backend node ids.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-pushNodesByBackendIdsToFrontend
//
// parameters:
//
// backendNodeIDs - The array of backend node ids.
func PushNodesByBackendIDsToFrontend(backendNodeIDs []cdp.BackendNodeID) *PushNodesByBackendIDsToFrontendParams {
return &PushNodesByBackendIDsToFrontendParams{
BackendNodeIDs: backendNodeIDs,
}
}
// PushNodesByBackendIDsToFrontendReturns return values.
type PushNodesByBackendIDsToFrontendReturns struct {
NodeIDs []cdp.NodeID `json:"nodeIds,omitempty"` // The array of ids of pushed nodes that correspond to the backend ids specified in backendNodeIds.
}
// Do executes DOM.pushNodesByBackendIdsToFrontend against the provided context.
//