forked from mkenney/go-chrome
/
cdtp.dom.go
1271 lines (1094 loc) · 35.8 KB
/
cdtp.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 socket
import (
"encoding/json"
"github.com/mkenney/go-chrome/tot/dom"
)
/*
DOMProtocol provides a namespace for the Chrome DOM protocol methods. The DOM
protocol 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.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/
*/
type DOMProtocol struct {
Socket Socketer
}
/*
CollectClassNamesFromSubtree creates a deep copy of the specified node and
places it into the target container before the given anchor.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-collectClassNamesFromSubtree
EXPERIMENTAL.
*/
func (protocol *DOMProtocol) CollectClassNamesFromSubtree(
params *dom.CollectClassNamesFromSubtreeParams,
) <-chan *dom.CollectClassNamesFromSubtreeResult {
resultChan := make(chan *dom.CollectClassNamesFromSubtreeResult)
command := NewCommand(protocol.Socket, "DOM.collectClassNamesFromSubtree", params)
result := &dom.CollectClassNamesFromSubtreeResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
CopyTo creates a deep copy of the specified node and places it into the target
container before the given anchor.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-copyTo EXPERIMENTAL.
*/
func (protocol *DOMProtocol) CopyTo(
params *dom.CopyToParams,
) <-chan *dom.CopyToResult {
resultChan := make(chan *dom.CopyToResult)
command := NewCommand(protocol.Socket, "DOM.copyTo", params)
result := &dom.CopyToResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
DescribeNode describes node given its id, does not require domain to be enabled.
Does not start tracking any objects, can be used for automation.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-describeNode
*/
func (protocol *DOMProtocol) DescribeNode(
params *dom.DescribeNodeParams,
) <-chan *dom.DescribeNodeResult {
resultChan := make(chan *dom.DescribeNodeResult)
command := NewCommand(protocol.Socket, "DOM.describeNode", params)
result := &dom.DescribeNodeResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
Disable disables the DOM agent for the given page.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-disable
*/
func (protocol *DOMProtocol) Disable() <-chan *dom.DisableResult {
resultChan := make(chan *dom.DisableResult)
command := NewCommand(protocol.Socket, "DOM.disable", nil)
result := &dom.DisableResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
DiscardSearchResults discards search results from the session with the given id.
getSearchResults should no longer be called for that search.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-discardSearchResults
EXPERIMENTAL.
*/
func (protocol *DOMProtocol) DiscardSearchResults(
params *dom.DiscardSearchResultsParams,
) <-chan *dom.DiscardSearchResultsResult {
resultChan := make(chan *dom.DiscardSearchResultsResult)
command := NewCommand(protocol.Socket, "DOM.discardSearchResults", params)
result := &dom.DiscardSearchResultsResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
Enable enables the DOM agent for the given page.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-enable
*/
func (protocol *DOMProtocol) Enable() <-chan *dom.EnableResult {
resultChan := make(chan *dom.EnableResult)
command := NewCommand(protocol.Socket, "DOM.enable", nil)
result := &dom.EnableResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
Focus focuses the given element.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-focus
*/
func (protocol *DOMProtocol) Focus(
params *dom.FocusParams,
) <-chan *dom.FocusResult {
resultChan := make(chan *dom.FocusResult)
command := NewCommand(protocol.Socket, "DOM.focus", params)
result := &dom.FocusResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
GetAttributes returns attributes for the specified node.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getAttributes
*/
func (protocol *DOMProtocol) GetAttributes(
params *dom.GetAttributesParams,
) <-chan *dom.GetAttributesResult {
resultChan := make(chan *dom.GetAttributesResult)
command := NewCommand(protocol.Socket, "DOM.getAttributes", params)
result := &dom.GetAttributesResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
GetBoxModel returns boxes for the given node.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getBoxModel
*/
func (protocol *DOMProtocol) GetBoxModel(
params *dom.GetBoxModelParams,
) <-chan *dom.GetBoxModelResult {
resultChan := make(chan *dom.GetBoxModelResult)
command := NewCommand(protocol.Socket, "DOM.getBoxModel", params)
result := &dom.GetBoxModelResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
GetDocument returns the root DOM node (and optionally the subtree) to the
caller.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getDocument
*/
func (protocol *DOMProtocol) GetDocument(
params *dom.GetDocumentParams,
) <-chan *dom.GetDocumentResult {
resultChan := make(chan *dom.GetDocumentResult)
command := NewCommand(protocol.Socket, "DOM.getDocument", params)
result := &dom.GetDocumentResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
GetFlattenedDocument returns the root DOM node (and optionally the subtree) to
the caller.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getFlattenedDocument
*/
func (protocol *DOMProtocol) GetFlattenedDocument(
params *dom.GetFlattenedDocumentParams,
) <-chan *dom.GetFlattenedDocumentResult {
resultChan := make(chan *dom.GetFlattenedDocumentResult)
command := NewCommand(protocol.Socket, "DOM.getFlattenedDocument", params)
result := &dom.GetFlattenedDocumentResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
GetNodeForLocation returns node id at given location.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getNodeForLocation EXPERIMENTAL.
*/
func (protocol *DOMProtocol) GetNodeForLocation(
params *dom.GetNodeForLocationParams,
) <-chan *dom.GetNodeForLocationResult {
resultChan := make(chan *dom.GetNodeForLocationResult)
command := NewCommand(protocol.Socket, "DOM.getNodeForLocation", params)
result := &dom.GetNodeForLocationResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
GetOuterHTML returns node's HTML markup.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getOuterHTML
*/
func (protocol *DOMProtocol) GetOuterHTML(
params *dom.GetOuterHTMLParams,
) <-chan *dom.GetOuterHTMLResult {
resultChan := make(chan *dom.GetOuterHTMLResult)
command := NewCommand(protocol.Socket, "DOM.getOuterHTML", params)
result := &dom.GetOuterHTMLResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
GetRelayoutBoundary returns the id of the nearest ancestor that is a relayout
boundary.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getRelayoutBoundary EXPERIMENTAL.
*/
func (protocol *DOMProtocol) GetRelayoutBoundary(
params *dom.GetRelayoutBoundaryParams,
) <-chan *dom.GetRelayoutBoundaryResult {
resultChan := make(chan *dom.GetRelayoutBoundaryResult)
command := NewCommand(protocol.Socket, "DOM.getRelayoutBoundary", params)
result := &dom.GetRelayoutBoundaryResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
GetSearchResults returns search results from given fromIndex to given toIndex
from the search with the given identifier.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getSearchResults
EXPERIMENTAL.
*/
func (protocol *DOMProtocol) GetSearchResults(
params *dom.GetSearchResultsParams,
) <-chan *dom.GetSearchResultsResult {
resultChan := make(chan *dom.GetSearchResultsResult)
command := NewCommand(protocol.Socket, "DOM.getSearchResults", params)
result := &dom.GetSearchResultsResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
MarkUndoableState marks last undoable state.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-markUndoableState
EXPERIMENTAL.
*/
func (protocol *DOMProtocol) MarkUndoableState() <-chan *dom.MarkUndoableStateResult {
resultChan := make(chan *dom.MarkUndoableStateResult)
command := NewCommand(protocol.Socket, "DOM.markUndoableState", nil)
result := &dom.MarkUndoableStateResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
MoveTo moves node into the new container, places it before the given anchor.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-moveTo
*/
func (protocol *DOMProtocol) MoveTo(
params *dom.MoveToParams,
) <-chan *dom.MoveToResult {
resultChan := make(chan *dom.MoveToResult)
command := NewCommand(protocol.Socket, "DOM.moveTo", params)
result := &dom.MoveToResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
PerformSearch searches for a given string in the DOM tree. Use getSearchResults
to access search results or cancelSearch to end this search session.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-performSearch
EXPERIMENTAL.
*/
func (protocol *DOMProtocol) PerformSearch(
params *dom.PerformSearchParams,
) <-chan *dom.PerformSearchResult {
resultChan := make(chan *dom.PerformSearchResult)
command := NewCommand(protocol.Socket, "DOM.performSearch", params)
result := &dom.PerformSearchResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
PushNodeByPathToFrontend requests that the node is sent to the caller given its
path.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-pushNodeByPathToFrontend
EXPERIMENTAL. @TODO, use XPath.
*/
func (protocol *DOMProtocol) PushNodeByPathToFrontend(
params *dom.PushNodeByPathToFrontendParams,
) <-chan *dom.PushNodeByPathToFrontendResult {
resultChan := make(chan *dom.PushNodeByPathToFrontendResult)
command := NewCommand(protocol.Socket, "DOM.pushNodeByPathToFrontend", params)
result := &dom.PushNodeByPathToFrontendResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
PushNodesByBackendIDsToFrontend requests that a batch of nodes is sent to the
caller given their backend node IDs.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-pushNodesByBackendIdsToFrontend
EXPERIMENTAL.
*/
func (protocol *DOMProtocol) PushNodesByBackendIDsToFrontend(
params *dom.PushNodesByBackendIDsToFrontendParams,
) <-chan *dom.PushNodesByBackendIDsToFrontendResult {
resultChan := make(chan *dom.PushNodesByBackendIDsToFrontendResult)
command := NewCommand(protocol.Socket, "DOM.pushNodesByBackendIdsToFrontend", params)
result := &dom.PushNodesByBackendIDsToFrontendResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
QuerySelector executes querySelector on a given node.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-querySelector
*/
func (protocol *DOMProtocol) QuerySelector(
params *dom.QuerySelectorParams,
) <-chan *dom.QuerySelectorResult {
resultChan := make(chan *dom.QuerySelectorResult)
command := NewCommand(protocol.Socket, "DOM.querySelector", params)
result := &dom.QuerySelectorResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
QuerySelectorAll executes querySelectorAll on a given node.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-querySelectorAll
*/
func (protocol *DOMProtocol) QuerySelectorAll(
params *dom.QuerySelectorAllParams,
) <-chan *dom.QuerySelectorAllResult {
resultChan := make(chan *dom.QuerySelectorAllResult)
command := NewCommand(protocol.Socket, "DOM.querySelectorAll", params)
result := &dom.QuerySelectorAllResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
Redo re-does the last undone action.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-redo EXPERIMENTAL.
*/
func (protocol *DOMProtocol) Redo() <-chan *dom.RedoResult {
resultChan := make(chan *dom.RedoResult)
command := NewCommand(protocol.Socket, "DOM.redo", nil)
result := &dom.RedoResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
RemoveAttribute removes attribute with given name from an element with given id.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-removeAttribute
*/
func (protocol *DOMProtocol) RemoveAttribute(
params *dom.RemoveAttributeParams,
) <-chan *dom.RemoveAttributeResult {
resultChan := make(chan *dom.RemoveAttributeResult)
command := NewCommand(protocol.Socket, "DOM.removeAttribute", params)
result := &dom.RemoveAttributeResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
RemoveNode removes the specified node.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-removeNode
*/
func (protocol *DOMProtocol) RemoveNode(
params *dom.RemoveNodeParams,
) <-chan *dom.RemoveNodeResult {
resultChan := make(chan *dom.RemoveNodeResult)
command := NewCommand(protocol.Socket, "DOM.removeNode", params)
result := &dom.RemoveNodeResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
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.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-requestChildNodes
*/
func (protocol *DOMProtocol) RequestChildNodes(
params *dom.RequestChildNodesParams,
) <-chan *dom.RequestChildNodesResult {
resultChan := make(chan *dom.RequestChildNodesResult)
command := NewCommand(protocol.Socket, "DOM.requestChildNodes", params)
result := &dom.RequestChildNodesResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
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.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-requestNode
*/
func (protocol *DOMProtocol) RequestNode(
params *dom.RequestNodeParams,
) <-chan *dom.RequestNodeResult {
resultChan := make(chan *dom.RequestNodeResult)
command := NewCommand(protocol.Socket, "DOM.requestNode", params)
result := &dom.RequestNodeResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
ResolveNode resolves the JavaScript node object for a given NodeID or
BackendNodeID.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-resolveNode
*/
func (protocol *DOMProtocol) ResolveNode(
params *dom.ResolveNodeParams,
) <-chan *dom.ResolveNodeResult {
resultChan := make(chan *dom.ResolveNodeResult)
command := NewCommand(protocol.Socket, "DOM.resolveNode", params)
result := &dom.ResolveNodeResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetAttributeValue sets attribute for an element with given id.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-setAttributeValue
*/
func (protocol *DOMProtocol) SetAttributeValue(
params *dom.SetAttributeValueParams,
) <-chan *dom.SetAttributeValueResult {
resultChan := make(chan *dom.SetAttributeValueResult)
command := NewCommand(protocol.Socket, "DOM.setAttributeValue", params)
result := &dom.SetAttributeValueResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
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.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-setAttributesAsText
*/
func (protocol *DOMProtocol) SetAttributesAsText(
params *dom.SetAttributesAsTextParams,
) <-chan *dom.SetAttributesAsTextResult {
resultChan := make(chan *dom.SetAttributesAsTextResult)
command := NewCommand(protocol.Socket, "DOM.setAttributesAsText", params)
result := &dom.SetAttributesAsTextResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetFileInputFiles sets files for the given file input element.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-setFileInputFiles
*/
func (protocol *DOMProtocol) SetFileInputFiles(
params *dom.SetFileInputFilesParams,
) <-chan *dom.SetFileInputFilesResult {
resultChan := make(chan *dom.SetFileInputFilesResult)
command := NewCommand(protocol.Socket, "DOM.setFileInputFiles", params)
result := &dom.SetFileInputFilesResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetInspectedNode enables console to refer to the node with given id via $x (see
Command Line API for more details $x functions).
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-setInspectedNode EXPERIMENTAL.
*/
func (protocol *DOMProtocol) SetInspectedNode(
params *dom.SetInspectedNodeParams,
) <-chan *dom.SetInspectedNodeResult {
resultChan := make(chan *dom.SetInspectedNodeResult)
command := NewCommand(protocol.Socket, "DOM.setInspectedNode", params)
result := &dom.SetInspectedNodeResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetNodeName sets node name for the specified node.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-setNodeName
*/
func (protocol *DOMProtocol) SetNodeName(
params *dom.SetNodeNameParams,
) <-chan *dom.SetNodeNameResult {
resultChan := make(chan *dom.SetNodeNameResult)
command := NewCommand(protocol.Socket, "DOM.setNodeName", params)
result := &dom.SetNodeNameResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetNodeValue sets node value for the specified node.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-setNodeValue
*/
func (protocol *DOMProtocol) SetNodeValue(
params *dom.SetNodeValueParams,
) <-chan *dom.SetNodeValueResult {
resultChan := make(chan *dom.SetNodeValueResult)
command := NewCommand(protocol.Socket, "DOM.setNodeValue", params)
result := &dom.SetNodeValueResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetOuterHTML sets node HTML markup, returns new node id.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-setOuterHTML
*/
func (protocol *DOMProtocol) SetOuterHTML(
params *dom.SetOuterHTMLParams,
) <-chan *dom.SetOuterHTMLResult {
resultChan := make(chan *dom.SetOuterHTMLResult)
command := NewCommand(protocol.Socket, "DOM.setOuterHTML", params)
result := &dom.SetOuterHTMLResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
Undo undoes the last performed action.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-undo
EXPERIMENTAL.
*/
func (protocol *DOMProtocol) Undo() <-chan *dom.UndoResult {
resultChan := make(chan *dom.UndoResult)
command := NewCommand(protocol.Socket, "DOM.undo", nil)
result := &dom.UndoResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
OnAttributeModified adds a handler to the DOM.attributeModified event.
DOM.attributeModified fires when Element's attribute is modified.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#event-attributeModified
*/
func (protocol *DOMProtocol) OnAttributeModified(
callback func(event *dom.AttributeModifiedEvent),
) {
handler := NewEventHandler(
"DOM.attributeModified",
func(response *Response) {
event := &dom.AttributeModifiedEvent{}
json.Unmarshal([]byte(response.Params), event)
if nil != response.Error && 0 != response.Error.Code {
event.Err = response.Error
}
callback(event)
},
)
protocol.Socket.AddEventHandler(handler)
}
/*
OnAttributeRemoved adds a handler to the DOM.attributeRemoved event.
DOM.attributeRemoved fires when Element's attribute is modified.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#event-attributeRemoved
*/
func (protocol *DOMProtocol) OnAttributeRemoved(
callback func(event *dom.AttributeRemovedEvent),
) {
handler := NewEventHandler(
"DOM.attributeRemoved",
func(response *Response) {
event := &dom.AttributeRemovedEvent{}
json.Unmarshal([]byte(response.Params), event)
if nil != response.Error && 0 != response.Error.Code {
event.Err = response.Error
}
callback(event)
},
)
protocol.Socket.AddEventHandler(handler)
}
/*
OnCharacterDataModified adds a handler to the DOM.characterDataModified event.
DOM.characterDataModified mirrors the DOMCharacterDataModified event.
https://chromedevtools.github.io/devtools-protocol/tot/DOM/#event-characterDataModified
*/
func (protocol *DOMProtocol) OnCharacterDataModified(