2017-01-24 15:09:23 +00:00
// Package target provides the Chrome Debugging Protocol
// commands, types, and events for the Chrome Target domain.
//
// Supports additional targets discovery and allows to attach to them.
//
// Generated by the chromedp-gen command.
package target
// AUTOGENERATED. DO NOT EDIT.
import (
"context"
2017-01-26 07:28:34 +00:00
cdp "github.com/knq/chromedp/cdp"
2017-01-24 15:09:23 +00:00
"github.com/mailru/easyjson"
)
// SetDiscoverTargetsParams controls whether to discover available targets
// and notify via targetCreated/targetDestroyed events.
type SetDiscoverTargetsParams struct {
Discover bool ` json:"discover" ` // Whether to discover available targets.
}
// SetDiscoverTargets controls whether to discover available targets and
// notify via targetCreated/targetDestroyed events.
//
// parameters:
// discover - Whether to discover available targets.
func SetDiscoverTargets ( discover bool ) * SetDiscoverTargetsParams {
return & SetDiscoverTargetsParams {
Discover : discover ,
}
}
// Do executes Target.setDiscoverTargets.
2017-01-26 07:28:34 +00:00
func ( p * SetDiscoverTargetsParams ) 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 . CommandTargetSetDiscoverTargets , 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
}
// SetAutoAttachParams controls whether to automatically attach to new
// targets which are considered to be related to this one. When turned on,
// attaches to all existing related targets as well. When turned off,
// automatically detaches from all currently attached targets.
type SetAutoAttachParams struct {
AutoAttach bool ` json:"autoAttach" ` // Whether to auto-attach to related targets.
WaitForDebuggerOnStart bool ` json:"waitForDebuggerOnStart" ` // Whether to pause new targets when attaching to them. Use Runtime.runIfWaitingForDebugger to run paused targets.
}
// SetAutoAttach controls whether to automatically attach to new targets
// which are considered to be related to this one. When turned on, attaches to
// all existing related targets as well. When turned off, automatically detaches
// from all currently attached targets.
//
// parameters:
// autoAttach - Whether to auto-attach to related targets.
// waitForDebuggerOnStart - Whether to pause new targets when attaching to them. Use Runtime.runIfWaitingForDebugger to run paused targets.
func SetAutoAttach ( autoAttach bool , waitForDebuggerOnStart bool ) * SetAutoAttachParams {
return & SetAutoAttachParams {
AutoAttach : autoAttach ,
WaitForDebuggerOnStart : waitForDebuggerOnStart ,
}
}
// Do executes Target.setAutoAttach.
2017-01-26 07:28:34 +00:00
func ( p * SetAutoAttachParams ) 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 . CommandTargetSetAutoAttach , 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
// SetAttachToFramesParams [no description].
2017-01-24 15:09:23 +00:00
type SetAttachToFramesParams struct {
Value bool ` json:"value" ` // Whether to attach to frames.
}
2017-01-26 07:28:34 +00:00
// SetAttachToFrames [no description].
//
2017-01-24 15:09:23 +00:00
// parameters:
// value - Whether to attach to frames.
func SetAttachToFrames ( value bool ) * SetAttachToFramesParams {
return & SetAttachToFramesParams {
Value : value ,
}
}
// Do executes Target.setAttachToFrames.
2017-01-26 07:28:34 +00:00
func ( p * SetAttachToFramesParams ) 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 . CommandTargetSetAttachToFrames , 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
}
// SetRemoteLocationsParams enables target discovery for the specified
// locations, when setDiscoverTargets was set to true.
type SetRemoteLocationsParams struct {
Locations [ ] * RemoteLocation ` json:"locations" ` // List of remote locations.
}
// SetRemoteLocations enables target discovery for the specified locations,
// when setDiscoverTargets was set to true.
//
// parameters:
// locations - List of remote locations.
func SetRemoteLocations ( locations [ ] * RemoteLocation ) * SetRemoteLocationsParams {
return & SetRemoteLocationsParams {
Locations : locations ,
}
}
// Do executes Target.setRemoteLocations.
2017-01-26 07:28:34 +00:00
func ( p * SetRemoteLocationsParams ) 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 . CommandTargetSetRemoteLocations , 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
}
// SendMessageToTargetParams sends protocol message to the target with given
// id.
type SendMessageToTargetParams struct {
TargetID string ` json:"targetId" `
Message string ` json:"message" `
}
// SendMessageToTarget sends protocol message to the target with given id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// targetID
2017-01-24 15:09:23 +00:00
// message
2017-01-26 07:28:34 +00:00
func SendMessageToTarget ( targetID string , message string ) * SendMessageToTargetParams {
2017-01-24 15:09:23 +00:00
return & SendMessageToTargetParams {
2017-01-26 07:28:34 +00:00
TargetID : targetID ,
2017-01-24 15:09:23 +00:00
Message : message ,
}
}
// Do executes Target.sendMessageToTarget.
2017-01-26 07:28:34 +00:00
func ( p * SendMessageToTargetParams ) 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 . CommandTargetSendMessageToTarget , 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
}
// GetTargetInfoParams returns information about a target.
type GetTargetInfoParams struct {
2017-01-26 07:28:34 +00:00
TargetID ID ` json:"targetId" `
2017-01-24 15:09:23 +00:00
}
// GetTargetInfo returns information about a target.
//
// parameters:
2017-01-26 07:28:34 +00:00
// targetID
func GetTargetInfo ( targetID ID ) * GetTargetInfoParams {
2017-01-24 15:09:23 +00:00
return & GetTargetInfoParams {
2017-01-26 07:28:34 +00:00
TargetID : targetID ,
2017-01-24 15:09:23 +00:00
}
}
// GetTargetInfoReturns return values.
type GetTargetInfoReturns struct {
2017-01-26 07:28:34 +00:00
TargetInfo * Info ` json:"targetInfo,omitempty" `
2017-01-24 15:09:23 +00:00
}
// Do executes Target.getTargetInfo.
//
// returns:
// targetInfo
2017-01-26 07:28:34 +00:00
func ( p * GetTargetInfoParams ) Do ( ctxt context . Context , h cdp . FrameHandler ) ( targetInfo * Info , 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 . CommandTargetGetTargetInfo , 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 GetTargetInfoReturns
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 . TargetInfo , 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
}
// ActivateTargetParams activates (focuses) the target.
type ActivateTargetParams struct {
2017-01-26 07:28:34 +00:00
TargetID ID ` json:"targetId" `
2017-01-24 15:09:23 +00:00
}
// ActivateTarget activates (focuses) the target.
//
// parameters:
2017-01-26 07:28:34 +00:00
// targetID
func ActivateTarget ( targetID ID ) * ActivateTargetParams {
2017-01-24 15:09:23 +00:00
return & ActivateTargetParams {
2017-01-26 07:28:34 +00:00
TargetID : targetID ,
2017-01-24 15:09:23 +00:00
}
}
// Do executes Target.activateTarget.
2017-01-26 07:28:34 +00:00
func ( p * ActivateTargetParams ) 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 . CommandTargetActivateTarget , 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
}
// CloseTargetParams closes the target. If the target is a page that gets
// closed too.
type CloseTargetParams struct {
2017-01-26 07:28:34 +00:00
TargetID ID ` json:"targetId" `
2017-01-24 15:09:23 +00:00
}
// CloseTarget closes the target. If the target is a page that gets closed
// too.
//
// parameters:
2017-01-26 07:28:34 +00:00
// targetID
func CloseTarget ( targetID ID ) * CloseTargetParams {
2017-01-24 15:09:23 +00:00
return & CloseTargetParams {
2017-01-26 07:28:34 +00:00
TargetID : targetID ,
2017-01-24 15:09:23 +00:00
}
}
// CloseTargetReturns return values.
type CloseTargetReturns struct {
Success bool ` json:"success,omitempty" `
}
// Do executes Target.closeTarget.
//
// returns:
// success
2017-01-26 07:28:34 +00:00
func ( p * CloseTargetParams ) Do ( ctxt context . Context , h cdp . FrameHandler ) ( success bool , 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 false , err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h . Execute ( ctxt , cdp . CommandTargetCloseTarget , 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 false , cdp . ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res . ( type ) {
case easyjson . RawMessage :
// unmarshal
var r CloseTargetReturns
err = easyjson . Unmarshal ( v , & r )
if err != nil {
2017-01-26 07:28:34 +00:00
return false , cdp . ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r . Success , nil
case error :
return false , v
}
case <- ctxt . Done ( ) :
2017-01-26 07:28:34 +00:00
return false , cdp . ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return false , cdp . ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// AttachToTargetParams attaches to the target with given id.
type AttachToTargetParams struct {
2017-01-26 07:28:34 +00:00
TargetID ID ` json:"targetId" `
2017-01-24 15:09:23 +00:00
}
// AttachToTarget attaches to the target with given id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// targetID
func AttachToTarget ( targetID ID ) * AttachToTargetParams {
2017-01-24 15:09:23 +00:00
return & AttachToTargetParams {
2017-01-26 07:28:34 +00:00
TargetID : targetID ,
2017-01-24 15:09:23 +00:00
}
}
// AttachToTargetReturns return values.
type AttachToTargetReturns struct {
Success bool ` json:"success,omitempty" ` // Whether attach succeeded.
}
// Do executes Target.attachToTarget.
//
// returns:
// success - Whether attach succeeded.
2017-01-26 07:28:34 +00:00
func ( p * AttachToTargetParams ) Do ( ctxt context . Context , h cdp . FrameHandler ) ( success bool , 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 false , err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h . Execute ( ctxt , cdp . CommandTargetAttachToTarget , 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 false , cdp . ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res . ( type ) {
case easyjson . RawMessage :
// unmarshal
var r AttachToTargetReturns
err = easyjson . Unmarshal ( v , & r )
if err != nil {
2017-01-26 07:28:34 +00:00
return false , cdp . ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r . Success , nil
case error :
return false , v
}
case <- ctxt . Done ( ) :
2017-01-26 07:28:34 +00:00
return false , cdp . ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return false , cdp . ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// DetachFromTargetParams detaches from the target with given id.
type DetachFromTargetParams struct {
2017-01-26 07:28:34 +00:00
TargetID ID ` json:"targetId" `
2017-01-24 15:09:23 +00:00
}
// DetachFromTarget detaches from the target with given id.
//
// parameters:
2017-01-26 07:28:34 +00:00
// targetID
func DetachFromTarget ( targetID ID ) * DetachFromTargetParams {
2017-01-24 15:09:23 +00:00
return & DetachFromTargetParams {
2017-01-26 07:28:34 +00:00
TargetID : targetID ,
2017-01-24 15:09:23 +00:00
}
}
// Do executes Target.detachFromTarget.
2017-01-26 07:28:34 +00:00
func ( p * DetachFromTargetParams ) 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 . CommandTargetDetachFromTarget , 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
}
// CreateBrowserContextParams creates a new empty BrowserContext. Similar to
// an incognito profile but you can have more than one.
type CreateBrowserContextParams struct { }
// CreateBrowserContext creates a new empty BrowserContext. Similar to an
// incognito profile but you can have more than one.
func CreateBrowserContext ( ) * CreateBrowserContextParams {
return & CreateBrowserContextParams { }
}
// CreateBrowserContextReturns return values.
type CreateBrowserContextReturns struct {
BrowserContextID BrowserContextID ` json:"browserContextId,omitempty" ` // The id of the context created.
}
// Do executes Target.createBrowserContext.
//
// returns:
2017-01-26 07:28:34 +00:00
// browserContextID - The id of the context created.
func ( p * CreateBrowserContextParams ) Do ( ctxt context . Context , h cdp . FrameHandler ) ( browserContextID BrowserContextID , 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 . CommandTargetCreateBrowserContext , 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 :
// unmarshal
var r CreateBrowserContextReturns
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 . BrowserContextID , 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
}
// DisposeBrowserContextParams deletes a BrowserContext, will fail of any
// open page uses it.
type DisposeBrowserContextParams struct {
BrowserContextID BrowserContextID ` json:"browserContextId" `
}
// DisposeBrowserContext deletes a BrowserContext, will fail of any open page
// uses it.
//
// parameters:
2017-01-26 07:28:34 +00:00
// browserContextID
func DisposeBrowserContext ( browserContextID BrowserContextID ) * DisposeBrowserContextParams {
2017-01-24 15:09:23 +00:00
return & DisposeBrowserContextParams {
2017-01-26 07:28:34 +00:00
BrowserContextID : browserContextID ,
2017-01-24 15:09:23 +00:00
}
}
// DisposeBrowserContextReturns return values.
type DisposeBrowserContextReturns struct {
Success bool ` json:"success,omitempty" `
}
// Do executes Target.disposeBrowserContext.
//
// returns:
// success
2017-01-26 07:28:34 +00:00
func ( p * DisposeBrowserContextParams ) Do ( ctxt context . Context , h cdp . FrameHandler ) ( success bool , 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 false , err
}
// execute
2017-01-26 07:28:34 +00:00
ch := h . Execute ( ctxt , cdp . CommandTargetDisposeBrowserContext , 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 false , cdp . ErrChannelClosed
2017-01-24 15:09:23 +00:00
}
switch v := res . ( type ) {
case easyjson . RawMessage :
// unmarshal
var r DisposeBrowserContextReturns
err = easyjson . Unmarshal ( v , & r )
if err != nil {
2017-01-26 07:28:34 +00:00
return false , cdp . ErrInvalidResult
2017-01-24 15:09:23 +00:00
}
return r . Success , nil
case error :
return false , v
}
case <- ctxt . Done ( ) :
2017-01-26 07:28:34 +00:00
return false , cdp . ErrContextDone
2017-01-24 15:09:23 +00:00
}
2017-01-26 07:28:34 +00:00
return false , cdp . ErrUnknownResult
2017-01-24 15:09:23 +00:00
}
// CreateTargetParams creates a new page.
type CreateTargetParams struct {
URL string ` json:"url" ` // The initial URL the page will be navigated to.
Width int64 ` json:"width,omitempty" ` // Frame width in DIP (headless chrome only).
Height int64 ` json:"height,omitempty" ` // Frame height in DIP (headless chrome only).
BrowserContextID BrowserContextID ` json:"browserContextId,omitempty" ` // The browser context to create the page in (headless chrome only).
}
// CreateTarget creates a new page.
//
// parameters:
// url - The initial URL the page will be navigated to.
func CreateTarget ( url string ) * CreateTargetParams {
return & CreateTargetParams {
URL : url ,
}
}
// WithWidth frame width in DIP (headless chrome only).
func ( p CreateTargetParams ) WithWidth ( width int64 ) * CreateTargetParams {
p . Width = width
return & p
}
// WithHeight frame height in DIP (headless chrome only).
func ( p CreateTargetParams ) WithHeight ( height int64 ) * CreateTargetParams {
p . Height = height
return & p
}
// WithBrowserContextID the browser context to create the page in (headless
// chrome only).
2017-01-26 07:28:34 +00:00
func ( p CreateTargetParams ) WithBrowserContextID ( browserContextID BrowserContextID ) * CreateTargetParams {
p . BrowserContextID = browserContextID
2017-01-24 15:09:23 +00:00
return & p
}
// CreateTargetReturns return values.
type CreateTargetReturns struct {
2017-01-26 07:28:34 +00:00
TargetID ID ` json:"targetId,omitempty" ` // The id of the page opened.
2017-01-24 15:09:23 +00:00
}
// Do executes Target.createTarget.
//
// returns:
2017-01-26 07:28:34 +00:00
// targetID - The id of the page opened.
func ( p * CreateTargetParams ) Do ( ctxt context . Context , h cdp . FrameHandler ) ( targetID ID , 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 . CommandTargetCreateTarget , 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 CreateTargetReturns
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 . TargetID , 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
}
// GetTargetsParams retrieves a list of available targets.
type GetTargetsParams struct { }
// GetTargets retrieves a list of available targets.
func GetTargets ( ) * GetTargetsParams {
return & GetTargetsParams { }
}
// GetTargetsReturns return values.
type GetTargetsReturns struct {
2017-01-26 07:28:34 +00:00
TargetInfos [ ] * Info ` json:"targetInfos,omitempty" ` // The list of targets.
2017-01-24 15:09:23 +00:00
}
// Do executes Target.getTargets.
//
// returns:
// targetInfos - The list of targets.
2017-01-26 07:28:34 +00:00
func ( p * GetTargetsParams ) Do ( ctxt context . Context , h cdp . FrameHandler ) ( targetInfos [ ] * Info , 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 . CommandTargetGetTargets , 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 GetTargetsReturns
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 . TargetInfos , 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
}