target.go 25 KB

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