-
Notifications
You must be signed in to change notification settings - Fork 6
/
page.go
3097 lines (2526 loc) · 81.8 KB
/
page.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 protocol
import (
"encoding/json"
"github.com/yijinliu/algo-lib/go/src/logging"
hc "github.com/yijinliu/headless-chromium/go"
"sync"
)
// Resource type as it was perceived by the rendering engine.
type ResourceType string
const ResourceTypeDocument ResourceType = "Document"
const ResourceTypeStylesheet ResourceType = "Stylesheet"
const ResourceTypeImage ResourceType = "Image"
const ResourceTypeMedia ResourceType = "Media"
const ResourceTypeFont ResourceType = "Font"
const ResourceTypeScript ResourceType = "Script"
const ResourceTypeTextTrack ResourceType = "TextTrack"
const ResourceTypeXHR ResourceType = "XHR"
const ResourceTypeFetch ResourceType = "Fetch"
const ResourceTypeEventSource ResourceType = "EventSource"
const ResourceTypeWebSocket ResourceType = "WebSocket"
const ResourceTypeManifest ResourceType = "Manifest"
const ResourceTypeOther ResourceType = "Other"
// Unique frame identifier.
type FrameId string
// Information about the Frame on the page.
type Frame struct {
Id string `json:"id"` // Frame unique identifier.
ParentId string `json:"parentId,omitempty"` // Parent frame identifier.
LoaderId *LoaderId `json:"loaderId"` // Identifier of the loader associated with this frame.
Name string `json:"name,omitempty"` // Frame's name as specified in the tag.
Url string `json:"url"` // Frame document's URL.
SecurityOrigin string `json:"securityOrigin"` // Frame document's security origin.
MimeType string `json:"mimeType"` // Frame document's mimeType as determined by the browser.
}
// Information about the Resource on the page.
// @experimental
type FrameResource struct {
Url string `json:"url"` // Resource URL.
Type ResourceType `json:"type"` // Type of this resource.
MimeType string `json:"mimeType"` // Resource mimeType as determined by the browser.
LastModified *NetworkTimestamp `json:"lastModified,omitempty"` // last-modified timestamp as reported by server.
ContentSize float64 `json:"contentSize,omitempty"` // Resource content size.
Failed bool `json:"failed,omitempty"` // True if the resource failed to load.
Canceled bool `json:"canceled,omitempty"` // True if the resource was canceled during loading.
}
// Information about the Frame hierarchy along with their cached resources.
// @experimental
type FrameResourceTree struct {
Frame *Frame `json:"frame"` // Frame information for this tree item.
ChildFrames []*FrameResourceTree `json:"childFrames,omitempty"` // Child frames.
Resources []*FrameResource `json:"resources"` // Information about frame resources.
}
// Unique script identifier.
// @experimental
type ScriptIdentifier string
// Navigation history entry.
// @experimental
type NavigationEntry struct {
Id int `json:"id"` // Unique id of the navigation history entry.
Url string `json:"url"` // URL of the navigation history entry.
Title string `json:"title"` // Title of the navigation history entry.
}
// Screencast frame metadata.
// @experimental
type ScreencastFrameMetadata struct {
OffsetTop float64 `json:"offsetTop"` // Top offset in DIP.
PageScaleFactor float64 `json:"pageScaleFactor"` // Page scale factor.
DeviceWidth float64 `json:"deviceWidth"` // Device screen width in DIP.
DeviceHeight float64 `json:"deviceHeight"` // Device screen height in DIP.
ScrollOffsetX float64 `json:"scrollOffsetX"` // Position of horizontal scroll in CSS pixels.
ScrollOffsetY float64 `json:"scrollOffsetY"` // Position of vertical scroll in CSS pixels.
Timestamp float64 `json:"timestamp,omitempty"` // Frame swap timestamp.
}
// Javascript dialog type.
// @experimental
type DialogType string
const DialogTypeAlert DialogType = "alert"
const DialogTypeConfirm DialogType = "confirm"
const DialogTypePrompt DialogType = "prompt"
const DialogTypeBeforeunload DialogType = "beforeunload"
// Error while paring app manifest.
// @experimental
type AppManifestError struct {
Message string `json:"message"` // Error message.
Critical int `json:"critical"` // If criticial, this is a non-recoverable parse error.
Line int `json:"line"` // Error line.
Column int `json:"column"` // Error column.
}
// Proceed: allow the navigation; Cancel: cancel the navigation; CancelAndIgnore: cancels the navigation and makes the requester of the navigation acts like the request was never made.
// @experimental
type NavigationResponse string
const NavigationResponseProceed NavigationResponse = "Proceed"
const NavigationResponseCancel NavigationResponse = "Cancel"
const NavigationResponseCancelAndIgnore NavigationResponse = "CancelAndIgnore"
// Layout viewport position and dimensions.
// @experimental
type LayoutViewport struct {
PageX int `json:"pageX"` // Horizontal offset relative to the document (CSS pixels).
PageY int `json:"pageY"` // Vertical offset relative to the document (CSS pixels).
ClientWidth int `json:"clientWidth"` // Width (CSS pixels), excludes scrollbar if present.
ClientHeight int `json:"clientHeight"` // Height (CSS pixels), excludes scrollbar if present.
}
// Visual viewport position, dimensions, and scale.
// @experimental
type VisualViewport struct {
OffsetX float64 `json:"offsetX"` // Horizontal offset relative to the layout viewport (CSS pixels).
OffsetY float64 `json:"offsetY"` // Vertical offset relative to the layout viewport (CSS pixels).
PageX float64 `json:"pageX"` // Horizontal offset relative to the document (CSS pixels).
PageY float64 `json:"pageY"` // Vertical offset relative to the document (CSS pixels).
ClientWidth float64 `json:"clientWidth"` // Width (CSS pixels), excludes scrollbar if present.
ClientHeight float64 `json:"clientHeight"` // Height (CSS pixels), excludes scrollbar if present.
Scale float64 `json:"scale"` // Scale relative to the ideal viewport (size at width=device-width).
}
// Enables page domain notifications.
type PageEnableCommand struct {
wg sync.WaitGroup
err error
}
func NewPageEnableCommand() *PageEnableCommand {
return &PageEnableCommand{}
}
func (cmd *PageEnableCommand) Name() string {
return "Page.enable"
}
func (cmd *PageEnableCommand) Params() interface{} {
return nil
}
func (cmd *PageEnableCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func PageEnable(conn *hc.Conn) (err error) {
cmd := NewPageEnableCommand()
cmd.Run(conn)
return cmd.err
}
type PageEnableCB func(err error)
// Enables page domain notifications.
type AsyncPageEnableCommand struct {
cb PageEnableCB
}
func NewAsyncPageEnableCommand(cb PageEnableCB) *AsyncPageEnableCommand {
return &AsyncPageEnableCommand{
cb: cb,
}
}
func (cmd *AsyncPageEnableCommand) Name() string {
return "Page.enable"
}
func (cmd *AsyncPageEnableCommand) Params() interface{} {
return nil
}
func (cmd *PageEnableCommand) Done(data []byte, err error) {
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncPageEnableCommand) Done(data []byte, err error) {
cmd.cb(err)
}
// Disables page domain notifications.
type PageDisableCommand struct {
wg sync.WaitGroup
err error
}
func NewPageDisableCommand() *PageDisableCommand {
return &PageDisableCommand{}
}
func (cmd *PageDisableCommand) Name() string {
return "Page.disable"
}
func (cmd *PageDisableCommand) Params() interface{} {
return nil
}
func (cmd *PageDisableCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func PageDisable(conn *hc.Conn) (err error) {
cmd := NewPageDisableCommand()
cmd.Run(conn)
return cmd.err
}
type PageDisableCB func(err error)
// Disables page domain notifications.
type AsyncPageDisableCommand struct {
cb PageDisableCB
}
func NewAsyncPageDisableCommand(cb PageDisableCB) *AsyncPageDisableCommand {
return &AsyncPageDisableCommand{
cb: cb,
}
}
func (cmd *AsyncPageDisableCommand) Name() string {
return "Page.disable"
}
func (cmd *AsyncPageDisableCommand) Params() interface{} {
return nil
}
func (cmd *PageDisableCommand) Done(data []byte, err error) {
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncPageDisableCommand) Done(data []byte, err error) {
cmd.cb(err)
}
type AddScriptToEvaluateOnLoadParams struct {
ScriptSource string `json:"scriptSource"`
}
type AddScriptToEvaluateOnLoadResult struct {
Identifier ScriptIdentifier `json:"identifier"` // Identifier of the added script.
}
// @experimental
type AddScriptToEvaluateOnLoadCommand struct {
params *AddScriptToEvaluateOnLoadParams
result AddScriptToEvaluateOnLoadResult
wg sync.WaitGroup
err error
}
func NewAddScriptToEvaluateOnLoadCommand(params *AddScriptToEvaluateOnLoadParams) *AddScriptToEvaluateOnLoadCommand {
return &AddScriptToEvaluateOnLoadCommand{
params: params,
}
}
func (cmd *AddScriptToEvaluateOnLoadCommand) Name() string {
return "Page.addScriptToEvaluateOnLoad"
}
func (cmd *AddScriptToEvaluateOnLoadCommand) Params() interface{} {
return cmd.params
}
func (cmd *AddScriptToEvaluateOnLoadCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func AddScriptToEvaluateOnLoad(params *AddScriptToEvaluateOnLoadParams, conn *hc.Conn) (result *AddScriptToEvaluateOnLoadResult, err error) {
cmd := NewAddScriptToEvaluateOnLoadCommand(params)
cmd.Run(conn)
return &cmd.result, cmd.err
}
type AddScriptToEvaluateOnLoadCB func(result *AddScriptToEvaluateOnLoadResult, err error)
// @experimental
type AsyncAddScriptToEvaluateOnLoadCommand struct {
params *AddScriptToEvaluateOnLoadParams
cb AddScriptToEvaluateOnLoadCB
}
func NewAsyncAddScriptToEvaluateOnLoadCommand(params *AddScriptToEvaluateOnLoadParams, cb AddScriptToEvaluateOnLoadCB) *AsyncAddScriptToEvaluateOnLoadCommand {
return &AsyncAddScriptToEvaluateOnLoadCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncAddScriptToEvaluateOnLoadCommand) Name() string {
return "Page.addScriptToEvaluateOnLoad"
}
func (cmd *AsyncAddScriptToEvaluateOnLoadCommand) Params() interface{} {
return cmd.params
}
func (cmd *AddScriptToEvaluateOnLoadCommand) Result() *AddScriptToEvaluateOnLoadResult {
return &cmd.result
}
func (cmd *AddScriptToEvaluateOnLoadCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncAddScriptToEvaluateOnLoadCommand) Done(data []byte, err error) {
var result AddScriptToEvaluateOnLoadResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
type RemoveScriptToEvaluateOnLoadParams struct {
Identifier ScriptIdentifier `json:"identifier"`
}
// @experimental
type RemoveScriptToEvaluateOnLoadCommand struct {
params *RemoveScriptToEvaluateOnLoadParams
wg sync.WaitGroup
err error
}
func NewRemoveScriptToEvaluateOnLoadCommand(params *RemoveScriptToEvaluateOnLoadParams) *RemoveScriptToEvaluateOnLoadCommand {
return &RemoveScriptToEvaluateOnLoadCommand{
params: params,
}
}
func (cmd *RemoveScriptToEvaluateOnLoadCommand) Name() string {
return "Page.removeScriptToEvaluateOnLoad"
}
func (cmd *RemoveScriptToEvaluateOnLoadCommand) Params() interface{} {
return cmd.params
}
func (cmd *RemoveScriptToEvaluateOnLoadCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func RemoveScriptToEvaluateOnLoad(params *RemoveScriptToEvaluateOnLoadParams, conn *hc.Conn) (err error) {
cmd := NewRemoveScriptToEvaluateOnLoadCommand(params)
cmd.Run(conn)
return cmd.err
}
type RemoveScriptToEvaluateOnLoadCB func(err error)
// @experimental
type AsyncRemoveScriptToEvaluateOnLoadCommand struct {
params *RemoveScriptToEvaluateOnLoadParams
cb RemoveScriptToEvaluateOnLoadCB
}
func NewAsyncRemoveScriptToEvaluateOnLoadCommand(params *RemoveScriptToEvaluateOnLoadParams, cb RemoveScriptToEvaluateOnLoadCB) *AsyncRemoveScriptToEvaluateOnLoadCommand {
return &AsyncRemoveScriptToEvaluateOnLoadCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncRemoveScriptToEvaluateOnLoadCommand) Name() string {
return "Page.removeScriptToEvaluateOnLoad"
}
func (cmd *AsyncRemoveScriptToEvaluateOnLoadCommand) Params() interface{} {
return cmd.params
}
func (cmd *RemoveScriptToEvaluateOnLoadCommand) Done(data []byte, err error) {
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncRemoveScriptToEvaluateOnLoadCommand) Done(data []byte, err error) {
cmd.cb(err)
}
type SetAutoAttachToCreatedPagesParams struct {
AutoAttach bool `json:"autoAttach"` // If true, browser will open a new inspector window for every page created from this one.
}
// Controls whether browser will open a new inspector window for connected pages.
// @experimental
type SetAutoAttachToCreatedPagesCommand struct {
params *SetAutoAttachToCreatedPagesParams
wg sync.WaitGroup
err error
}
func NewSetAutoAttachToCreatedPagesCommand(params *SetAutoAttachToCreatedPagesParams) *SetAutoAttachToCreatedPagesCommand {
return &SetAutoAttachToCreatedPagesCommand{
params: params,
}
}
func (cmd *SetAutoAttachToCreatedPagesCommand) Name() string {
return "Page.setAutoAttachToCreatedPages"
}
func (cmd *SetAutoAttachToCreatedPagesCommand) Params() interface{} {
return cmd.params
}
func (cmd *SetAutoAttachToCreatedPagesCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func SetAutoAttachToCreatedPages(params *SetAutoAttachToCreatedPagesParams, conn *hc.Conn) (err error) {
cmd := NewSetAutoAttachToCreatedPagesCommand(params)
cmd.Run(conn)
return cmd.err
}
type SetAutoAttachToCreatedPagesCB func(err error)
// Controls whether browser will open a new inspector window for connected pages.
// @experimental
type AsyncSetAutoAttachToCreatedPagesCommand struct {
params *SetAutoAttachToCreatedPagesParams
cb SetAutoAttachToCreatedPagesCB
}
func NewAsyncSetAutoAttachToCreatedPagesCommand(params *SetAutoAttachToCreatedPagesParams, cb SetAutoAttachToCreatedPagesCB) *AsyncSetAutoAttachToCreatedPagesCommand {
return &AsyncSetAutoAttachToCreatedPagesCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncSetAutoAttachToCreatedPagesCommand) Name() string {
return "Page.setAutoAttachToCreatedPages"
}
func (cmd *AsyncSetAutoAttachToCreatedPagesCommand) Params() interface{} {
return cmd.params
}
func (cmd *SetAutoAttachToCreatedPagesCommand) Done(data []byte, err error) {
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncSetAutoAttachToCreatedPagesCommand) Done(data []byte, err error) {
cmd.cb(err)
}
type ReloadParams struct {
IgnoreCache bool `json:"ignoreCache,omitempty"` // If true, browser cache is ignored (as if the user pressed Shift+refresh).
ScriptToEvaluateOnLoad string `json:"scriptToEvaluateOnLoad,omitempty"` // If set, the script will be injected into all frames of the inspected page after reload.
}
// Reloads given page optionally ignoring the cache.
type ReloadCommand struct {
params *ReloadParams
wg sync.WaitGroup
err error
}
func NewReloadCommand(params *ReloadParams) *ReloadCommand {
return &ReloadCommand{
params: params,
}
}
func (cmd *ReloadCommand) Name() string {
return "Page.reload"
}
func (cmd *ReloadCommand) Params() interface{} {
return cmd.params
}
func (cmd *ReloadCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func Reload(params *ReloadParams, conn *hc.Conn) (err error) {
cmd := NewReloadCommand(params)
cmd.Run(conn)
return cmd.err
}
type ReloadCB func(err error)
// Reloads given page optionally ignoring the cache.
type AsyncReloadCommand struct {
params *ReloadParams
cb ReloadCB
}
func NewAsyncReloadCommand(params *ReloadParams, cb ReloadCB) *AsyncReloadCommand {
return &AsyncReloadCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncReloadCommand) Name() string {
return "Page.reload"
}
func (cmd *AsyncReloadCommand) Params() interface{} {
return cmd.params
}
func (cmd *ReloadCommand) Done(data []byte, err error) {
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncReloadCommand) Done(data []byte, err error) {
cmd.cb(err)
}
type NavigateParams struct {
Url string `json:"url"` // URL to navigate the page to.
}
type NavigateResult struct {
FrameId FrameId `json:"frameId"` // Frame id that will be navigated.
}
// Navigates current page to the given URL.
type NavigateCommand struct {
params *NavigateParams
result NavigateResult
wg sync.WaitGroup
err error
}
func NewNavigateCommand(params *NavigateParams) *NavigateCommand {
return &NavigateCommand{
params: params,
}
}
func (cmd *NavigateCommand) Name() string {
return "Page.navigate"
}
func (cmd *NavigateCommand) Params() interface{} {
return cmd.params
}
func (cmd *NavigateCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func Navigate(params *NavigateParams, conn *hc.Conn) (result *NavigateResult, err error) {
cmd := NewNavigateCommand(params)
cmd.Run(conn)
return &cmd.result, cmd.err
}
type NavigateCB func(result *NavigateResult, err error)
// Navigates current page to the given URL.
type AsyncNavigateCommand struct {
params *NavigateParams
cb NavigateCB
}
func NewAsyncNavigateCommand(params *NavigateParams, cb NavigateCB) *AsyncNavigateCommand {
return &AsyncNavigateCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncNavigateCommand) Name() string {
return "Page.navigate"
}
func (cmd *AsyncNavigateCommand) Params() interface{} {
return cmd.params
}
func (cmd *NavigateCommand) Result() *NavigateResult {
return &cmd.result
}
func (cmd *NavigateCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncNavigateCommand) Done(data []byte, err error) {
var result NavigateResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
// Force the page stop all navigations and pending resource fetches.
// @experimental
type StopLoadingCommand struct {
wg sync.WaitGroup
err error
}
func NewStopLoadingCommand() *StopLoadingCommand {
return &StopLoadingCommand{}
}
func (cmd *StopLoadingCommand) Name() string {
return "Page.stopLoading"
}
func (cmd *StopLoadingCommand) Params() interface{} {
return nil
}
func (cmd *StopLoadingCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func StopLoading(conn *hc.Conn) (err error) {
cmd := NewStopLoadingCommand()
cmd.Run(conn)
return cmd.err
}
type StopLoadingCB func(err error)
// Force the page stop all navigations and pending resource fetches.
// @experimental
type AsyncStopLoadingCommand struct {
cb StopLoadingCB
}
func NewAsyncStopLoadingCommand(cb StopLoadingCB) *AsyncStopLoadingCommand {
return &AsyncStopLoadingCommand{
cb: cb,
}
}
func (cmd *AsyncStopLoadingCommand) Name() string {
return "Page.stopLoading"
}
func (cmd *AsyncStopLoadingCommand) Params() interface{} {
return nil
}
func (cmd *StopLoadingCommand) Done(data []byte, err error) {
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncStopLoadingCommand) Done(data []byte, err error) {
cmd.cb(err)
}
type GetNavigationHistoryResult struct {
CurrentIndex int `json:"currentIndex"` // Index of the current navigation history entry.
Entries []*NavigationEntry `json:"entries"` // Array of navigation history entries.
}
// Returns navigation history for the current page.
// @experimental
type GetNavigationHistoryCommand struct {
result GetNavigationHistoryResult
wg sync.WaitGroup
err error
}
func NewGetNavigationHistoryCommand() *GetNavigationHistoryCommand {
return &GetNavigationHistoryCommand{}
}
func (cmd *GetNavigationHistoryCommand) Name() string {
return "Page.getNavigationHistory"
}
func (cmd *GetNavigationHistoryCommand) Params() interface{} {
return nil
}
func (cmd *GetNavigationHistoryCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func GetNavigationHistory(conn *hc.Conn) (result *GetNavigationHistoryResult, err error) {
cmd := NewGetNavigationHistoryCommand()
cmd.Run(conn)
return &cmd.result, cmd.err
}
type GetNavigationHistoryCB func(result *GetNavigationHistoryResult, err error)
// Returns navigation history for the current page.
// @experimental
type AsyncGetNavigationHistoryCommand struct {
cb GetNavigationHistoryCB
}
func NewAsyncGetNavigationHistoryCommand(cb GetNavigationHistoryCB) *AsyncGetNavigationHistoryCommand {
return &AsyncGetNavigationHistoryCommand{
cb: cb,
}
}
func (cmd *AsyncGetNavigationHistoryCommand) Name() string {
return "Page.getNavigationHistory"
}
func (cmd *AsyncGetNavigationHistoryCommand) Params() interface{} {
return nil
}
func (cmd *GetNavigationHistoryCommand) Result() *GetNavigationHistoryResult {
return &cmd.result
}
func (cmd *GetNavigationHistoryCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncGetNavigationHistoryCommand) Done(data []byte, err error) {
var result GetNavigationHistoryResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
type NavigateToHistoryEntryParams struct {
EntryId int `json:"entryId"` // Unique id of the entry to navigate to.
}
// Navigates current page to the given history entry.
// @experimental
type NavigateToHistoryEntryCommand struct {
params *NavigateToHistoryEntryParams
wg sync.WaitGroup
err error
}
func NewNavigateToHistoryEntryCommand(params *NavigateToHistoryEntryParams) *NavigateToHistoryEntryCommand {
return &NavigateToHistoryEntryCommand{
params: params,
}
}
func (cmd *NavigateToHistoryEntryCommand) Name() string {
return "Page.navigateToHistoryEntry"
}
func (cmd *NavigateToHistoryEntryCommand) Params() interface{} {
return cmd.params
}
func (cmd *NavigateToHistoryEntryCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func NavigateToHistoryEntry(params *NavigateToHistoryEntryParams, conn *hc.Conn) (err error) {
cmd := NewNavigateToHistoryEntryCommand(params)
cmd.Run(conn)
return cmd.err
}
type NavigateToHistoryEntryCB func(err error)
// Navigates current page to the given history entry.
// @experimental
type AsyncNavigateToHistoryEntryCommand struct {
params *NavigateToHistoryEntryParams
cb NavigateToHistoryEntryCB
}
func NewAsyncNavigateToHistoryEntryCommand(params *NavigateToHistoryEntryParams, cb NavigateToHistoryEntryCB) *AsyncNavigateToHistoryEntryCommand {
return &AsyncNavigateToHistoryEntryCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncNavigateToHistoryEntryCommand) Name() string {
return "Page.navigateToHistoryEntry"
}
func (cmd *AsyncNavigateToHistoryEntryCommand) Params() interface{} {
return cmd.params
}
func (cmd *NavigateToHistoryEntryCommand) Done(data []byte, err error) {
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncNavigateToHistoryEntryCommand) Done(data []byte, err error) {
cmd.cb(err)
}
type PageGetCookiesResult struct {
Cookies []*Cookie `json:"cookies"` // Array of cookie objects.
}
// Returns all browser cookies. Depending on the backend support, will return detailed cookie information in the cookies field.
// @experimental
type PageGetCookiesCommand struct {
result PageGetCookiesResult
wg sync.WaitGroup
err error
}
func NewPageGetCookiesCommand() *PageGetCookiesCommand {
return &PageGetCookiesCommand{}
}
func (cmd *PageGetCookiesCommand) Name() string {
return "Page.getCookies"
}
func (cmd *PageGetCookiesCommand) Params() interface{} {
return nil
}
func (cmd *PageGetCookiesCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func PageGetCookies(conn *hc.Conn) (result *PageGetCookiesResult, err error) {
cmd := NewPageGetCookiesCommand()
cmd.Run(conn)
return &cmd.result, cmd.err
}
type PageGetCookiesCB func(result *PageGetCookiesResult, err error)
// Returns all browser cookies. Depending on the backend support, will return detailed cookie information in the cookies field.
// @experimental
type AsyncPageGetCookiesCommand struct {
cb PageGetCookiesCB
}
func NewAsyncPageGetCookiesCommand(cb PageGetCookiesCB) *AsyncPageGetCookiesCommand {
return &AsyncPageGetCookiesCommand{
cb: cb,
}
}
func (cmd *AsyncPageGetCookiesCommand) Name() string {
return "Page.getCookies"
}
func (cmd *AsyncPageGetCookiesCommand) Params() interface{} {
return nil
}
func (cmd *PageGetCookiesCommand) Result() *PageGetCookiesResult {
return &cmd.result
}
func (cmd *PageGetCookiesCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncPageGetCookiesCommand) Done(data []byte, err error) {
var result PageGetCookiesResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
type PageDeleteCookieParams struct {
CookieName string `json:"cookieName"` // Name of the cookie to remove.
Url string `json:"url"` // URL to match cooke domain and path.
}
// Deletes browser cookie with given name, domain and path.
// @experimental
type PageDeleteCookieCommand struct {
params *PageDeleteCookieParams
wg sync.WaitGroup
err error
}
func NewPageDeleteCookieCommand(params *PageDeleteCookieParams) *PageDeleteCookieCommand {
return &PageDeleteCookieCommand{
params: params,
}
}
func (cmd *PageDeleteCookieCommand) Name() string {
return "Page.deleteCookie"
}
func (cmd *PageDeleteCookieCommand) Params() interface{} {
return cmd.params
}
func (cmd *PageDeleteCookieCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func PageDeleteCookie(params *PageDeleteCookieParams, conn *hc.Conn) (err error) {
cmd := NewPageDeleteCookieCommand(params)