1// Package target provides the Chrome DevTools Protocol 2// commands, types, and events for the Target domain. 3// 4// Supports additional targets discovery and allows to attach to them. 5// 6// Generated by the cdproto-gen command. 7package target 8 9// Code generated by cdproto-gen. DO NOT EDIT. 10 11import ( 12 "context" 13 14 "github.com/chromedp/cdproto/cdp" 15) 16 17// ActivateTargetParams activates (focuses) the target. 18type ActivateTargetParams struct { 19 TargetID ID `json:"targetId"` 20} 21 22// ActivateTarget activates (focuses) the target. 23// 24// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-activateTarget 25// 26// parameters: 27// targetID 28func ActivateTarget(targetID ID) *ActivateTargetParams { 29 return &ActivateTargetParams{ 30 TargetID: targetID, 31 } 32} 33 34// Do executes Target.activateTarget against the provided context. 35func (p *ActivateTargetParams) Do(ctx context.Context) (err error) { 36 return cdp.Execute(ctx, CommandActivateTarget, p, nil) 37} 38 39// AttachToTargetParams attaches to the target with given id. 40type AttachToTargetParams struct { 41 TargetID ID `json:"targetId"` 42 Flatten bool `json:"flatten,omitempty"` // Enables "flat" access to the session via specifying sessionId attribute in the commands. We plan to make this the default, deprecate non-flattened mode, and eventually retire it. See crbug.com/991325. 43} 44 45// AttachToTarget attaches to the target with given id. 46// 47// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-attachToTarget 48// 49// parameters: 50// targetID 51func AttachToTarget(targetID ID) *AttachToTargetParams { 52 return &AttachToTargetParams{ 53 TargetID: targetID, 54 } 55} 56 57// WithFlatten enables "flat" access to the session via specifying sessionId 58// attribute in the commands. We plan to make this the default, deprecate 59// non-flattened mode, and eventually retire it. See crbug.com/991325. 60func (p AttachToTargetParams) WithFlatten(flatten bool) *AttachToTargetParams { 61 p.Flatten = flatten 62 return &p 63} 64 65// AttachToTargetReturns return values. 66type AttachToTargetReturns struct { 67 SessionID SessionID `json:"sessionId,omitempty"` // Id assigned to the session. 68} 69 70// Do executes Target.attachToTarget against the provided context. 71// 72// returns: 73// sessionID - Id assigned to the session. 74func (p *AttachToTargetParams) Do(ctx context.Context) (sessionID SessionID, err error) { 75 // execute 76 var res AttachToTargetReturns 77 err = cdp.Execute(ctx, CommandAttachToTarget, p, &res) 78 if err != nil { 79 return "", err 80 } 81 82 return res.SessionID, nil 83} 84 85// AttachToBrowserTargetParams attaches to the browser target, only uses flat 86// sessionId mode. 87type AttachToBrowserTargetParams struct{} 88 89// AttachToBrowserTarget attaches to the browser target, only uses flat 90// sessionId mode. 91// 92// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-attachToBrowserTarget 93func AttachToBrowserTarget() *AttachToBrowserTargetParams { 94 return &AttachToBrowserTargetParams{} 95} 96 97// AttachToBrowserTargetReturns return values. 98type AttachToBrowserTargetReturns struct { 99 SessionID SessionID `json:"sessionId,omitempty"` // Id assigned to the session. 100} 101 102// Do executes Target.attachToBrowserTarget against the provided context. 103// 104// returns: 105// sessionID - Id assigned to the session. 106func (p *AttachToBrowserTargetParams) Do(ctx context.Context) (sessionID SessionID, err error) { 107 // execute 108 var res AttachToBrowserTargetReturns 109 err = cdp.Execute(ctx, CommandAttachToBrowserTarget, nil, &res) 110 if err != nil { 111 return "", err 112 } 113 114 return res.SessionID, nil 115} 116 117// CloseTargetParams closes the target. If the target is a page that gets 118// closed too. 119type CloseTargetParams struct { 120 TargetID ID `json:"targetId"` 121} 122 123// CloseTarget closes the target. If the target is a page that gets closed 124// too. 125// 126// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-closeTarget 127// 128// parameters: 129// targetID 130func CloseTarget(targetID ID) *CloseTargetParams { 131 return &CloseTargetParams{ 132 TargetID: targetID, 133 } 134} 135 136// CloseTargetReturns return values. 137type CloseTargetReturns struct { 138 Success bool `json:"success,omitempty"` 139} 140 141// Do executes Target.closeTarget against the provided context. 142// 143// returns: 144// success 145func (p *CloseTargetParams) Do(ctx context.Context) (success bool, err error) { 146 // execute 147 var res CloseTargetReturns 148 err = cdp.Execute(ctx, CommandCloseTarget, p, &res) 149 if err != nil { 150 return false, err 151 } 152 153 return res.Success, nil 154} 155 156// ExposeDevToolsProtocolParams inject object to the target's main frame that 157// provides a communication channel with browser target. Injected object will be 158// available as window[bindingName]. The object has the follwing API: - 159// binding.send(json) - a method to send messages over the remote debugging 160// protocol - binding.onmessage = json => handleMessage(json) - a callback that 161// will be called for the protocol notifications and command responses. 162type ExposeDevToolsProtocolParams struct { 163 TargetID ID `json:"targetId"` 164 BindingName string `json:"bindingName,omitempty"` // Binding name, 'cdp' if not specified. 165} 166 167// ExposeDevToolsProtocol inject object to the target's main frame that 168// provides a communication channel with browser target. Injected object will be 169// available as window[bindingName]. The object has the follwing API: - 170// binding.send(json) - a method to send messages over the remote debugging 171// protocol - binding.onmessage = json => handleMessage(json) - a callback that 172// will be called for the protocol notifications and command responses. 173// 174// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-exposeDevToolsProtocol 175// 176// parameters: 177// targetID 178func ExposeDevToolsProtocol(targetID ID) *ExposeDevToolsProtocolParams { 179 return &ExposeDevToolsProtocolParams{ 180 TargetID: targetID, 181 } 182} 183 184// WithBindingName binding name, 'cdp' if not specified. 185func (p ExposeDevToolsProtocolParams) WithBindingName(bindingName string) *ExposeDevToolsProtocolParams { 186 p.BindingName = bindingName 187 return &p 188} 189 190// Do executes Target.exposeDevToolsProtocol against the provided context. 191func (p *ExposeDevToolsProtocolParams) Do(ctx context.Context) (err error) { 192 return cdp.Execute(ctx, CommandExposeDevToolsProtocol, p, nil) 193} 194 195// CreateBrowserContextParams creates a new empty BrowserContext. Similar to 196// an incognito profile but you can have more than one. 197type CreateBrowserContextParams struct{} 198 199// CreateBrowserContext creates a new empty BrowserContext. Similar to an 200// incognito profile but you can have more than one. 201// 202// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-createBrowserContext 203func CreateBrowserContext() *CreateBrowserContextParams { 204 return &CreateBrowserContextParams{} 205} 206 207// CreateBrowserContextReturns return values. 208type CreateBrowserContextReturns struct { 209 BrowserContextID cdp.BrowserContextID `json:"browserContextId,omitempty"` // The id of the context created. 210} 211 212// Do executes Target.createBrowserContext against the provided context. 213// 214// returns: 215// browserContextID - The id of the context created. 216func (p *CreateBrowserContextParams) Do(ctx context.Context) (browserContextID cdp.BrowserContextID, err error) { 217 // execute 218 var res CreateBrowserContextReturns 219 err = cdp.Execute(ctx, CommandCreateBrowserContext, nil, &res) 220 if err != nil { 221 return "", err 222 } 223 224 return res.BrowserContextID, nil 225} 226 227// GetBrowserContextsParams returns all browser contexts created with 228// Target.createBrowserContext method. 229type GetBrowserContextsParams struct{} 230 231// GetBrowserContexts returns all browser contexts created with 232// Target.createBrowserContext method. 233// 234// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-getBrowserContexts 235func GetBrowserContexts() *GetBrowserContextsParams { 236 return &GetBrowserContextsParams{} 237} 238 239// GetBrowserContextsReturns return values. 240type GetBrowserContextsReturns struct { 241 BrowserContextIds []cdp.BrowserContextID `json:"browserContextIds,omitempty"` // An array of browser context ids. 242} 243 244// Do executes Target.getBrowserContexts against the provided context. 245// 246// returns: 247// browserContextIds - An array of browser context ids. 248func (p *GetBrowserContextsParams) Do(ctx context.Context) (browserContextIds []cdp.BrowserContextID, err error) { 249 // execute 250 var res GetBrowserContextsReturns 251 err = cdp.Execute(ctx, CommandGetBrowserContexts, nil, &res) 252 if err != nil { 253 return nil, err 254 } 255 256 return res.BrowserContextIds, nil 257} 258 259// CreateTargetParams creates a new page. 260type CreateTargetParams struct { 261 URL string `json:"url"` // The initial URL the page will be navigated to. 262 Width int64 `json:"width,omitempty"` // Frame width in DIP (headless chrome only). 263 Height int64 `json:"height,omitempty"` // Frame height in DIP (headless chrome only). 264 BrowserContextID cdp.BrowserContextID `json:"browserContextId,omitempty"` // The browser context to create the page in. 265 EnableBeginFrameControl bool `json:"enableBeginFrameControl,omitempty"` // Whether BeginFrames for this target will be controlled via DevTools (headless chrome only, not supported on MacOS yet, false by default). 266 NewWindow bool `json:"newWindow,omitempty"` // Whether to create a new Window or Tab (chrome-only, false by default). 267 Background bool `json:"background,omitempty"` // Whether to create the target in background or foreground (chrome-only, false by default). 268} 269 270// CreateTarget creates a new page. 271// 272// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-createTarget 273// 274// parameters: 275// url - The initial URL the page will be navigated to. 276func CreateTarget(url string) *CreateTargetParams { 277 return &CreateTargetParams{ 278 URL: url, 279 } 280} 281 282// WithWidth frame width in DIP (headless chrome only). 283func (p CreateTargetParams) WithWidth(width int64) *CreateTargetParams { 284 p.Width = width 285 return &p 286} 287 288// WithHeight frame height in DIP (headless chrome only). 289func (p CreateTargetParams) WithHeight(height int64) *CreateTargetParams { 290 p.Height = height 291 return &p 292} 293 294// WithBrowserContextID the browser context to create the page in. 295func (p CreateTargetParams) WithBrowserContextID(browserContextID cdp.BrowserContextID) *CreateTargetParams { 296 p.BrowserContextID = browserContextID 297 return &p 298} 299 300// WithEnableBeginFrameControl whether BeginFrames for this target will be 301// controlled via DevTools (headless chrome only, not supported on MacOS yet, 302// false by default). 303func (p CreateTargetParams) WithEnableBeginFrameControl(enableBeginFrameControl bool) *CreateTargetParams { 304 p.EnableBeginFrameControl = enableBeginFrameControl 305 return &p 306} 307 308// WithNewWindow whether to create a new Window or Tab (chrome-only, false by 309// default). 310func (p CreateTargetParams) WithNewWindow(newWindow bool) *CreateTargetParams { 311 p.NewWindow = newWindow 312 return &p 313} 314 315// WithBackground whether to create the target in background or foreground 316// (chrome-only, false by default). 317func (p CreateTargetParams) WithBackground(background bool) *CreateTargetParams { 318 p.Background = background 319 return &p 320} 321 322// CreateTargetReturns return values. 323type CreateTargetReturns struct { 324 TargetID ID `json:"targetId,omitempty"` // The id of the page opened. 325} 326 327// Do executes Target.createTarget against the provided context. 328// 329// returns: 330// targetID - The id of the page opened. 331func (p *CreateTargetParams) Do(ctx context.Context) (targetID ID, err error) { 332 // execute 333 var res CreateTargetReturns 334 err = cdp.Execute(ctx, CommandCreateTarget, p, &res) 335 if err != nil { 336 return "", err 337 } 338 339 return res.TargetID, nil 340} 341 342// DetachFromTargetParams detaches session with given id. 343type DetachFromTargetParams struct { 344 SessionID SessionID `json:"sessionId,omitempty"` // Session to detach. 345} 346 347// DetachFromTarget detaches session with given id. 348// 349// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-detachFromTarget 350// 351// parameters: 352func DetachFromTarget() *DetachFromTargetParams { 353 return &DetachFromTargetParams{} 354} 355 356// WithSessionID session to detach. 357func (p DetachFromTargetParams) WithSessionID(sessionID SessionID) *DetachFromTargetParams { 358 p.SessionID = sessionID 359 return &p 360} 361 362// Do executes Target.detachFromTarget against the provided context. 363func (p *DetachFromTargetParams) Do(ctx context.Context) (err error) { 364 return cdp.Execute(ctx, CommandDetachFromTarget, p, nil) 365} 366 367// DisposeBrowserContextParams deletes a BrowserContext. All the belonging 368// pages will be closed without calling their beforeunload hooks. 369type DisposeBrowserContextParams struct { 370 BrowserContextID cdp.BrowserContextID `json:"browserContextId"` 371} 372 373// DisposeBrowserContext deletes a BrowserContext. All the belonging pages 374// will be closed without calling their beforeunload hooks. 375// 376// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-disposeBrowserContext 377// 378// parameters: 379// browserContextID 380func DisposeBrowserContext(browserContextID cdp.BrowserContextID) *DisposeBrowserContextParams { 381 return &DisposeBrowserContextParams{ 382 BrowserContextID: browserContextID, 383 } 384} 385 386// Do executes Target.disposeBrowserContext against the provided context. 387func (p *DisposeBrowserContextParams) Do(ctx context.Context) (err error) { 388 return cdp.Execute(ctx, CommandDisposeBrowserContext, p, nil) 389} 390 391// GetTargetInfoParams returns information about a target. 392type GetTargetInfoParams struct { 393 TargetID ID `json:"targetId,omitempty"` 394} 395 396// GetTargetInfo returns information about a target. 397// 398// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-getTargetInfo 399// 400// parameters: 401func GetTargetInfo() *GetTargetInfoParams { 402 return &GetTargetInfoParams{} 403} 404 405// WithTargetID [no description]. 406func (p GetTargetInfoParams) WithTargetID(targetID ID) *GetTargetInfoParams { 407 p.TargetID = targetID 408 return &p 409} 410 411// GetTargetInfoReturns return values. 412type GetTargetInfoReturns struct { 413 TargetInfo *Info `json:"targetInfo,omitempty"` 414} 415 416// Do executes Target.getTargetInfo against the provided context. 417// 418// returns: 419// targetInfo 420func (p *GetTargetInfoParams) Do(ctx context.Context) (targetInfo *Info, err error) { 421 // execute 422 var res GetTargetInfoReturns 423 err = cdp.Execute(ctx, CommandGetTargetInfo, p, &res) 424 if err != nil { 425 return nil, err 426 } 427 428 return res.TargetInfo, nil 429} 430 431// GetTargetsParams retrieves a list of available targets. 432type GetTargetsParams struct{} 433 434// GetTargets retrieves a list of available targets. 435// 436// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-getTargets 437func GetTargets() *GetTargetsParams { 438 return &GetTargetsParams{} 439} 440 441// GetTargetsReturns return values. 442type GetTargetsReturns struct { 443 TargetInfos []*Info `json:"targetInfos,omitempty"` // The list of targets. 444} 445 446// Do executes Target.getTargets against the provided context. 447// 448// returns: 449// targetInfos - The list of targets. 450func (p *GetTargetsParams) Do(ctx context.Context) (targetInfos []*Info, err error) { 451 // execute 452 var res GetTargetsReturns 453 err = cdp.Execute(ctx, CommandGetTargets, nil, &res) 454 if err != nil { 455 return nil, err 456 } 457 458 return res.TargetInfos, nil 459} 460 461// SetAutoAttachParams controls whether to automatically attach to new 462// targets which are considered to be related to this one. When turned on, 463// attaches to all existing related targets as well. When turned off, 464// automatically detaches from all currently attached targets. 465type SetAutoAttachParams struct { 466 AutoAttach bool `json:"autoAttach"` // Whether to auto-attach to related targets. 467 WaitForDebuggerOnStart bool `json:"waitForDebuggerOnStart"` // Whether to pause new targets when attaching to them. Use Runtime.runIfWaitingForDebugger to run paused targets. 468 Flatten bool `json:"flatten,omitempty"` // Enables "flat" access to the session via specifying sessionId attribute in the commands. We plan to make this the default, deprecate non-flattened mode, and eventually retire it. See crbug.com/991325. 469 WindowOpen bool `json:"windowOpen,omitempty"` // Auto-attach to the targets created via window.open from current target. 470} 471 472// SetAutoAttach controls whether to automatically attach to new targets 473// which are considered to be related to this one. When turned on, attaches to 474// all existing related targets as well. When turned off, automatically detaches 475// from all currently attached targets. 476// 477// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-setAutoAttach 478// 479// parameters: 480// autoAttach - Whether to auto-attach to related targets. 481// waitForDebuggerOnStart - Whether to pause new targets when attaching to them. Use Runtime.runIfWaitingForDebugger to run paused targets. 482func SetAutoAttach(autoAttach bool, waitForDebuggerOnStart bool) *SetAutoAttachParams { 483 return &SetAutoAttachParams{ 484 AutoAttach: autoAttach, 485 WaitForDebuggerOnStart: waitForDebuggerOnStart, 486 } 487} 488 489// WithFlatten enables "flat" access to the session via specifying sessionId 490// attribute in the commands. We plan to make this the default, deprecate 491// non-flattened mode, and eventually retire it. See crbug.com/991325. 492func (p SetAutoAttachParams) WithFlatten(flatten bool) *SetAutoAttachParams { 493 p.Flatten = flatten 494 return &p 495} 496 497// WithWindowOpen auto-attach to the targets created via window.open from 498// current target. 499func (p SetAutoAttachParams) WithWindowOpen(windowOpen bool) *SetAutoAttachParams { 500 p.WindowOpen = windowOpen 501 return &p 502} 503 504// Do executes Target.setAutoAttach against the provided context. 505func (p *SetAutoAttachParams) Do(ctx context.Context) (err error) { 506 return cdp.Execute(ctx, CommandSetAutoAttach, p, nil) 507} 508 509// SetDiscoverTargetsParams controls whether to discover available targets 510// and notify via targetCreated/targetInfoChanged/targetDestroyed events. 511type SetDiscoverTargetsParams struct { 512 Discover bool `json:"discover"` // Whether to discover available targets. 513} 514 515// SetDiscoverTargets controls whether to discover available targets and 516// notify via targetCreated/targetInfoChanged/targetDestroyed events. 517// 518// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-setDiscoverTargets 519// 520// parameters: 521// discover - Whether to discover available targets. 522func SetDiscoverTargets(discover bool) *SetDiscoverTargetsParams { 523 return &SetDiscoverTargetsParams{ 524 Discover: discover, 525 } 526} 527 528// Do executes Target.setDiscoverTargets against the provided context. 529func (p *SetDiscoverTargetsParams) Do(ctx context.Context) (err error) { 530 return cdp.Execute(ctx, CommandSetDiscoverTargets, p, nil) 531} 532 533// SetRemoteLocationsParams enables target discovery for the specified 534// locations, when setDiscoverTargets was set to true. 535type SetRemoteLocationsParams struct { 536 Locations []*RemoteLocation `json:"locations"` // List of remote locations. 537} 538 539// SetRemoteLocations enables target discovery for the specified locations, 540// when setDiscoverTargets was set to true. 541// 542// See: https://chromedevtools.github.io/devtools-protocol/tot/Target#method-setRemoteLocations 543// 544// parameters: 545// locations - List of remote locations. 546func SetRemoteLocations(locations []*RemoteLocation) *SetRemoteLocationsParams { 547 return &SetRemoteLocationsParams{ 548 Locations: locations, 549 } 550} 551 552// Do executes Target.setRemoteLocations against the provided context. 553func (p *SetRemoteLocationsParams) Do(ctx context.Context) (err error) { 554 return cdp.Execute(ctx, CommandSetRemoteLocations, p, nil) 555} 556 557// Command names. 558const ( 559 CommandActivateTarget = "Target.activateTarget" 560 CommandAttachToTarget = "Target.attachToTarget" 561 CommandAttachToBrowserTarget = "Target.attachToBrowserTarget" 562 CommandCloseTarget = "Target.closeTarget" 563 CommandExposeDevToolsProtocol = "Target.exposeDevToolsProtocol" 564 CommandCreateBrowserContext = "Target.createBrowserContext" 565 CommandGetBrowserContexts = "Target.getBrowserContexts" 566 CommandCreateTarget = "Target.createTarget" 567 CommandDetachFromTarget = "Target.detachFromTarget" 568 CommandDisposeBrowserContext = "Target.disposeBrowserContext" 569 CommandGetTargetInfo = "Target.getTargetInfo" 570 CommandGetTargets = "Target.getTargets" 571 CommandSetAutoAttach = "Target.setAutoAttach" 572 CommandSetDiscoverTargets = "Target.setDiscoverTargets" 573 CommandSetRemoteLocations = "Target.setRemoteLocations" 574) 575