chromedp/cdp/page/page.go

1031 lines
36 KiB
Go
Raw Normal View History

2017-01-24 15:09:23 +00:00
// Package page provides the Chrome Debugging Protocol
// commands, types, and events for the Page domain.
2017-01-24 15:09:23 +00:00
//
// Actions and events related to the inspected page belong to the page
// domain.
//
// Generated by the chromedp-gen command.
package page
// Code generated by chromedp-gen. DO NOT EDIT.
2017-01-24 15:09:23 +00:00
import (
"context"
"encoding/base64"
2017-01-26 07:28:34 +00:00
cdp "github.com/knq/chromedp/cdp"
2017-01-24 15:09:23 +00:00
"github.com/knq/chromedp/cdp/debugger"
2017-02-25 00:21:58 +00:00
"github.com/knq/chromedp/cdp/dom"
2017-06-25 01:38:47 +00:00
"github.com/knq/chromedp/cdp/runtime"
2017-01-24 15:09:23 +00:00
)
// AddScriptToEvaluateOnNewDocumentParams evaluates given script in every
// frame upon creation (before loading frame's scripts).
type AddScriptToEvaluateOnNewDocumentParams struct {
Source string `json:"source"`
2017-01-24 15:09:23 +00:00
}
// AddScriptToEvaluateOnNewDocument evaluates given script in every frame
// upon creation (before loading frame's scripts).
2017-01-26 07:28:34 +00:00
//
2017-01-24 15:09:23 +00:00
// parameters:
// source
func AddScriptToEvaluateOnNewDocument(source string) *AddScriptToEvaluateOnNewDocumentParams {
return &AddScriptToEvaluateOnNewDocumentParams{
Source: source,
2017-01-24 15:09:23 +00:00
}
}
// AddScriptToEvaluateOnNewDocumentReturns return values.
type AddScriptToEvaluateOnNewDocumentReturns struct {
2017-01-24 15:09:23 +00:00
Identifier ScriptIdentifier `json:"identifier,omitempty"` // Identifier of the added script.
}
// Do executes Page.addScriptToEvaluateOnNewDocument against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
// identifier - Identifier of the added script.
func (p *AddScriptToEvaluateOnNewDocumentParams) Do(ctxt context.Context, h cdp.Handler) (identifier ScriptIdentifier, err error) {
// execute
var res AddScriptToEvaluateOnNewDocumentReturns
err = h.Execute(ctxt, cdp.CommandPageAddScriptToEvaluateOnNewDocument, p, &res)
2017-01-24 15:09:23 +00:00
if err != nil {
return "", err
}
return res.Identifier, nil
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// BringToFrontParams brings page to front (activates tab).
type BringToFrontParams struct{}
2017-01-24 15:09:23 +00:00
2017-12-18 00:23:14 +00:00
// BringToFront brings page to front (activates tab).
func BringToFront() *BringToFrontParams {
return &BringToFrontParams{}
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.bringToFront against the provided context and
// target handler.
2017-12-18 00:23:14 +00:00
func (p *BringToFrontParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageBringToFront, nil, nil)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// 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).
Clip *Viewport `json:"clip,omitempty"` // Capture the screenshot of a given region only.
FromSurface bool `json:"fromSurface,omitempty"` // Capture the screenshot from the surface, rather than the view. Defaults to true.
2017-11-22 05:01:27 +00:00
}
2017-12-18 00:23:14 +00:00
// CaptureScreenshot capture page screenshot.
2017-11-22 05:01:27 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
func CaptureScreenshot() *CaptureScreenshotParams {
return &CaptureScreenshotParams{}
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// WithFormat image compression format (defaults to png).
func (p CaptureScreenshotParams) WithFormat(format CaptureScreenshotFormat) *CaptureScreenshotParams {
p.Format = format
return &p
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// WithQuality compression quality from range [0..100] (jpeg only).
func (p CaptureScreenshotParams) WithQuality(quality int64) *CaptureScreenshotParams {
p.Quality = quality
2017-01-24 15:09:23 +00:00
return &p
}
2017-12-18 00:23:14 +00:00
// WithClip capture the screenshot of a given region only.
func (p CaptureScreenshotParams) WithClip(clip *Viewport) *CaptureScreenshotParams {
p.Clip = clip
2017-01-24 15:09:23 +00:00
return &p
}
2017-12-18 00:23:14 +00:00
// 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
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// CaptureScreenshotReturns return values.
type CaptureScreenshotReturns struct {
Data string `json:"data,omitempty"` // Base64-encoded image data.
2017-07-31 02:26:12 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.captureScreenshot against the provided context and
// target handler.
2017-07-31 02:26:12 +00:00
//
2017-12-18 00:23:14 +00:00
// 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
2017-07-31 02:26:12 +00:00
}
2017-12-18 00:23:14 +00:00
// decode
var dec []byte
dec, err = base64.StdEncoding.DecodeString(res.Data)
if err != nil {
return nil, err
}
return dec, nil
2017-07-31 02:26:12 +00:00
}
2017-12-18 00:23:14 +00:00
// 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.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// CreateIsolatedWorld creates an isolated world for the given frame.
2017-01-24 15:09:23 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
// frameID - Id of the frame in which the isolated world should be created.
func CreateIsolatedWorld(frameID cdp.FrameID) *CreateIsolatedWorldParams {
return &CreateIsolatedWorldParams{
FrameID: frameID,
2017-01-24 15:09:23 +00:00
}
}
2017-12-18 00:23:14 +00:00
// WithWorldName an optional name which is reported in the Execution Context.
func (p CreateIsolatedWorldParams) WithWorldName(worldName string) *CreateIsolatedWorldParams {
p.WorldName = worldName
2017-02-25 00:21:58 +00:00
return &p
}
2017-12-18 00:23:14 +00:00
// 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
2017-05-24 02:36:12 +00:00
return &p
}
2017-12-18 00:23:14 +00:00
// CreateIsolatedWorldReturns return values.
type CreateIsolatedWorldReturns struct {
ExecutionContextID runtime.ExecutionContextID `json:"executionContextId,omitempty"` // Execution context of the isolated world.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.createIsolatedWorld against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-12-18 00:23:14 +00:00
// executionContextID - Execution context of the isolated world.
func (p *CreateIsolatedWorldParams) Do(ctxt context.Context, h cdp.Handler) (executionContextID runtime.ExecutionContextID, err error) {
// execute
2017-12-18 00:23:14 +00:00
var res CreateIsolatedWorldReturns
err = h.Execute(ctxt, cdp.CommandPageCreateIsolatedWorld, p, &res)
2017-01-24 15:09:23 +00:00
if err != nil {
2017-12-18 00:23:14 +00:00
return 0, err
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
return res.ExecutionContextID, nil
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// DisableParams disables page domain notifications.
type DisableParams struct{}
2017-01-24 15:09:23 +00:00
2017-12-18 00:23:14 +00:00
// Disable disables page domain notifications.
func Disable() *DisableParams {
return &DisableParams{}
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.disable against the provided context and
// target handler.
2017-12-18 00:23:14 +00:00
func (p *DisableParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageDisable, nil, nil)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// EnableParams enables page domain notifications.
type EnableParams struct{}
2017-01-24 15:09:23 +00:00
2017-12-18 00:23:14 +00:00
// Enable enables page domain notifications.
func Enable() *EnableParams {
return &EnableParams{}
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.enable against the provided context and
// target handler.
2017-12-18 00:23:14 +00:00
func (p *EnableParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageEnable, nil, nil)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// GetAppManifestParams [no description].
type GetAppManifestParams struct{}
2017-01-24 15:09:23 +00:00
2017-12-18 00:23:14 +00:00
// GetAppManifest [no description].
func GetAppManifest() *GetAppManifestParams {
return &GetAppManifestParams{}
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// 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.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.getAppManifest against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-12-18 00:23:14 +00:00
// 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) {
2017-01-24 15:09:23 +00:00
// execute
2017-12-18 00:23:14 +00:00
var res GetAppManifestReturns
err = h.Execute(ctxt, cdp.CommandPageGetAppManifest, nil, &res)
if err != nil {
2017-12-18 00:23:14 +00:00
return "", nil, "", err
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
return res.URL, res.Errors, res.Data, nil
2017-01-24 15:09:23 +00:00
}
2017-11-02 04:49:15 +00:00
// GetFrameTreeParams returns present frame tree structure.
type GetFrameTreeParams struct{}
// GetFrameTree returns present frame tree structure.
func GetFrameTree() *GetFrameTreeParams {
return &GetFrameTreeParams{}
}
// GetFrameTreeReturns return values.
type GetFrameTreeReturns struct {
FrameTree *FrameTree `json:"frameTree,omitempty"` // Present frame tree structure.
}
// Do executes Page.getFrameTree against the provided context and
// target handler.
//
// returns:
// frameTree - Present frame tree structure.
func (p *GetFrameTreeParams) Do(ctxt context.Context, h cdp.Handler) (frameTree *FrameTree, err error) {
// execute
var res GetFrameTreeReturns
err = h.Execute(ctxt, cdp.CommandPageGetFrameTree, nil, &res)
if err != nil {
return nil, err
}
return res.FrameTree, nil
}
2017-12-18 00:23:14 +00:00
// 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
}
// 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
}
2017-01-24 15:09:23 +00:00
// GetResourceContentParams returns content of the given resource.
type GetResourceContentParams struct {
2017-01-26 07:28:34 +00:00
FrameID cdp.FrameID `json:"frameId"` // Frame id to get resource for.
URL string `json:"url"` // URL of the resource to get content for.
2017-01-24 15:09:23 +00:00
}
// GetResourceContent returns content of the given resource.
//
// parameters:
2017-01-26 07:28:34 +00:00
// frameID - Frame id to get resource for.
2017-01-24 15:09:23 +00:00
// url - URL of the resource to get content for.
2017-01-26 07:28:34 +00:00
func GetResourceContent(frameID cdp.FrameID, url string) *GetResourceContentParams {
2017-01-24 15:09:23 +00:00
return &GetResourceContentParams{
2017-01-26 07:28:34 +00:00
FrameID: frameID,
2017-01-24 15:09:23 +00:00
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.
2017-01-24 15:09:23 +00:00
//
// 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)
2017-01-24 15:09:23 +00:00
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
2017-01-24 15:09:23 +00:00
}
} else {
dec = []byte(res.Content)
2017-01-24 15:09:23 +00:00
}
return dec, nil
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// GetResourceTreeParams returns present frame / resource tree structure.
type GetResourceTreeParams struct{}
2017-01-24 15:09:23 +00:00
2017-12-18 00:23:14 +00:00
// GetResourceTree returns present frame / resource tree structure.
func GetResourceTree() *GetResourceTreeParams {
return &GetResourceTreeParams{}
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// GetResourceTreeReturns return values.
type GetResourceTreeReturns struct {
FrameTree *FrameResourceTree `json:"frameTree,omitempty"` // Present frame / resource tree structure.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.getResourceTree against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-12-18 00:23:14 +00:00
// frameTree - Present frame / resource tree structure.
func (p *GetResourceTreeParams) Do(ctxt context.Context, h cdp.Handler) (frameTree *FrameResourceTree, err error) {
// execute
2017-12-18 00:23:14 +00:00
var res GetResourceTreeReturns
err = h.Execute(ctxt, cdp.CommandPageGetResourceTree, nil, &res)
2017-01-24 15:09:23 +00:00
if err != nil {
return nil, err
}
2017-12-18 00:23:14 +00:00
return res.FrameTree, nil
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// 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.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// HandleJavaScriptDialog accepts or dismisses a JavaScript initiated dialog
// (alert, confirm, prompt, or onbeforeunload).
2017-01-24 15:09:23 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
// accept - Whether to accept or dismiss the dialog.
func HandleJavaScriptDialog(accept bool) *HandleJavaScriptDialogParams {
return &HandleJavaScriptDialogParams{
Accept: accept,
2017-01-24 15:09:23 +00:00
}
}
2017-12-18 00:23:14 +00:00
// 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.
2017-12-18 00:23:14 +00:00
func (p *HandleJavaScriptDialogParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageHandleJavaScriptDialog, p, nil)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// 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.
}
2017-01-24 15:09:23 +00:00
2017-12-18 00:23:14 +00:00
// Navigate navigates current page to the given URL.
//
// parameters:
2017-12-18 00:23:14 +00:00
// url - URL to navigate the page to.
func Navigate(url string) *NavigateParams {
return &NavigateParams{
URL: url,
}
}
2017-12-18 00:23:14 +00:00
// WithReferrer referrer URL.
func (p NavigateParams) WithReferrer(referrer string) *NavigateParams {
p.Referrer = referrer
2017-07-13 00:28:14 +00:00
return &p
}
2017-12-18 00:23:14 +00:00
// WithTransitionType intended transition type.
func (p NavigateParams) WithTransitionType(transitionType TransitionType) *NavigateParams {
p.TransitionType = transitionType
2017-03-13 02:29:26 +00:00
return &p
}
2017-12-18 00:23:14 +00:00
// NavigateReturns return values.
type NavigateReturns struct {
FrameID cdp.FrameID `json:"frameId,omitempty"` // Frame id that has navigated (or failed to navigate)
LoaderID cdp.LoaderID `json:"loaderId,omitempty"` // Loader identifier.
ErrorText string `json:"errorText,omitempty"` // User friendly error message, present if and only if navigation has failed.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.navigate against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-12-18 00:23:14 +00:00
// frameID - Frame id that has navigated (or failed to navigate)
// loaderID - Loader identifier.
// errorText - User friendly error message, present if and only if navigation has failed.
func (p *NavigateParams) Do(ctxt context.Context, h cdp.Handler) (frameID cdp.FrameID, loaderID cdp.LoaderID, errorText string, err error) {
// execute
2017-12-18 00:23:14 +00:00
var res NavigateReturns
err = h.Execute(ctxt, cdp.CommandPageNavigate, p, &res)
if err != nil {
2017-12-18 00:23:14 +00:00
return "", "", "", err
}
2017-12-18 00:23:14 +00:00
return res.FrameID, res.LoaderID, res.ErrorText, 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,
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
}
// 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)
2017-01-24 15:09:23 +00:00
}
2017-05-15 07:59:53 +00:00
// PrintToPDFParams print page as PDF.
type PrintToPDFParams struct {
2017-07-22 00:37:02 +00:00
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.
IgnoreInvalidPageRanges bool `json:"ignoreInvalidPageRanges,omitempty"` // Whether to silently ignore invalid but successfully parsed page ranges, such as '3-2'. Defaults to false.
2017-12-18 00:23:14 +00:00
HeaderTemplate string `json:"headerTemplate,omitempty"` // HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: - date - formatted print date - title - document title - url - document location - pageNumber - current page number - totalPages - total pages in the document For example, <span class=title></span> would generate span containing the title.
FooterTemplate string `json:"footerTemplate,omitempty"` // HTML template for the print footer. Should use the same format as the headerTemplate.
2017-05-15 07:59:53 +00:00
}
// PrintToPDF print page as PDF.
//
// parameters:
func PrintToPDF() *PrintToPDFParams {
return &PrintToPDFParams{}
}
2017-05-15 07:59:53 +00:00
// 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
}
2017-07-22 00:37:02 +00:00
// WithIgnoreInvalidPageRanges whether to silently ignore invalid but
// successfully parsed page ranges, such as '3-2'. Defaults to false.
func (p PrintToPDFParams) WithIgnoreInvalidPageRanges(ignoreInvalidPageRanges bool) *PrintToPDFParams {
p.IgnoreInvalidPageRanges = ignoreInvalidPageRanges
return &p
}
2017-12-18 00:23:14 +00:00
// WithHeaderTemplate HTML template for the print header. Should be valid
// HTML markup with following classes used to inject printing values into them:
// - date - formatted print date - title - document title - url - document
// location - pageNumber - current page number - totalPages - total pages in the
// document For example, <span class=title></span> would generate span
// containing the title.
func (p PrintToPDFParams) WithHeaderTemplate(headerTemplate string) *PrintToPDFParams {
p.HeaderTemplate = headerTemplate
return &p
}
// WithFooterTemplate HTML template for the print footer. Should use the same
// format as the headerTemplate.
func (p PrintToPDFParams) WithFooterTemplate(footerTemplate string) *PrintToPDFParams {
p.FooterTemplate = footerTemplate
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
2017-05-15 07:59:53 +00:00
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
}
2017-12-18 00:23:14 +00:00
// 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. Argument will be ignored if reloading dataURL origin.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Reload reloads given page optionally ignoring the cache.
2017-01-24 15:09:23 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
func Reload() *ReloadParams {
return &ReloadParams{}
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// WithIgnoreCache if true, browser cache is ignored (as if the user pressed
// Shift+refresh).
func (p ReloadParams) WithIgnoreCache(ignoreCache bool) *ReloadParams {
p.IgnoreCache = ignoreCache
2017-01-24 15:09:23 +00:00
return &p
}
2017-12-18 00:23:14 +00:00
// WithScriptToEvaluateOnLoad if set, the script will be injected into all
// frames of the inspected page after reload. Argument will be ignored if
// reloading dataURL origin.
func (p ReloadParams) WithScriptToEvaluateOnLoad(scriptToEvaluateOnLoad string) *ReloadParams {
p.ScriptToEvaluateOnLoad = scriptToEvaluateOnLoad
2017-01-24 15:09:23 +00:00
return &p
}
2017-12-18 00:23:14 +00:00
// 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)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// RemoveScriptToEvaluateOnNewDocumentParams removes given script from the
// list.
type RemoveScriptToEvaluateOnNewDocumentParams struct {
Identifier ScriptIdentifier `json:"identifier"`
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// RemoveScriptToEvaluateOnNewDocument removes given script from the list.
//
// parameters:
// identifier
func RemoveScriptToEvaluateOnNewDocument(identifier ScriptIdentifier) *RemoveScriptToEvaluateOnNewDocumentParams {
return &RemoveScriptToEvaluateOnNewDocumentParams{
Identifier: identifier,
}
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.removeScriptToEvaluateOnNewDocument against the provided context and
// target handler.
2017-12-18 00:23:14 +00:00
func (p *RemoveScriptToEvaluateOnNewDocumentParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageRemoveScriptToEvaluateOnNewDocument, p, nil)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// RequestAppBannerParams [no description].
type RequestAppBannerParams struct{}
2017-01-24 15:09:23 +00:00
2017-12-18 00:23:14 +00:00
// RequestAppBanner [no description].
func RequestAppBanner() *RequestAppBannerParams {
return &RequestAppBannerParams{}
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.requestAppBanner against the provided context and
// target handler.
2017-12-18 00:23:14 +00:00
func (p *RequestAppBannerParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageRequestAppBanner, nil, nil)
2017-01-24 15:09:23 +00:00
}
// 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:
2017-01-26 07:28:34 +00:00
// sessionID - Frame number.
func ScreencastFrameAck(sessionID int64) *ScreencastFrameAckParams {
2017-01-24 15:09:23 +00:00
return &ScreencastFrameAckParams{
2017-01-26 07:28:34 +00:00
SessionID: sessionID,
2017-01-24 15:09:23 +00:00
}
}
// 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)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// 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.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SearchInResource searches for given string in resource content.
2017-01-24 15:09:23 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
// 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,
2017-01-24 15:09:23 +00:00
}
}
2017-12-18 00:23:14 +00:00
// WithCaseSensitive if true, search is case sensitive.
func (p SearchInResourceParams) WithCaseSensitive(caseSensitive bool) *SearchInResourceParams {
p.CaseSensitive = caseSensitive
2017-01-24 15:09:23 +00:00
return &p
}
2017-12-18 00:23:14 +00:00
// WithIsRegex if true, treats string parameter as regex.
func (p SearchInResourceParams) WithIsRegex(isRegex bool) *SearchInResourceParams {
p.IsRegex = isRegex
return &p
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SearchInResourceReturns return values.
type SearchInResourceReturns struct {
Result []*debugger.SearchMatch `json:"result,omitempty"` // List of search matches.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.searchInResource against the provided context and
// target handler.
2017-01-24 15:09:23 +00:00
//
// returns:
2017-12-18 00:23:14 +00:00
// result - List of search matches.
func (p *SearchInResourceParams) Do(ctxt context.Context, h cdp.Handler) (result []*debugger.SearchMatch, err error) {
2017-01-24 15:09:23 +00:00
// execute
2017-12-18 00:23:14 +00:00
var res SearchInResourceReturns
err = h.Execute(ctxt, cdp.CommandPageSearchInResource, p, &res)
if err != nil {
2017-12-18 00:23:14 +00:00
return nil, err
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
return res.Result, nil
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetAdBlockingEnabledParams enable Chrome's experimental ad filter on all
// sites.
type SetAdBlockingEnabledParams struct {
Enabled bool `json:"enabled"` // Whether to block ads.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetAdBlockingEnabled enable Chrome's experimental ad filter on all sites.
2017-01-24 15:09:23 +00:00
//
2017-12-18 00:23:14 +00:00
// parameters:
// enabled - Whether to block ads.
func SetAdBlockingEnabled(enabled bool) *SetAdBlockingEnabledParams {
return &SetAdBlockingEnabledParams{
Enabled: enabled,
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
}
2017-01-24 15:09:23 +00:00
2017-12-18 00:23:14 +00:00
// Do executes Page.setAdBlockingEnabled against the provided context and
// target handler.
func (p *SetAdBlockingEnabledParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageSetAdBlockingEnabled, p, nil)
2017-01-24 15:09:23 +00:00
}
2017-05-15 07:59:53 +00:00
2017-12-18 00:23:14 +00:00
// 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.
2017-05-15 07:59:53 +00:00
}
2017-12-18 00:23:14 +00:00
// SetAutoAttachToCreatedPages controls whether browser will open a new
// inspector window for connected pages.
2017-05-15 07:59:53 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
// 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,
2017-05-15 07:59:53 +00:00
}
}
2017-12-18 00:23:14 +00:00
// 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)
2017-05-15 07:59:53 +00:00
}
2017-12-18 00:23:14 +00:00
// 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.
2017-06-25 01:38:47 +00:00
}
2017-12-18 00:23:14 +00:00
// SetDocumentContent sets given markup as the document's HTML.
2017-06-25 01:38:47 +00:00
//
2017-12-18 00:23:14 +00:00
// 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,
2017-06-25 01:38:47 +00:00
}
2017-07-31 02:26:12 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Page.setDocumentContent against the provided context and
2017-07-31 02:26:12 +00:00
// target handler.
2017-12-18 00:23:14 +00:00
func (p *SetDocumentContentParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageSetDocumentContent, p, nil)
2017-07-31 02:26:12 +00:00
}
2017-08-29 02:48:17 +00:00
// SetDownloadBehaviorParams set the behavior when downloading a file.
type SetDownloadBehaviorParams struct {
Behavior SetDownloadBehaviorBehavior `json:"behavior"` // Whether to allow all or deny all download requests, or use default Chrome behavior if available (otherwise deny).
DownloadPath string `json:"downloadPath,omitempty"` // The default path to save downloaded files to. This is required if behavior is set to 'allow'
}
// SetDownloadBehavior set the behavior when downloading a file.
//
// parameters:
// behavior - Whether to allow all or deny all download requests, or use default Chrome behavior if available (otherwise deny).
func SetDownloadBehavior(behavior SetDownloadBehaviorBehavior) *SetDownloadBehaviorParams {
return &SetDownloadBehaviorParams{
Behavior: behavior,
}
}
// WithDownloadPath the default path to save downloaded files to. This is
// required if behavior is set to 'allow'.
func (p SetDownloadBehaviorParams) WithDownloadPath(downloadPath string) *SetDownloadBehaviorParams {
p.DownloadPath = downloadPath
return &p
}
// Do executes Page.setDownloadBehavior against the provided context and
// target handler.
func (p *SetDownloadBehaviorParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageSetDownloadBehavior, p, nil)
}
2017-12-18 00:23:14 +00:00
// SetLifecycleEventsEnabledParams controls whether page will emit lifecycle
// events.
type SetLifecycleEventsEnabledParams struct {
Enabled bool `json:"enabled"` // If true, starts emitting lifecycle events.
}
// SetLifecycleEventsEnabled controls whether page will emit lifecycle
// events.
//
// parameters:
// enabled - If true, starts emitting lifecycle events.
func SetLifecycleEventsEnabled(enabled bool) *SetLifecycleEventsEnabledParams {
return &SetLifecycleEventsEnabledParams{
Enabled: enabled,
}
}
// Do executes Page.setLifecycleEventsEnabled against the provided context and
// target handler.
func (p *SetLifecycleEventsEnabledParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandPageSetLifecycleEventsEnabled, p, 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)
}
// 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)
}
// 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)
}