chromedp/cdp/page/page.go

1536 lines
35 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 Chrome 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"
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"
"github.com/mailru/easyjson"
)
// EnableParams enables page domain notifications.
type EnableParams struct{}
// Enable enables page domain notifications.
func Enable() *EnableParams {
return &EnableParams{}
}
// Do executes Page.enable.
2017-01-26 07:28:34 +00:00
func (p *EnableParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageEnable, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// DisableParams disables page domain notifications.
type DisableParams struct{}
// Disable disables page domain notifications.
func Disable() *DisableParams {
return &DisableParams{}
}
// Do executes Page.disable.
2017-01-26 07:28:34 +00:00
func (p *DisableParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageDisable, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
// AddScriptToEvaluateOnLoadParams [no description].
2017-01-24 15:09:23 +00:00
type AddScriptToEvaluateOnLoadParams struct {
ScriptSource string `json:"scriptSource"`
}
2017-01-26 07:28:34 +00:00
// AddScriptToEvaluateOnLoad [no description].
//
2017-01-24 15:09:23 +00:00
// 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.
//
// returns:
// identifier - Identifier of the added script.
2017-01-26 07:28:34 +00:00
func (p *AddScriptToEvaluateOnLoadParams) Do(ctxt context.Context, h cdp.FrameHandler) (identifier ScriptIdentifier, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return "", err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageAddScriptToEvaluateOnLoad, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return "", cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r AddScriptToEvaluateOnLoadReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return "", cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.Identifier, nil
case error:
return "", v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return "", cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return "", cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
// RemoveScriptToEvaluateOnLoadParams [no description].
2017-01-24 15:09:23 +00:00
type RemoveScriptToEvaluateOnLoadParams struct {
Identifier ScriptIdentifier `json:"identifier"`
}
2017-01-26 07:28:34 +00:00
// RemoveScriptToEvaluateOnLoad [no description].
//
2017-01-24 15:09:23 +00:00
// parameters:
// identifier
func RemoveScriptToEvaluateOnLoad(identifier ScriptIdentifier) *RemoveScriptToEvaluateOnLoadParams {
return &RemoveScriptToEvaluateOnLoadParams{
Identifier: identifier,
}
}
// Do executes Page.removeScriptToEvaluateOnLoad.
2017-01-26 07:28:34 +00:00
func (p *RemoveScriptToEvaluateOnLoadParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageRemoveScriptToEvaluateOnLoad, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +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.
}
// 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.
2017-01-26 07:28:34 +00:00
func (p *SetAutoAttachToCreatedPagesParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageSetAutoAttachToCreatedPages, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +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.
}
// 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.
2017-01-26 07:28:34 +00:00
func (p *ReloadParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageReload, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// NavigateParams navigates current page to the given URL.
type NavigateParams struct {
URL string `json:"url"` // URL to navigate the page to.
}
// 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,
}
}
// NavigateReturns return values.
type NavigateReturns struct {
2017-01-26 07:28:34 +00:00
FrameID cdp.FrameID `json:"frameId,omitempty"` // Frame id that will be navigated.
2017-01-24 15:09:23 +00:00
}
// Do executes Page.navigate.
//
// returns:
2017-01-26 07:28:34 +00:00
// frameID - Frame id that will be navigated.
func (p *NavigateParams) Do(ctxt context.Context, h cdp.FrameHandler) (frameID cdp.FrameID, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return "", err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageNavigate, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return "", cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r NavigateReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return "", cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.FrameID, nil
case error:
return "", v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return "", cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return "", cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// 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.
2017-01-26 07:28:34 +00:00
func (p *StopLoadingParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageStopLoading, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// 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.
//
// returns:
// currentIndex - Index of the current navigation history entry.
// entries - Array of navigation history entries.
2017-01-26 07:28:34 +00:00
func (p *GetNavigationHistoryParams) Do(ctxt context.Context, h cdp.FrameHandler) (currentIndex int64, entries []*NavigationEntry, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageGetNavigationHistory, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return 0, nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetNavigationHistoryReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return 0, nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.CurrentIndex, r.Entries, nil
case error:
return 0, nil, v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return 0, nil, cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return 0, nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// 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:
2017-01-26 07:28:34 +00:00
// entryID - Unique id of the entry to navigate to.
func NavigateToHistoryEntry(entryID int64) *NavigateToHistoryEntryParams {
2017-01-24 15:09:23 +00:00
return &NavigateToHistoryEntryParams{
2017-01-26 07:28:34 +00:00
EntryID: entryID,
2017-01-24 15:09:23 +00:00
}
}
// Do executes Page.navigateToHistoryEntry.
2017-01-26 07:28:34 +00:00
func (p *NavigateToHistoryEntryParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageNavigateToHistoryEntry, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// 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.
//
// returns:
// frameTree - Present frame / resource tree structure.
2017-01-26 07:28:34 +00:00
func (p *GetResourceTreeParams) Do(ctxt context.Context, h cdp.FrameHandler) (frameTree *FrameResourceTree, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageGetResourceTree, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetResourceTreeReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.FrameTree, nil
case error:
return nil, v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
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.
//
// returns:
// content - Resource content.
2017-01-26 07:28:34 +00:00
func (p *GetResourceContentParams) Do(ctxt context.Context, h cdp.FrameHandler) (content []byte, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageGetResourceContent, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetResourceContentReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
// decode
var dec []byte
if r.Base64encoded {
dec, err = base64.StdEncoding.DecodeString(r.Content)
if err != nil {
return nil, err
}
} else {
dec = []byte(r.Content)
}
return dec, nil
case error:
return nil, v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SearchInResourceParams searches for given string in resource content.
type SearchInResourceParams struct {
2017-01-26 07:28:34 +00:00
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
}
// SearchInResource searches for given string in resource content.
//
// parameters:
2017-01-26 07:28:34 +00:00
// frameID - Frame id for resource to search in.
2017-01-24 15:09:23 +00:00
// url - URL of the resource to search in.
// query - String to search for.
2017-01-26 07:28:34 +00:00
func SearchInResource(frameID cdp.FrameID, url string, query string) *SearchInResourceParams {
2017-01-24 15:09:23 +00:00
return &SearchInResourceParams{
2017-01-26 07:28:34 +00:00
FrameID: frameID,
2017-01-24 15:09:23 +00:00
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.
//
// returns:
// result - List of search matches.
2017-01-26 07:28:34 +00:00
func (p *SearchInResourceParams) Do(ctxt context.Context, h cdp.FrameHandler) (result []*debugger.SearchMatch, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageSearchInResource, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r SearchInResourceReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.Result, nil
case error:
return nil, v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SetDocumentContentParams sets given markup as the document's HTML.
type SetDocumentContentParams struct {
2017-01-26 07:28:34 +00:00
FrameID cdp.FrameID `json:"frameId"` // Frame id to set HTML for.
HTML string `json:"html"` // HTML content to set.
2017-01-24 15:09:23 +00:00
}
// SetDocumentContent sets given markup as the document's HTML.
//
// parameters:
2017-01-26 07:28:34 +00:00
// frameID - Frame id to set HTML for.
2017-01-24 15:09:23 +00:00
// html - HTML content to set.
2017-01-26 07:28:34 +00:00
func SetDocumentContent(frameID cdp.FrameID, html string) *SetDocumentContentParams {
2017-01-24 15:09:23 +00:00
return &SetDocumentContentParams{
2017-01-26 07:28:34 +00:00
FrameID: frameID,
2017-01-24 15:09:23 +00:00
HTML: html,
}
}
// Do executes Page.setDocumentContent.
2017-01-26 07:28:34 +00:00
func (p *SetDocumentContentParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageSetDocumentContent, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +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).
}
2017-01-24 15:09:23 +00:00
// CaptureScreenshot capture page screenshot.
//
// parameters:
2017-01-24 15:09:23 +00:00
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
}
2017-01-24 15:09:23 +00:00
// CaptureScreenshotReturns return values.
type CaptureScreenshotReturns struct {
Data string `json:"data,omitempty"` // Base64-encoded image data.
2017-01-24 15:09:23 +00:00
}
// Do executes Page.captureScreenshot.
//
// returns:
// data - Base64-encoded image data.
2017-01-26 07:28:34 +00:00
func (p *CaptureScreenshotParams) Do(ctxt context.Context, h cdp.FrameHandler) (data []byte, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return nil, err
}
2017-01-24 15:09:23 +00:00
// execute
ch := h.Execute(ctxt, cdp.CommandPageCaptureScreenshot, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r CaptureScreenshotReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
// decode
var dec []byte
dec, err = base64.StdEncoding.DecodeString(r.Data)
if err != nil {
return nil, err
}
return dec, nil
case error:
return nil, v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// 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.
2017-01-26 07:28:34 +00:00
func (p *StartScreencastParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageStartScreencast, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// 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.
2017-01-26 07:28:34 +00:00
func (p *StopScreencastParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageStopScreencast, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
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.
2017-01-26 07:28:34 +00:00
func (p *ScreencastFrameAckParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageScreencastFrameAck, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +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.
}
// 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.
2017-01-26 07:28:34 +00:00
func (p *HandleJavaScriptDialogParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageHandleJavaScriptDialog, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// SetColorPickerEnabledParams shows / hides color picker.
type SetColorPickerEnabledParams struct {
Enabled bool `json:"enabled"` // Shows / hides color picker
}
// SetColorPickerEnabled shows / hides color picker.
//
// parameters:
// enabled - Shows / hides color picker
func SetColorPickerEnabled(enabled bool) *SetColorPickerEnabledParams {
return &SetColorPickerEnabledParams{
Enabled: enabled,
}
}
// Do executes Page.setColorPickerEnabled.
2017-01-26 07:28:34 +00:00
func (p *SetColorPickerEnabledParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageSetColorPickerEnabled, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// ConfigureOverlayParams configures overlay.
type ConfigureOverlayParams struct {
Suspended bool `json:"suspended,omitempty"` // Whether overlay should be suspended and not consume any resources.
Message string `json:"message,omitempty"` // Overlay message to display.
}
// ConfigureOverlay configures overlay.
//
// parameters:
func ConfigureOverlay() *ConfigureOverlayParams {
return &ConfigureOverlayParams{}
}
// WithSuspended whether overlay should be suspended and not consume any
// resources.
func (p ConfigureOverlayParams) WithSuspended(suspended bool) *ConfigureOverlayParams {
p.Suspended = suspended
return &p
}
// WithMessage overlay message to display.
func (p ConfigureOverlayParams) WithMessage(message string) *ConfigureOverlayParams {
p.Message = message
return &p
}
// Do executes Page.configureOverlay.
2017-01-26 07:28:34 +00:00
func (p *ConfigureOverlayParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageConfigureOverlay, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
// GetAppManifestParams [no description].
2017-01-24 15:09:23 +00:00
type GetAppManifestParams struct{}
2017-01-26 07:28:34 +00:00
// GetAppManifest [no description].
2017-01-24 15:09:23 +00:00
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.
//
// returns:
// url - Manifest location.
// errors
// data - Manifest content.
2017-01-26 07:28:34 +00:00
func (p *GetAppManifestParams) Do(ctxt context.Context, h cdp.FrameHandler) (url string, errors []*AppManifestError, data string, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageGetAppManifest, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return "", nil, "", cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetAppManifestReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return "", nil, "", cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.URL, r.Errors, r.Data, nil
case error:
return "", nil, "", v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return "", nil, "", cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return "", nil, "", cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
// RequestAppBannerParams [no description].
2017-01-24 15:09:23 +00:00
type RequestAppBannerParams struct{}
2017-01-26 07:28:34 +00:00
// RequestAppBanner [no description].
2017-01-24 15:09:23 +00:00
func RequestAppBanner() *RequestAppBannerParams {
return &RequestAppBannerParams{}
}
// Do executes Page.requestAppBanner.
2017-01-26 07:28:34 +00:00
func (p *RequestAppBannerParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageRequestAppBanner, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// 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.
2017-01-26 07:28:34 +00:00
func (p *SetControlNavigationsParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageSetControlNavigations, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// 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
2017-01-26 07:28:34 +00:00
// navigationID
func ProcessNavigation(response NavigationResponse, navigationID int64) *ProcessNavigationParams {
2017-01-24 15:09:23 +00:00
return &ProcessNavigationParams{
Response: response,
2017-01-26 07:28:34 +00:00
NavigationID: navigationID,
2017-01-24 15:09:23 +00:00
}
}
// Do executes Page.processNavigation.
2017-01-26 07:28:34 +00:00
func (p *ProcessNavigationParams) Do(ctxt context.Context, h cdp.FrameHandler) (err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// marshal
buf, err := easyjson.Marshal(p)
if err != nil {
return err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageProcessNavigation, easyjson.RawMessage(buf))
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
return nil
case error:
return v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return cdp.ErrUnknownResult
2017-01-24 15:09:23 +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.
}
// Do executes Page.getLayoutMetrics.
//
// returns:
// layoutViewport - Metrics relating to the layout viewport.
// visualViewport - Metrics relating to the visual viewport.
2017-01-26 07:28:34 +00:00
func (p *GetLayoutMetricsParams) Do(ctxt context.Context, h cdp.FrameHandler) (layoutViewport *LayoutViewport, visualViewport *VisualViewport, err error) {
2017-01-24 15:09:23 +00:00
if ctxt == nil {
ctxt = context.Background()
}
// execute
2017-01-26 07:28:34 +00:00
ch := h.Execute(ctxt, cdp.CommandPageGetLayoutMetrics, cdp.Empty)
2017-01-24 15:09:23 +00:00
// read response
select {
case res := <-ch:
if res == nil {
2017-01-26 07:28:34 +00:00
return nil, nil, cdp.ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res.(type) {
case easyjson.RawMessage:
// unmarshal
var r GetLayoutMetricsReturns
err = easyjson.Unmarshal(v, &r)
if err != nil {
2017-01-26 07:28:34 +00:00
return nil, nil, cdp.ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r.LayoutViewport, r.VisualViewport, nil
case error:
return nil, nil, v
}
case <-ctxt.Done():
2017-01-26 07:28:34 +00:00
return nil, nil, cdp.ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return nil, nil, cdp.ErrUnknownResult
2017-01-24 15:09:23 +00:00
}