chromedp/cdp/emulation/emulation.go

484 lines
20 KiB
Go
Raw Normal View History

2017-01-24 15:09:23 +00:00
// Package emulation provides the Chrome Debugging Protocol
// commands, types, and events for the Emulation domain.
2017-01-24 15:09:23 +00:00
//
// This domain emulates different environments for the page.
//
// Generated by the chromedp-gen command.
package emulation
// Code generated by chromedp-gen. DO NOT EDIT.
2017-01-24 15:09:23 +00:00
import (
"context"
2017-01-26 07:28:34 +00:00
cdp "github.com/knq/chromedp/cdp"
2017-10-15 05:47:06 +00:00
"github.com/knq/chromedp/cdp/page"
2017-11-22 05:01:27 +00:00
"github.com/knq/chromedp/cdp/runtime"
2017-01-24 15:09:23 +00:00
)
2017-12-18 00:23:14 +00:00
// CanEmulateParams tells whether emulation is supported.
type CanEmulateParams struct{}
// CanEmulate tells whether emulation is supported.
func CanEmulate() *CanEmulateParams {
return &CanEmulateParams{}
}
// CanEmulateReturns return values.
type CanEmulateReturns struct {
Result bool `json:"result,omitempty"` // True if emulation is supported.
}
// Do executes Emulation.canEmulate against the provided context and
// target handler.
//
// returns:
// result - True if emulation is supported.
func (p *CanEmulateParams) Do(ctxt context.Context, h cdp.Handler) (result bool, err error) {
// execute
var res CanEmulateReturns
err = h.Execute(ctxt, cdp.CommandEmulationCanEmulate, nil, &res)
if err != nil {
return false, err
}
return res.Result, nil
}
// ClearDeviceMetricsOverrideParams clears the overridden device metrics.
type ClearDeviceMetricsOverrideParams struct{}
// ClearDeviceMetricsOverride clears the overridden device metrics.
func ClearDeviceMetricsOverride() *ClearDeviceMetricsOverrideParams {
return &ClearDeviceMetricsOverrideParams{}
}
// Do executes Emulation.clearDeviceMetricsOverride against the provided context and
// target handler.
func (p *ClearDeviceMetricsOverrideParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationClearDeviceMetricsOverride, nil, nil)
}
// ClearGeolocationOverrideParams clears the overridden Geolocation Position
// and Error.
type ClearGeolocationOverrideParams struct{}
// ClearGeolocationOverride clears the overridden Geolocation Position and
// Error.
func ClearGeolocationOverride() *ClearGeolocationOverrideParams {
return &ClearGeolocationOverrideParams{}
}
// Do executes Emulation.clearGeolocationOverride against the provided context and
// target handler.
func (p *ClearGeolocationOverrideParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationClearGeolocationOverride, nil, nil)
}
// ResetPageScaleFactorParams requests that page scale factor is reset to
// initial values.
type ResetPageScaleFactorParams struct{}
// ResetPageScaleFactor requests that page scale factor is reset to initial
// values.
func ResetPageScaleFactor() *ResetPageScaleFactorParams {
return &ResetPageScaleFactorParams{}
}
// Do executes Emulation.resetPageScaleFactor against the provided context and
// target handler.
func (p *ResetPageScaleFactorParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationResetPageScaleFactor, nil, nil)
}
// SetCPUThrottlingRateParams enables CPU throttling to emulate slow CPUs.
type SetCPUThrottlingRateParams struct {
Rate float64 `json:"rate"` // Throttling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).
}
// SetCPUThrottlingRate enables CPU throttling to emulate slow CPUs.
//
// parameters:
// rate - Throttling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).
func SetCPUThrottlingRate(rate float64) *SetCPUThrottlingRateParams {
return &SetCPUThrottlingRateParams{
Rate: rate,
}
}
// Do executes Emulation.setCPUThrottlingRate against the provided context and
// target handler.
func (p *SetCPUThrottlingRateParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationSetCPUThrottlingRate, p, nil)
}
// SetDefaultBackgroundColorOverrideParams sets or clears an override of the
// default background color of the frame. This override is used if the content
// does not specify one.
type SetDefaultBackgroundColorOverrideParams struct {
Color *cdp.RGBA `json:"color,omitempty"` // RGBA of the default background color. If not specified, any existing override will be cleared.
}
// SetDefaultBackgroundColorOverride sets or clears an override of the
// default background color of the frame. This override is used if the content
// does not specify one.
//
// parameters:
func SetDefaultBackgroundColorOverride() *SetDefaultBackgroundColorOverrideParams {
return &SetDefaultBackgroundColorOverrideParams{}
}
// WithColor rGBA of the default background color. If not specified, any
// existing override will be cleared.
func (p SetDefaultBackgroundColorOverrideParams) WithColor(color *cdp.RGBA) *SetDefaultBackgroundColorOverrideParams {
p.Color = color
return &p
}
// Do executes Emulation.setDefaultBackgroundColorOverride against the provided context and
// target handler.
func (p *SetDefaultBackgroundColorOverrideParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationSetDefaultBackgroundColorOverride, p, nil)
}
2017-01-24 15:09:23 +00:00
// SetDeviceMetricsOverrideParams overrides the values of device screen
// dimensions (window.screen.width, window.screen.height, window.innerWidth,
// window.innerHeight, and "device-width"/"device-height"-related CSS media
// query results).
type SetDeviceMetricsOverrideParams struct {
2017-07-22 00:37:02 +00:00
Width int64 `json:"width"` // Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override.
Height int64 `json:"height"` // Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override.
DeviceScaleFactor float64 `json:"deviceScaleFactor"` // Overriding device scale factor value. 0 disables the override.
Mobile bool `json:"mobile"` // Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more.
2017-09-15 23:52:13 +00:00
Scale float64 `json:"scale,omitempty"` // Scale to apply to resulting view image.
ScreenWidth int64 `json:"screenWidth,omitempty"` // Overriding screen width value in pixels (minimum 0, maximum 10000000).
ScreenHeight int64 `json:"screenHeight,omitempty"` // Overriding screen height value in pixels (minimum 0, maximum 10000000).
PositionX int64 `json:"positionX,omitempty"` // Overriding view X position on screen in pixels (minimum 0, maximum 10000000).
PositionY int64 `json:"positionY,omitempty"` // Overriding view Y position on screen in pixels (minimum 0, maximum 10000000).
2017-07-22 00:37:02 +00:00
DontSetVisibleSize bool `json:"dontSetVisibleSize,omitempty"` // Do not set visible view size, rely upon explicit setVisibleSize call.
ScreenOrientation *ScreenOrientation `json:"screenOrientation,omitempty"` // Screen orientation override.
2017-10-15 05:47:06 +00:00
Viewport *page.Viewport `json:"viewport,omitempty"` // If set, the visible area of the page will be overridden to this viewport. This viewport change is not observed by the page, e.g. viewport-relative elements do not change positions.
2017-01-24 15:09:23 +00:00
}
// SetDeviceMetricsOverride overrides the values of device screen dimensions
// (window.screen.width, window.screen.height, window.innerWidth,
// window.innerHeight, and "device-width"/"device-height"-related CSS media
// query results).
//
// parameters:
// width - Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override.
// height - Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override.
// deviceScaleFactor - Overriding device scale factor value. 0 disables the override.
// mobile - Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more.
2017-07-13 00:28:14 +00:00
func SetDeviceMetricsOverride(width int64, height int64, deviceScaleFactor float64, mobile bool) *SetDeviceMetricsOverrideParams {
2017-01-24 15:09:23 +00:00
return &SetDeviceMetricsOverrideParams{
Width: width,
Height: height,
DeviceScaleFactor: deviceScaleFactor,
Mobile: mobile,
}
}
2017-09-15 23:52:13 +00:00
// WithScale scale to apply to resulting view image.
2017-01-24 15:09:23 +00:00
func (p SetDeviceMetricsOverrideParams) WithScale(scale float64) *SetDeviceMetricsOverrideParams {
p.Scale = scale
return &p
}
// WithScreenWidth overriding screen width value in pixels (minimum 0,
2017-09-15 23:52:13 +00:00
// maximum 10000000).
2017-01-24 15:09:23 +00:00
func (p SetDeviceMetricsOverrideParams) WithScreenWidth(screenWidth int64) *SetDeviceMetricsOverrideParams {
p.ScreenWidth = screenWidth
return &p
}
// WithScreenHeight overriding screen height value in pixels (minimum 0,
2017-09-15 23:52:13 +00:00
// maximum 10000000).
2017-01-24 15:09:23 +00:00
func (p SetDeviceMetricsOverrideParams) WithScreenHeight(screenHeight int64) *SetDeviceMetricsOverrideParams {
p.ScreenHeight = screenHeight
return &p
}
// WithPositionX overriding view X position on screen in pixels (minimum 0,
2017-09-15 23:52:13 +00:00
// maximum 10000000).
2017-01-24 15:09:23 +00:00
func (p SetDeviceMetricsOverrideParams) WithPositionX(positionX int64) *SetDeviceMetricsOverrideParams {
p.PositionX = positionX
return &p
}
// WithPositionY overriding view Y position on screen in pixels (minimum 0,
2017-09-15 23:52:13 +00:00
// maximum 10000000).
2017-01-24 15:09:23 +00:00
func (p SetDeviceMetricsOverrideParams) WithPositionY(positionY int64) *SetDeviceMetricsOverrideParams {
p.PositionY = positionY
return &p
}
2017-07-22 00:37:02 +00:00
// WithDontSetVisibleSize do not set visible view size, rely upon explicit
// setVisibleSize call.
func (p SetDeviceMetricsOverrideParams) WithDontSetVisibleSize(dontSetVisibleSize bool) *SetDeviceMetricsOverrideParams {
p.DontSetVisibleSize = dontSetVisibleSize
return &p
}
2017-01-24 15:09:23 +00:00
// WithScreenOrientation screen orientation override.
func (p SetDeviceMetricsOverrideParams) WithScreenOrientation(screenOrientation *ScreenOrientation) *SetDeviceMetricsOverrideParams {
p.ScreenOrientation = screenOrientation
return &p
}
2017-10-15 05:47:06 +00:00
// WithViewport if set, the visible area of the page will be overridden to
// this viewport. This viewport change is not observed by the page, e.g.
// viewport-relative elements do not change positions.
func (p SetDeviceMetricsOverrideParams) WithViewport(viewport *page.Viewport) *SetDeviceMetricsOverrideParams {
p.Viewport = viewport
return &p
}
// Do executes Emulation.setDeviceMetricsOverride against the provided context and
// target handler.
func (p *SetDeviceMetricsOverrideParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationSetDeviceMetricsOverride, p, nil)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetEmitTouchEventsForMouseParams [no description].
type SetEmitTouchEventsForMouseParams struct {
Enabled bool `json:"enabled"` // Whether touch emulation based on mouse input should be enabled.
Configuration SetEmitTouchEventsForMouseConfiguration `json:"configuration,omitempty"` // Touch/gesture events configuration. Default: current platform.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetEmitTouchEventsForMouse [no description].
2017-01-24 15:09:23 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
// enabled - Whether touch emulation based on mouse input should be enabled.
func SetEmitTouchEventsForMouse(enabled bool) *SetEmitTouchEventsForMouseParams {
return &SetEmitTouchEventsForMouseParams{
Enabled: enabled,
2017-01-24 15:09:23 +00:00
}
}
2017-12-18 00:23:14 +00:00
// WithConfiguration touch/gesture events configuration. Default: current
// platform.
func (p SetEmitTouchEventsForMouseParams) WithConfiguration(configuration SetEmitTouchEventsForMouseConfiguration) *SetEmitTouchEventsForMouseParams {
p.Configuration = configuration
return &p
}
// Do executes Emulation.setEmitTouchEventsForMouse against the provided context and
// target handler.
2017-12-18 00:23:14 +00:00
func (p *SetEmitTouchEventsForMouseParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationSetEmitTouchEventsForMouse, p, nil)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetEmulatedMediaParams emulates the given media for CSS media queries.
type SetEmulatedMediaParams struct {
Media string `json:"media"` // Media type to emulate. Empty string disables the override.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetEmulatedMedia emulates the given media for CSS media queries.
2017-01-24 15:09:23 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
// media - Media type to emulate. Empty string disables the override.
func SetEmulatedMedia(media string) *SetEmulatedMediaParams {
return &SetEmulatedMediaParams{
Media: media,
2017-01-24 15:09:23 +00:00
}
}
2017-12-18 00:23:14 +00:00
// Do executes Emulation.setEmulatedMedia against the provided context and
// target handler.
2017-12-18 00:23:14 +00:00
func (p *SetEmulatedMediaParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationSetEmulatedMedia, p, nil)
2017-01-24 15:09:23 +00:00
}
// SetGeolocationOverrideParams overrides the Geolocation Position or Error.
// Omitting any of the parameters emulates position unavailable.
type SetGeolocationOverrideParams struct {
Latitude float64 `json:"latitude,omitempty"` // Mock latitude
Longitude float64 `json:"longitude,omitempty"` // Mock longitude
Accuracy float64 `json:"accuracy,omitempty"` // Mock accuracy
}
// SetGeolocationOverride overrides the Geolocation Position or Error.
// Omitting any of the parameters emulates position unavailable.
//
// parameters:
func SetGeolocationOverride() *SetGeolocationOverrideParams {
return &SetGeolocationOverrideParams{}
}
// WithLatitude mock latitude.
func (p SetGeolocationOverrideParams) WithLatitude(latitude float64) *SetGeolocationOverrideParams {
p.Latitude = latitude
return &p
}
// WithLongitude mock longitude.
func (p SetGeolocationOverrideParams) WithLongitude(longitude float64) *SetGeolocationOverrideParams {
p.Longitude = longitude
return &p
}
// WithAccuracy mock accuracy.
func (p SetGeolocationOverrideParams) WithAccuracy(accuracy float64) *SetGeolocationOverrideParams {
p.Accuracy = accuracy
return &p
}
// Do executes Emulation.setGeolocationOverride against the provided context and
// target handler.
func (p *SetGeolocationOverrideParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationSetGeolocationOverride, p, nil)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetNavigatorOverridesParams overrides value returned by the javascript
// navigator object.
type SetNavigatorOverridesParams struct {
Platform string `json:"platform"` // The platform navigator.platform should return.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetNavigatorOverrides overrides value returned by the javascript navigator
// object.
2017-01-24 15:09:23 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
// platform - The platform navigator.platform should return.
func SetNavigatorOverrides(platform string) *SetNavigatorOverridesParams {
return &SetNavigatorOverridesParams{
Platform: platform,
2017-01-24 15:09:23 +00:00
}
}
2017-12-18 00:23:14 +00:00
// Do executes Emulation.setNavigatorOverrides against the provided context and
// target handler.
2017-12-18 00:23:14 +00:00
func (p *SetNavigatorOverridesParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationSetNavigatorOverrides, p, nil)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetPageScaleFactorParams sets a specified page scale factor.
type SetPageScaleFactorParams struct {
PageScaleFactor float64 `json:"pageScaleFactor"` // Page scale factor.
2017-08-11 02:28:38 +00:00
}
2017-12-18 00:23:14 +00:00
// SetPageScaleFactor sets a specified page scale factor.
2017-08-11 02:28:38 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
// pageScaleFactor - Page scale factor.
func SetPageScaleFactor(pageScaleFactor float64) *SetPageScaleFactorParams {
return &SetPageScaleFactorParams{
PageScaleFactor: pageScaleFactor,
2017-08-11 02:28:38 +00:00
}
}
2017-12-18 00:23:14 +00:00
// Do executes Emulation.setPageScaleFactor against the provided context and
2017-08-11 02:28:38 +00:00
// target handler.
2017-12-18 00:23:14 +00:00
func (p *SetPageScaleFactorParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationSetPageScaleFactor, p, nil)
2017-08-11 02:28:38 +00:00
}
2017-12-18 00:23:14 +00:00
// SetScriptExecutionDisabledParams switches script execution in the page.
type SetScriptExecutionDisabledParams struct {
Value bool `json:"value"` // Whether script execution should be disabled in the page.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetScriptExecutionDisabled switches script execution in the page.
2017-01-24 15:09:23 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
// value - Whether script execution should be disabled in the page.
func SetScriptExecutionDisabled(value bool) *SetScriptExecutionDisabledParams {
return &SetScriptExecutionDisabledParams{
Value: value,
2017-01-24 15:09:23 +00:00
}
}
2017-12-18 00:23:14 +00:00
// Do executes Emulation.setScriptExecutionDisabled against the provided context and
// target handler.
2017-12-18 00:23:14 +00:00
func (p *SetScriptExecutionDisabledParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationSetScriptExecutionDisabled, p, nil)
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetTouchEmulationEnabledParams enables touch on platforms which do not
// support them.
type SetTouchEmulationEnabledParams struct {
Enabled bool `json:"enabled"` // Whether the touch event emulation should be enabled.
MaxTouchPoints int64 `json:"maxTouchPoints,omitempty"` // Maximum touch points supported. Defaults to one.
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// SetTouchEmulationEnabled enables touch on platforms which do not support
// them.
2017-01-24 15:09:23 +00:00
//
// parameters:
2017-12-18 00:23:14 +00:00
// enabled - Whether the touch event emulation should be enabled.
func SetTouchEmulationEnabled(enabled bool) *SetTouchEmulationEnabledParams {
return &SetTouchEmulationEnabledParams{
Enabled: enabled,
2017-01-24 15:09:23 +00:00
}
}
2017-12-18 00:23:14 +00:00
// WithMaxTouchPoints maximum touch points supported. Defaults to one.
func (p SetTouchEmulationEnabledParams) WithMaxTouchPoints(maxTouchPoints int64) *SetTouchEmulationEnabledParams {
p.MaxTouchPoints = maxTouchPoints
return &p
2017-01-24 15:09:23 +00:00
}
2017-12-18 00:23:14 +00:00
// Do executes Emulation.setTouchEmulationEnabled against the provided context and
// target handler.
2017-12-18 00:23:14 +00:00
func (p *SetTouchEmulationEnabledParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandEmulationSetTouchEmulationEnabled, p, nil)
2017-01-24 15:09:23 +00:00
}
// SetVirtualTimePolicyParams turns on virtual time for all frames (replacing
// real-time with a synthetic time source) and sets the current virtual time
// policy. Note this supersedes any previous time budget.
type SetVirtualTimePolicyParams struct {
2017-10-24 02:06:01 +00:00
Policy VirtualTimePolicy `json:"policy"`
2017-11-22 05:01:27 +00:00
Budget float64 `json:"budget,omitempty"` // If set, after this many virtual milliseconds have elapsed virtual time will be paused and a virtualTimeBudgetExpired event is sent.
2017-10-24 02:06:01 +00:00
MaxVirtualTimeTaskStarvationCount int64 `json:"maxVirtualTimeTaskStarvationCount,omitempty"` // If set this specifies the maximum number of tasks that can be run before virtual is forced forwards to prevent deadlock.
2017-01-24 15:09:23 +00:00
}
// SetVirtualTimePolicy turns on virtual time for all frames (replacing
// real-time with a synthetic time source) and sets the current virtual time
// policy. Note this supersedes any previous time budget.
//
// parameters:
// policy
func SetVirtualTimePolicy(policy VirtualTimePolicy) *SetVirtualTimePolicyParams {
return &SetVirtualTimePolicyParams{
Policy: policy,
}
}
// WithBudget if set, after this many virtual milliseconds have elapsed
// virtual time will be paused and a virtualTimeBudgetExpired event is sent.
2017-11-22 05:01:27 +00:00
func (p SetVirtualTimePolicyParams) WithBudget(budget float64) *SetVirtualTimePolicyParams {
2017-01-24 15:09:23 +00:00
p.Budget = budget
return &p
}
2017-10-24 02:06:01 +00:00
// WithMaxVirtualTimeTaskStarvationCount if set this specifies the maximum
// number of tasks that can be run before virtual is forced forwards to prevent
// deadlock.
func (p SetVirtualTimePolicyParams) WithMaxVirtualTimeTaskStarvationCount(maxVirtualTimeTaskStarvationCount int64) *SetVirtualTimePolicyParams {
p.MaxVirtualTimeTaskStarvationCount = maxVirtualTimeTaskStarvationCount
return &p
}
2017-11-22 05:01:27 +00:00
// SetVirtualTimePolicyReturns return values.
type SetVirtualTimePolicyReturns struct {
VirtualTimeBase *runtime.Timestamp `json:"virtualTimeBase,omitempty"` // Absolute timestamp at which virtual time was first enabled (milliseconds since epoch).
}
// Do executes Emulation.setVirtualTimePolicy against the provided context and
// target handler.
2017-11-22 05:01:27 +00:00
//
// returns:
// virtualTimeBase - Absolute timestamp at which virtual time was first enabled (milliseconds since epoch).
func (p *SetVirtualTimePolicyParams) Do(ctxt context.Context, h cdp.Handler) (virtualTimeBase *runtime.Timestamp, err error) {
// execute
var res SetVirtualTimePolicyReturns
err = h.Execute(ctxt, cdp.CommandEmulationSetVirtualTimePolicy, p, &res)
if err != nil {
return nil, err
}
return res.VirtualTimeBase, nil
2017-01-24 15:09:23 +00:00
}