forked from chromedp/chromedp
/
page.go
904 lines (775 loc) · 30.6 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
// Package page provides the Chrome Debugging Protocol
// commands, types, and events for the Page domain.
//
// Actions and events related to the inspected page belong to the page
// domain.
//
// Generated by the chromedp-gen command.
package page
// AUTOGENERATED. DO NOT EDIT.
import (
"context"
"encoding/base64"
cdp "github.com/knq/chromedp/cdp"
"github.com/knq/chromedp/cdp/debugger"
"github.com/knq/chromedp/cdp/dom"
)
// EnableParams enables page domain notifications.
type EnableParams struct{}
// Enable enables page domain notifications.
func Enable() *EnableParams {
return &EnableParams{}
}
// Do executes Page.enable against the provided context and
// target handler.
func (p *EnableParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageEnable, nil, nil)
}
// DisableParams disables page domain notifications.
type DisableParams struct{}
// Disable disables page domain notifications.
func Disable() *DisableParams {
return &DisableParams{}
}
// Do executes Page.disable against the provided context and
// target handler.
func (p *DisableParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageDisable, nil, nil)
}
// AddScriptToEvaluateOnLoadParams [no description].
type AddScriptToEvaluateOnLoadParams struct {
ScriptSource string `json:"scriptSource"`
}
// AddScriptToEvaluateOnLoad [no description].
//
// parameters:
// scriptSource
func AddScriptToEvaluateOnLoad(scriptSource string) *AddScriptToEvaluateOnLoadParams {
return &AddScriptToEvaluateOnLoadParams{
ScriptSource: scriptSource,
}
}
// AddScriptToEvaluateOnLoadReturns return values.
type AddScriptToEvaluateOnLoadReturns struct {
Identifier ScriptIdentifier `json:"identifier,omitempty"` // Identifier of the added script.
}
// Do executes Page.addScriptToEvaluateOnLoad against the provided context and
// target handler.
//
// returns:
// identifier - Identifier of the added script.
func (p *AddScriptToEvaluateOnLoadParams) Do(ctxt context.Context, h cdp.Handler) (identifier ScriptIdentifier, err error) {
// execute
var res AddScriptToEvaluateOnLoadReturns
err = h.Execute(ctxt, cdp.CommandPageAddScriptToEvaluateOnLoad, p, &res)
if err != nil {
return "", err
}
return res.Identifier, nil
}
// RemoveScriptToEvaluateOnLoadParams [no description].
type RemoveScriptToEvaluateOnLoadParams struct {
Identifier ScriptIdentifier `json:"identifier"`
}
// RemoveScriptToEvaluateOnLoad [no description].
//
// parameters:
// identifier
func RemoveScriptToEvaluateOnLoad(identifier ScriptIdentifier) *RemoveScriptToEvaluateOnLoadParams {
return &RemoveScriptToEvaluateOnLoadParams{
Identifier: identifier,
}
}
// Do executes Page.removeScriptToEvaluateOnLoad against the provided context and
// target handler.
func (p *RemoveScriptToEvaluateOnLoadParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageRemoveScriptToEvaluateOnLoad, p, nil)
}
// SetAutoAttachToCreatedPagesParams controls whether browser will open a new
// inspector window for connected pages.
type SetAutoAttachToCreatedPagesParams struct {
AutoAttach bool `json:"autoAttach"` // If true, browser will open a new inspector window for every page created from this one.
}
// SetAutoAttachToCreatedPages controls whether browser will open a new
// inspector window for connected pages.
//
// parameters:
// autoAttach - If true, browser will open a new inspector window for every page created from this one.
func SetAutoAttachToCreatedPages(autoAttach bool) *SetAutoAttachToCreatedPagesParams {
return &SetAutoAttachToCreatedPagesParams{
AutoAttach: autoAttach,
}
}
// Do executes Page.setAutoAttachToCreatedPages against the provided context and
// target handler.
func (p *SetAutoAttachToCreatedPagesParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageSetAutoAttachToCreatedPages, p, nil)
}
// ReloadParams reloads given page optionally ignoring the cache.
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.
}
// Reload reloads given page optionally ignoring the cache.
//
// parameters:
func Reload() *ReloadParams {
return &ReloadParams{}
}
// WithIgnoreCache if true, browser cache is ignored (as if the user pressed
// Shift+refresh).
func (p ReloadParams) WithIgnoreCache(ignoreCache bool) *ReloadParams {
p.IgnoreCache = ignoreCache
return &p
}
// WithScriptToEvaluateOnLoad if set, the script will be injected into all
// frames of the inspected page after reload.
func (p ReloadParams) WithScriptToEvaluateOnLoad(scriptToEvaluateOnLoad string) *ReloadParams {
p.ScriptToEvaluateOnLoad = scriptToEvaluateOnLoad
return &p
}
// Do executes Page.reload against the provided context and
// target handler.
func (p *ReloadParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageReload, p, nil)
}
// NavigateParams navigates current page to the given URL.
type NavigateParams struct {
URL string `json:"url"` // URL to navigate the page to.
Referrer string `json:"referrer,omitempty"` // Referrer URL.
TransitionType TransitionType `json:"transitionType,omitempty"` // Intended transition type.
}
// Navigate navigates current page to the given URL.
//
// parameters:
// url - URL to navigate the page to.
func Navigate(url string) *NavigateParams {
return &NavigateParams{
URL: url,
}
}
// WithReferrer referrer URL.
func (p NavigateParams) WithReferrer(referrer string) *NavigateParams {
p.Referrer = referrer
return &p
}
// WithTransitionType intended transition type.
func (p NavigateParams) WithTransitionType(transitionType TransitionType) *NavigateParams {
p.TransitionType = transitionType
return &p
}
// NavigateReturns return values.
type NavigateReturns struct {
FrameID cdp.FrameID `json:"frameId,omitempty"` // Frame id that will be navigated.
}
// Do executes Page.navigate against the provided context and
// target handler.
//
// returns:
// frameID - Frame id that will be navigated.
func (p *NavigateParams) Do(ctxt context.Context, h cdp.Handler) (frameID cdp.FrameID, err error) {
// execute
var res NavigateReturns
err = h.Execute(ctxt, cdp.CommandPageNavigate, p, &res)
if err != nil {
return "", err
}
return res.FrameID, nil
}
// StopLoadingParams force the page stop all navigations and pending resource
// fetches.
type StopLoadingParams struct{}
// StopLoading force the page stop all navigations and pending resource
// fetches.
func StopLoading() *StopLoadingParams {
return &StopLoadingParams{}
}
// Do executes Page.stopLoading against the provided context and
// target handler.
func (p *StopLoadingParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageStopLoading, nil, nil)
}
// GetNavigationHistoryParams returns navigation history for the current
// page.
type GetNavigationHistoryParams struct{}
// GetNavigationHistory returns navigation history for the current page.
func GetNavigationHistory() *GetNavigationHistoryParams {
return &GetNavigationHistoryParams{}
}
// GetNavigationHistoryReturns return values.
type GetNavigationHistoryReturns struct {
CurrentIndex int64 `json:"currentIndex,omitempty"` // Index of the current navigation history entry.
Entries []*NavigationEntry `json:"entries,omitempty"` // Array of navigation history entries.
}
// Do executes Page.getNavigationHistory against the provided context and
// target handler.
//
// returns:
// currentIndex - Index of the current navigation history entry.
// entries - Array of navigation history entries.
func (p *GetNavigationHistoryParams) Do(ctxt context.Context, h cdp.Handler) (currentIndex int64, entries []*NavigationEntry, err error) {
// execute
var res GetNavigationHistoryReturns
err = h.Execute(ctxt, cdp.CommandPageGetNavigationHistory, nil, &res)
if err != nil {
return 0, nil, err
}
return res.CurrentIndex, res.Entries, nil
}
// NavigateToHistoryEntryParams navigates current page to the given history
// entry.
type NavigateToHistoryEntryParams struct {
EntryID int64 `json:"entryId"` // Unique id of the entry to navigate to.
}
// NavigateToHistoryEntry navigates current page to the given history entry.
//
// parameters:
// entryID - Unique id of the entry to navigate to.
func NavigateToHistoryEntry(entryID int64) *NavigateToHistoryEntryParams {
return &NavigateToHistoryEntryParams{
EntryID: entryID,
}
}
// Do executes Page.navigateToHistoryEntry against the provided context and
// target handler.
func (p *NavigateToHistoryEntryParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageNavigateToHistoryEntry, p, nil)
}
// GetResourceTreeParams returns present frame / resource tree structure.
type GetResourceTreeParams struct{}
// GetResourceTree returns present frame / resource tree structure.
func GetResourceTree() *GetResourceTreeParams {
return &GetResourceTreeParams{}
}
// GetResourceTreeReturns return values.
type GetResourceTreeReturns struct {
FrameTree *FrameResourceTree `json:"frameTree,omitempty"` // Present frame / resource tree structure.
}
// Do executes Page.getResourceTree against the provided context and
// target handler.
//
// returns:
// frameTree - Present frame / resource tree structure.
func (p *GetResourceTreeParams) Do(ctxt context.Context, h cdp.Handler) (frameTree *FrameResourceTree, err error) {
// execute
var res GetResourceTreeReturns
err = h.Execute(ctxt, cdp.CommandPageGetResourceTree, nil, &res)
if err != nil {
return nil, err
}
return res.FrameTree, nil
}
// GetResourceContentParams returns content of the given resource.
type GetResourceContentParams struct {
FrameID cdp.FrameID `json:"frameId"` // Frame id to get resource for.
URL string `json:"url"` // URL of the resource to get content for.
}
// GetResourceContent returns content of the given resource.
//
// parameters:
// frameID - Frame id to get resource for.
// url - URL of the resource to get content for.
func GetResourceContent(frameID cdp.FrameID, url string) *GetResourceContentParams {
return &GetResourceContentParams{
FrameID: frameID,
URL: url,
}
}
// GetResourceContentReturns return values.
type GetResourceContentReturns struct {
Content string `json:"content,omitempty"` // Resource content.
Base64encoded bool `json:"base64Encoded,omitempty"` // True, if content was served as base64.
}
// Do executes Page.getResourceContent against the provided context and
// target handler.
//
// returns:
// content - Resource content.
func (p *GetResourceContentParams) Do(ctxt context.Context, h cdp.Handler) (content []byte, err error) {
// execute
var res GetResourceContentReturns
err = h.Execute(ctxt, cdp.CommandPageGetResourceContent, p, &res)
if err != nil {
return nil, err
}
// decode
var dec []byte
if res.Base64encoded {
dec, err = base64.StdEncoding.DecodeString(res.Content)
if err != nil {
return nil, err
}
} else {
dec = []byte(res.Content)
}
return dec, nil
}
// SearchInResourceParams searches for given string in resource content.
type SearchInResourceParams struct {
FrameID cdp.FrameID `json:"frameId"` // Frame id for resource to search in.
URL string `json:"url"` // URL of the resource to search in.
Query string `json:"query"` // String to search for.
CaseSensitive bool `json:"caseSensitive,omitempty"` // If true, search is case sensitive.
IsRegex bool `json:"isRegex,omitempty"` // If true, treats string parameter as regex.
}
// SearchInResource searches for given string in resource content.
//
// parameters:
// frameID - Frame id for resource to search in.
// url - URL of the resource to search in.
// query - String to search for.
func SearchInResource(frameID cdp.FrameID, url string, query string) *SearchInResourceParams {
return &SearchInResourceParams{
FrameID: frameID,
URL: url,
Query: query,
}
}
// WithCaseSensitive if true, search is case sensitive.
func (p SearchInResourceParams) WithCaseSensitive(caseSensitive bool) *SearchInResourceParams {
p.CaseSensitive = caseSensitive
return &p
}
// WithIsRegex if true, treats string parameter as regex.
func (p SearchInResourceParams) WithIsRegex(isRegex bool) *SearchInResourceParams {
p.IsRegex = isRegex
return &p
}
// SearchInResourceReturns return values.
type SearchInResourceReturns struct {
Result []*debugger.SearchMatch `json:"result,omitempty"` // List of search matches.
}
// Do executes Page.searchInResource against the provided context and
// target handler.
//
// returns:
// result - List of search matches.
func (p *SearchInResourceParams) Do(ctxt context.Context, h cdp.Handler) (result []*debugger.SearchMatch, err error) {
// execute
var res SearchInResourceReturns
err = h.Execute(ctxt, cdp.CommandPageSearchInResource, p, &res)
if err != nil {
return nil, err
}
return res.Result, nil
}
// SetDocumentContentParams sets given markup as the document's HTML.
type SetDocumentContentParams struct {
FrameID cdp.FrameID `json:"frameId"` // Frame id to set HTML for.
HTML string `json:"html"` // HTML content to set.
}
// SetDocumentContent sets given markup as the document's HTML.
//
// parameters:
// frameID - Frame id to set HTML for.
// html - HTML content to set.
func SetDocumentContent(frameID cdp.FrameID, html string) *SetDocumentContentParams {
return &SetDocumentContentParams{
FrameID: frameID,
HTML: html,
}
}
// Do executes Page.setDocumentContent against the provided context and
// target handler.
func (p *SetDocumentContentParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageSetDocumentContent, p, nil)
}
// CaptureScreenshotParams capture page screenshot.
type CaptureScreenshotParams struct {
Format CaptureScreenshotFormat `json:"format,omitempty"` // Image compression format (defaults to png).
Quality int64 `json:"quality,omitempty"` // Compression quality from range [0..100] (jpeg only).
FromSurface bool `json:"fromSurface,omitempty"` // Capture the screenshot from the surface, rather than the view. Defaults to true.
}
// CaptureScreenshot capture page screenshot.
//
// parameters:
func CaptureScreenshot() *CaptureScreenshotParams {
return &CaptureScreenshotParams{}
}
// WithFormat image compression format (defaults to png).
func (p CaptureScreenshotParams) WithFormat(format CaptureScreenshotFormat) *CaptureScreenshotParams {
p.Format = format
return &p
}
// WithQuality compression quality from range [0..100] (jpeg only).
func (p CaptureScreenshotParams) WithQuality(quality int64) *CaptureScreenshotParams {
p.Quality = quality
return &p
}
// WithFromSurface capture the screenshot from the surface, rather than the
// view. Defaults to true.
func (p CaptureScreenshotParams) WithFromSurface(fromSurface bool) *CaptureScreenshotParams {
p.FromSurface = fromSurface
return &p
}
// CaptureScreenshotReturns return values.
type CaptureScreenshotReturns struct {
Data string `json:"data,omitempty"` // Base64-encoded image data.
}
// Do executes Page.captureScreenshot against the provided context and
// target handler.
//
// returns:
// data - Base64-encoded image data.
func (p *CaptureScreenshotParams) Do(ctxt context.Context, h cdp.Handler) (data []byte, err error) {
// execute
var res CaptureScreenshotReturns
err = h.Execute(ctxt, cdp.CommandPageCaptureScreenshot, p, &res)
if err != nil {
return nil, err
}
// decode
var dec []byte
dec, err = base64.StdEncoding.DecodeString(res.Data)
if err != nil {
return nil, err
}
return dec, nil
}
// PrintToPDFParams print page as PDF.
type PrintToPDFParams struct {
Landscape bool `json:"landscape,omitempty"` // Paper orientation. Defaults to false.
DisplayHeaderFooter bool `json:"displayHeaderFooter,omitempty"` // Display header and footer. Defaults to false.
PrintBackground bool `json:"printBackground,omitempty"` // Print background graphics. Defaults to false.
Scale float64 `json:"scale,omitempty"` // Scale of the webpage rendering. Defaults to 1.
PaperWidth float64 `json:"paperWidth,omitempty"` // Paper width in inches. Defaults to 8.5 inches.
PaperHeight float64 `json:"paperHeight,omitempty"` // Paper height in inches. Defaults to 11 inches.
MarginTop float64 `json:"marginTop,omitempty"` // Top margin in inches. Defaults to 1cm (~0.4 inches).
MarginBottom float64 `json:"marginBottom,omitempty"` // Bottom margin in inches. Defaults to 1cm (~0.4 inches).
MarginLeft float64 `json:"marginLeft,omitempty"` // Left margin in inches. Defaults to 1cm (~0.4 inches).
MarginRight float64 `json:"marginRight,omitempty"` // Right margin in inches. Defaults to 1cm (~0.4 inches).
PageRanges string `json:"pageRanges,omitempty"` // Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
}
// PrintToPDF print page as PDF.
//
// parameters:
func PrintToPDF() *PrintToPDFParams {
return &PrintToPDFParams{}
}
// WithLandscape paper orientation. Defaults to false.
func (p PrintToPDFParams) WithLandscape(landscape bool) *PrintToPDFParams {
p.Landscape = landscape
return &p
}
// WithDisplayHeaderFooter display header and footer. Defaults to false.
func (p PrintToPDFParams) WithDisplayHeaderFooter(displayHeaderFooter bool) *PrintToPDFParams {
p.DisplayHeaderFooter = displayHeaderFooter
return &p
}
// WithPrintBackground print background graphics. Defaults to false.
func (p PrintToPDFParams) WithPrintBackground(printBackground bool) *PrintToPDFParams {
p.PrintBackground = printBackground
return &p
}
// WithScale scale of the webpage rendering. Defaults to 1.
func (p PrintToPDFParams) WithScale(scale float64) *PrintToPDFParams {
p.Scale = scale
return &p
}
// WithPaperWidth paper width in inches. Defaults to 8.5 inches.
func (p PrintToPDFParams) WithPaperWidth(paperWidth float64) *PrintToPDFParams {
p.PaperWidth = paperWidth
return &p
}
// WithPaperHeight paper height in inches. Defaults to 11 inches.
func (p PrintToPDFParams) WithPaperHeight(paperHeight float64) *PrintToPDFParams {
p.PaperHeight = paperHeight
return &p
}
// WithMarginTop top margin in inches. Defaults to 1cm (~0.4 inches).
func (p PrintToPDFParams) WithMarginTop(marginTop float64) *PrintToPDFParams {
p.MarginTop = marginTop
return &p
}
// WithMarginBottom bottom margin in inches. Defaults to 1cm (~0.4 inches).
func (p PrintToPDFParams) WithMarginBottom(marginBottom float64) *PrintToPDFParams {
p.MarginBottom = marginBottom
return &p
}
// WithMarginLeft left margin in inches. Defaults to 1cm (~0.4 inches).
func (p PrintToPDFParams) WithMarginLeft(marginLeft float64) *PrintToPDFParams {
p.MarginLeft = marginLeft
return &p
}
// WithMarginRight right margin in inches. Defaults to 1cm (~0.4 inches).
func (p PrintToPDFParams) WithMarginRight(marginRight float64) *PrintToPDFParams {
p.MarginRight = marginRight
return &p
}
// WithPageRanges paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to
// the empty string, which means print all pages.
func (p PrintToPDFParams) WithPageRanges(pageRanges string) *PrintToPDFParams {
p.PageRanges = pageRanges
return &p
}
// PrintToPDFReturns return values.
type PrintToPDFReturns struct {
Data string `json:"data,omitempty"` // Base64-encoded pdf data.
}
// Do executes Page.printToPDF against the provided context and
// target handler.
//
// returns:
// data - Base64-encoded pdf data.
func (p *PrintToPDFParams) Do(ctxt context.Context, h cdp.Handler) (data []byte, err error) {
// execute
var res PrintToPDFReturns
err = h.Execute(ctxt, cdp.CommandPagePrintToPDF, p, &res)
if err != nil {
return nil, err
}
// decode
var dec []byte
dec, err = base64.StdEncoding.DecodeString(res.Data)
if err != nil {
return nil, err
}
return dec, nil
}
// StartScreencastParams starts sending each frame using the screencastFrame
// event.
type StartScreencastParams struct {
Format ScreencastFormat `json:"format,omitempty"` // Image compression format.
Quality int64 `json:"quality,omitempty"` // Compression quality from range [0..100].
MaxWidth int64 `json:"maxWidth,omitempty"` // Maximum screenshot width.
MaxHeight int64 `json:"maxHeight,omitempty"` // Maximum screenshot height.
EveryNthFrame int64 `json:"everyNthFrame,omitempty"` // Send every n-th frame.
}
// StartScreencast starts sending each frame using the screencastFrame event.
//
// parameters:
func StartScreencast() *StartScreencastParams {
return &StartScreencastParams{}
}
// WithFormat image compression format.
func (p StartScreencastParams) WithFormat(format ScreencastFormat) *StartScreencastParams {
p.Format = format
return &p
}
// WithQuality compression quality from range [0..100].
func (p StartScreencastParams) WithQuality(quality int64) *StartScreencastParams {
p.Quality = quality
return &p
}
// WithMaxWidth maximum screenshot width.
func (p StartScreencastParams) WithMaxWidth(maxWidth int64) *StartScreencastParams {
p.MaxWidth = maxWidth
return &p
}
// WithMaxHeight maximum screenshot height.
func (p StartScreencastParams) WithMaxHeight(maxHeight int64) *StartScreencastParams {
p.MaxHeight = maxHeight
return &p
}
// WithEveryNthFrame send every n-th frame.
func (p StartScreencastParams) WithEveryNthFrame(everyNthFrame int64) *StartScreencastParams {
p.EveryNthFrame = everyNthFrame
return &p
}
// Do executes Page.startScreencast against the provided context and
// target handler.
func (p *StartScreencastParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageStartScreencast, p, nil)
}
// StopScreencastParams stops sending each frame in the screencastFrame.
type StopScreencastParams struct{}
// StopScreencast stops sending each frame in the screencastFrame.
func StopScreencast() *StopScreencastParams {
return &StopScreencastParams{}
}
// Do executes Page.stopScreencast against the provided context and
// target handler.
func (p *StopScreencastParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageStopScreencast, nil, nil)
}
// ScreencastFrameAckParams acknowledges that a screencast frame has been
// received by the frontend.
type ScreencastFrameAckParams struct {
SessionID int64 `json:"sessionId"` // Frame number.
}
// ScreencastFrameAck acknowledges that a screencast frame has been received
// by the frontend.
//
// parameters:
// sessionID - Frame number.
func ScreencastFrameAck(sessionID int64) *ScreencastFrameAckParams {
return &ScreencastFrameAckParams{
SessionID: sessionID,
}
}
// Do executes Page.screencastFrameAck against the provided context and
// target handler.
func (p *ScreencastFrameAckParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageScreencastFrameAck, p, nil)
}
// HandleJavaScriptDialogParams accepts or dismisses a JavaScript initiated
// dialog (alert, confirm, prompt, or onbeforeunload).
type HandleJavaScriptDialogParams struct {
Accept bool `json:"accept"` // Whether to accept or dismiss the dialog.
PromptText string `json:"promptText,omitempty"` // The text to enter into the dialog prompt before accepting. Used only if this is a prompt dialog.
}
// HandleJavaScriptDialog accepts or dismisses a JavaScript initiated dialog
// (alert, confirm, prompt, or onbeforeunload).
//
// parameters:
// accept - Whether to accept or dismiss the dialog.
func HandleJavaScriptDialog(accept bool) *HandleJavaScriptDialogParams {
return &HandleJavaScriptDialogParams{
Accept: accept,
}
}
// WithPromptText the text to enter into the dialog prompt before accepting.
// Used only if this is a prompt dialog.
func (p HandleJavaScriptDialogParams) WithPromptText(promptText string) *HandleJavaScriptDialogParams {
p.PromptText = promptText
return &p
}
// Do executes Page.handleJavaScriptDialog against the provided context and
// target handler.
func (p *HandleJavaScriptDialogParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageHandleJavaScriptDialog, p, nil)
}
// GetAppManifestParams [no description].
type GetAppManifestParams struct{}
// GetAppManifest [no description].
func GetAppManifest() *GetAppManifestParams {
return &GetAppManifestParams{}
}
// GetAppManifestReturns return values.
type GetAppManifestReturns struct {
URL string `json:"url,omitempty"` // Manifest location.
Errors []*AppManifestError `json:"errors,omitempty"`
Data string `json:"data,omitempty"` // Manifest content.
}
// Do executes Page.getAppManifest against the provided context and
// target handler.
//
// returns:
// url - Manifest location.
// errors
// data - Manifest content.
func (p *GetAppManifestParams) Do(ctxt context.Context, h cdp.Handler) (url string, errors []*AppManifestError, data string, err error) {
// execute
var res GetAppManifestReturns
err = h.Execute(ctxt, cdp.CommandPageGetAppManifest, nil, &res)
if err != nil {
return "", nil, "", err
}
return res.URL, res.Errors, res.Data, nil
}
// RequestAppBannerParams [no description].
type RequestAppBannerParams struct{}
// RequestAppBanner [no description].
func RequestAppBanner() *RequestAppBannerParams {
return &RequestAppBannerParams{}
}
// Do executes Page.requestAppBanner against the provided context and
// target handler.
func (p *RequestAppBannerParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageRequestAppBanner, nil, nil)
}
// SetControlNavigationsParams toggles navigation throttling which allows
// programatic control over navigation and redirect response.
type SetControlNavigationsParams struct {
Enabled bool `json:"enabled"`
}
// SetControlNavigations toggles navigation throttling which allows
// programatic control over navigation and redirect response.
//
// parameters:
// enabled
func SetControlNavigations(enabled bool) *SetControlNavigationsParams {
return &SetControlNavigationsParams{
Enabled: enabled,
}
}
// Do executes Page.setControlNavigations against the provided context and
// target handler.
func (p *SetControlNavigationsParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageSetControlNavigations, p, nil)
}
// ProcessNavigationParams should be sent in response to a
// navigationRequested or a redirectRequested event, telling the browser how to
// handle the navigation.
type ProcessNavigationParams struct {
Response NavigationResponse `json:"response"`
NavigationID int64 `json:"navigationId"`
}
// ProcessNavigation should be sent in response to a navigationRequested or a
// redirectRequested event, telling the browser how to handle the navigation.
//
// parameters:
// response
// navigationID
func ProcessNavigation(response NavigationResponse, navigationID int64) *ProcessNavigationParams {
return &ProcessNavigationParams{
Response: response,
NavigationID: navigationID,
}
}
// Do executes Page.processNavigation against the provided context and
// target handler.
func (p *ProcessNavigationParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageProcessNavigation, p, nil)
}
// GetLayoutMetricsParams returns metrics relating to the layouting of the
// page, such as viewport bounds/scale.
type GetLayoutMetricsParams struct{}
// GetLayoutMetrics returns metrics relating to the layouting of the page,
// such as viewport bounds/scale.
func GetLayoutMetrics() *GetLayoutMetricsParams {
return &GetLayoutMetricsParams{}
}
// GetLayoutMetricsReturns return values.
type GetLayoutMetricsReturns struct {
LayoutViewport *LayoutViewport `json:"layoutViewport,omitempty"` // Metrics relating to the layout viewport.
VisualViewport *VisualViewport `json:"visualViewport,omitempty"` // Metrics relating to the visual viewport.
ContentSize *dom.Rect `json:"contentSize,omitempty"` // Size of scrollable area.
}
// Do executes Page.getLayoutMetrics against the provided context and
// target handler.
//
// returns:
// layoutViewport - Metrics relating to the layout viewport.
// visualViewport - Metrics relating to the visual viewport.
// contentSize - Size of scrollable area.
func (p *GetLayoutMetricsParams) Do(ctxt context.Context, h cdp.Handler) (layoutViewport *LayoutViewport, visualViewport *VisualViewport, contentSize *dom.Rect, err error) {
// execute
var res GetLayoutMetricsReturns
err = h.Execute(ctxt, cdp.CommandPageGetLayoutMetrics, nil, &res)
if err != nil {
return nil, nil, nil, err
}
return res.LayoutViewport, res.VisualViewport, res.ContentSize, nil
}
// CreateIsolatedWorldParams creates an isolated world for the given frame.
type CreateIsolatedWorldParams struct {
FrameID cdp.FrameID `json:"frameId"` // Id of the frame in which the isolated world should be created.
WorldName string `json:"worldName,omitempty"` // An optional name which is reported in the Execution Context.
GrantUniveralAccess bool `json:"grantUniveralAccess,omitempty"` // Whether or not universal access should be granted to the isolated world. This is a powerful option, use with caution.
}
// CreateIsolatedWorld creates an isolated world for the given frame.
//
// parameters:
// frameID - Id of the frame in which the isolated world should be created.
func CreateIsolatedWorld(frameID cdp.FrameID) *CreateIsolatedWorldParams {
return &CreateIsolatedWorldParams{
FrameID: frameID,
}
}
// WithWorldName an optional name which is reported in the Execution Context.
func (p CreateIsolatedWorldParams) WithWorldName(worldName string) *CreateIsolatedWorldParams {
p.WorldName = worldName
return &p
}
// WithGrantUniveralAccess whether or not universal access should be granted
// to the isolated world. This is a powerful option, use with caution.
func (p CreateIsolatedWorldParams) WithGrantUniveralAccess(grantUniveralAccess bool) *CreateIsolatedWorldParams {
p.GrantUniveralAccess = grantUniveralAccess
return &p
}
// Do executes Page.createIsolatedWorld against the provided context and
// target handler.
func (p *CreateIsolatedWorldParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageCreateIsolatedWorld, p, nil)
}