target.go 28 KB

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