chromedp/cdp/headlessexperimental/headlessexperimental.go

126 lines
5.2 KiB
Go
Raw Normal View History

2017-10-15 05:47:06 +00:00
// Package headlessexperimental provides the Chrome Debugging Protocol
// commands, types, and events for the HeadlessExperimental domain.
//
// This domain provides experimental commands only supported in headless
// mode.
//
// Generated by the chromedp-gen command.
package headlessexperimental
// Code generated by chromedp-gen. DO NOT EDIT.
import (
"context"
"encoding/base64"
cdp "github.com/knq/chromedp/cdp"
"github.com/knq/chromedp/cdp/runtime"
)
// BeginFrameParams sends a BeginFrame to the target and returns when the
// frame was completed. Optionally captures a screenshot from the resulting
// frame. Requires that the target was created with enabled BeginFrameControl.
type BeginFrameParams struct {
FrameTime *runtime.Timestamp `json:"frameTime,omitempty"` // Timestamp of this BeginFrame (milliseconds since epoch). If not set, the current time will be used.
Deadline *runtime.Timestamp `json:"deadline,omitempty"` // Deadline of this BeginFrame (milliseconds since epoch). If not set, the deadline will be calculated from the frameTime and interval.
Interval float64 `json:"interval,omitempty"` // The interval between BeginFrames that is reported to the compositor, in milliseconds. Defaults to a 60 frames/second interval, i.e. about 16.666 milliseconds.
Screenshot *ScreenshotParams `json:"screenshot,omitempty"` // If set, a screenshot of the frame will be captured and returned in the response. Otherwise, no screenshot will be captured.
}
// BeginFrame sends a BeginFrame to the target and returns when the frame was
// completed. Optionally captures a screenshot from the resulting frame.
// Requires that the target was created with enabled BeginFrameControl.
//
// parameters:
func BeginFrame() *BeginFrameParams {
return &BeginFrameParams{}
}
// WithFrameTime timestamp of this BeginFrame (milliseconds since epoch). If
// not set, the current time will be used.
func (p BeginFrameParams) WithFrameTime(frameTime *runtime.Timestamp) *BeginFrameParams {
p.FrameTime = frameTime
return &p
}
// WithDeadline deadline of this BeginFrame (milliseconds since epoch). If
// not set, the deadline will be calculated from the frameTime and interval.
func (p BeginFrameParams) WithDeadline(deadline *runtime.Timestamp) *BeginFrameParams {
p.Deadline = deadline
return &p
}
// WithInterval the interval between BeginFrames that is reported to the
// compositor, in milliseconds. Defaults to a 60 frames/second interval, i.e.
// about 16.666 milliseconds.
func (p BeginFrameParams) WithInterval(interval float64) *BeginFrameParams {
p.Interval = interval
return &p
}
// WithScreenshot if set, a screenshot of the frame will be captured and
// returned in the response. Otherwise, no screenshot will be captured.
func (p BeginFrameParams) WithScreenshot(screenshot *ScreenshotParams) *BeginFrameParams {
p.Screenshot = screenshot
return &p
}
// BeginFrameReturns return values.
type BeginFrameReturns struct {
2017-10-24 02:06:01 +00:00
HasDamage bool `json:"hasDamage,omitempty"` // Whether the BeginFrame resulted in damage and, thus, a new frame was committed to the display.
MainFrameContentUpdated bool `json:"mainFrameContentUpdated,omitempty"` // Whether the main frame submitted a new display frame in response to this BeginFrame.
ScreenshotData string `json:"screenshotData,omitempty"` // Base64-encoded image data of the screenshot, if one was requested and successfully taken.
2017-10-15 05:47:06 +00:00
}
// Do executes HeadlessExperimental.beginFrame against the provided context and
// target handler.
//
// returns:
// hasDamage - Whether the BeginFrame resulted in damage and, thus, a new frame was committed to the display.
2017-10-24 02:06:01 +00:00
// mainFrameContentUpdated - Whether the main frame submitted a new display frame in response to this BeginFrame.
2017-10-15 05:47:06 +00:00
// screenshotData - Base64-encoded image data of the screenshot, if one was requested and successfully taken.
2017-10-24 02:06:01 +00:00
func (p *BeginFrameParams) Do(ctxt context.Context, h cdp.Handler) (hasDamage bool, mainFrameContentUpdated bool, screenshotData []byte, err error) {
2017-10-15 05:47:06 +00:00
// execute
var res BeginFrameReturns
err = h.Execute(ctxt, cdp.CommandHeadlessExperimentalBeginFrame, p, &res)
if err != nil {
2017-10-24 02:06:01 +00:00
return false, false, nil, err
2017-10-15 05:47:06 +00:00
}
// decode
var dec []byte
dec, err = base64.StdEncoding.DecodeString(res.ScreenshotData)
if err != nil {
2017-10-24 02:06:01 +00:00
return false, false, nil, err
2017-10-15 05:47:06 +00:00
}
2017-10-24 02:06:01 +00:00
return res.HasDamage, res.MainFrameContentUpdated, dec, nil
2017-10-15 05:47:06 +00:00
}
2017-12-18 00:23:14 +00:00
// DisableParams disables headless events for the target.
type DisableParams struct{}
// Disable disables headless events for the target.
func Disable() *DisableParams {
return &DisableParams{}
}
// Do executes HeadlessExperimental.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.CommandHeadlessExperimentalDisable, nil, nil)
}
// EnableParams enables headless events for the target.
type EnableParams struct{}
// Enable enables headless events for the target.
func Enable() *EnableParams {
return &EnableParams{}
}
// Do executes HeadlessExperimental.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.CommandHeadlessExperimentalEnable, nil, nil)
}