dom.go 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  1. // Package dom provides the Chrome DevTools Protocol
  2. // commands, types, and events for the DOM domain.
  3. //
  4. // This domain exposes DOM read/write operations. Each DOM Node is
  5. // represented with its mirror object that has an id. This id can be used to get
  6. // additional information on the Node, resolve it into the JavaScript object
  7. // wrapper, etc. It is important that client receives DOM events only for the
  8. // nodes that are known to the client. Backend keeps track of the nodes that
  9. // were sent to the client and never sends the same node twice. It is client's
  10. // responsibility to collect information about the nodes that were sent to the
  11. // client. Note that iframe owner elements will return corresponding document
  12. // elements as their child nodes.
  13. //
  14. // Generated by the cdproto-gen command.
  15. package dom
  16. // Code generated by cdproto-gen. DO NOT EDIT.
  17. import (
  18. "context"
  19. "github.com/chromedp/cdproto/cdp"
  20. "github.com/chromedp/cdproto/runtime"
  21. )
  22. // CollectClassNamesFromSubtreeParams collects class names for the node with
  23. // given id and all of it's child nodes.
  24. type CollectClassNamesFromSubtreeParams struct {
  25. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to collect class names.
  26. }
  27. // CollectClassNamesFromSubtree collects class names for the node with given
  28. // id and all of it's child nodes.
  29. //
  30. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-collectClassNamesFromSubtree
  31. //
  32. // parameters:
  33. //
  34. // nodeID - Id of the node to collect class names.
  35. func CollectClassNamesFromSubtree(nodeID cdp.NodeID) *CollectClassNamesFromSubtreeParams {
  36. return &CollectClassNamesFromSubtreeParams{
  37. NodeID: nodeID,
  38. }
  39. }
  40. // CollectClassNamesFromSubtreeReturns return values.
  41. type CollectClassNamesFromSubtreeReturns struct {
  42. ClassNames []string `json:"classNames,omitempty"` // Class name list.
  43. }
  44. // Do executes DOM.collectClassNamesFromSubtree against the provided context.
  45. //
  46. // returns:
  47. //
  48. // classNames - Class name list.
  49. func (p *CollectClassNamesFromSubtreeParams) Do(ctx context.Context) (classNames []string, err error) {
  50. // execute
  51. var res CollectClassNamesFromSubtreeReturns
  52. err = cdp.Execute(ctx, CommandCollectClassNamesFromSubtree, p, &res)
  53. if err != nil {
  54. return nil, err
  55. }
  56. return res.ClassNames, nil
  57. }
  58. // CopyToParams creates a deep copy of the specified node and places it into
  59. // the target container before the given anchor.
  60. type CopyToParams struct {
  61. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to copy.
  62. TargetNodeID cdp.NodeID `json:"targetNodeId"` // Id of the element to drop the copy into.
  63. InsertBeforeNodeID cdp.NodeID `json:"insertBeforeNodeId,omitempty"` // Drop the copy before this node (if absent, the copy becomes the last child of targetNodeId).
  64. }
  65. // CopyTo creates a deep copy of the specified node and places it into the
  66. // target container before the given anchor.
  67. //
  68. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-copyTo
  69. //
  70. // parameters:
  71. //
  72. // nodeID - Id of the node to copy.
  73. // targetNodeID - Id of the element to drop the copy into.
  74. func CopyTo(nodeID cdp.NodeID, targetNodeID cdp.NodeID) *CopyToParams {
  75. return &CopyToParams{
  76. NodeID: nodeID,
  77. TargetNodeID: targetNodeID,
  78. }
  79. }
  80. // WithInsertBeforeNodeID drop the copy before this node (if absent, the copy
  81. // becomes the last child of targetNodeId).
  82. func (p CopyToParams) WithInsertBeforeNodeID(insertBeforeNodeID cdp.NodeID) *CopyToParams {
  83. p.InsertBeforeNodeID = insertBeforeNodeID
  84. return &p
  85. }
  86. // CopyToReturns return values.
  87. type CopyToReturns struct {
  88. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node clone.
  89. }
  90. // Do executes DOM.copyTo against the provided context.
  91. //
  92. // returns:
  93. //
  94. // nodeID - Id of the node clone.
  95. func (p *CopyToParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
  96. // execute
  97. var res CopyToReturns
  98. err = cdp.Execute(ctx, CommandCopyTo, p, &res)
  99. if err != nil {
  100. return 0, err
  101. }
  102. return res.NodeID, nil
  103. }
  104. // DescribeNodeParams describes node given its id, does not require domain to
  105. // be enabled. Does not start tracking any objects, can be used for automation.
  106. type DescribeNodeParams struct {
  107. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
  108. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
  109. ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
  110. Depth int64 `json:"depth,omitempty"` // The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
  111. Pierce bool `json:"pierce,omitempty"` // Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
  112. }
  113. // DescribeNode describes node given its id, does not require domain to be
  114. // enabled. Does not start tracking any objects, can be used for automation.
  115. //
  116. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-describeNode
  117. //
  118. // parameters:
  119. func DescribeNode() *DescribeNodeParams {
  120. return &DescribeNodeParams{}
  121. }
  122. // WithNodeID identifier of the node.
  123. func (p DescribeNodeParams) WithNodeID(nodeID cdp.NodeID) *DescribeNodeParams {
  124. p.NodeID = nodeID
  125. return &p
  126. }
  127. // WithBackendNodeID identifier of the backend node.
  128. func (p DescribeNodeParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *DescribeNodeParams {
  129. p.BackendNodeID = backendNodeID
  130. return &p
  131. }
  132. // WithObjectID JavaScript object id of the node wrapper.
  133. func (p DescribeNodeParams) WithObjectID(objectID runtime.RemoteObjectID) *DescribeNodeParams {
  134. p.ObjectID = objectID
  135. return &p
  136. }
  137. // WithDepth the maximum depth at which children should be retrieved,
  138. // defaults to 1. Use -1 for the entire subtree or provide an integer larger
  139. // than 0.
  140. func (p DescribeNodeParams) WithDepth(depth int64) *DescribeNodeParams {
  141. p.Depth = depth
  142. return &p
  143. }
  144. // WithPierce whether or not iframes and shadow roots should be traversed
  145. // when returning the subtree (default is false).
  146. func (p DescribeNodeParams) WithPierce(pierce bool) *DescribeNodeParams {
  147. p.Pierce = pierce
  148. return &p
  149. }
  150. // DescribeNodeReturns return values.
  151. type DescribeNodeReturns struct {
  152. Node *cdp.Node `json:"node,omitempty"` // Node description.
  153. }
  154. // Do executes DOM.describeNode against the provided context.
  155. //
  156. // returns:
  157. //
  158. // node - Node description.
  159. func (p *DescribeNodeParams) Do(ctx context.Context) (node *cdp.Node, err error) {
  160. // execute
  161. var res DescribeNodeReturns
  162. err = cdp.Execute(ctx, CommandDescribeNode, p, &res)
  163. if err != nil {
  164. return nil, err
  165. }
  166. return res.Node, nil
  167. }
  168. // ScrollIntoViewIfNeededParams scrolls the specified rect of the given node
  169. // into view if not already visible. Note: exactly one between nodeId,
  170. // backendNodeId and objectId should be passed to identify the node.
  171. type ScrollIntoViewIfNeededParams struct {
  172. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
  173. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
  174. ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
  175. Rect *Rect `json:"rect,omitempty"` // The rect to be scrolled into view, relative to the node's border box, in CSS pixels. When omitted, center of the node will be used, similar to Element.scrollIntoView.
  176. }
  177. // ScrollIntoViewIfNeeded scrolls the specified rect of the given node into
  178. // view if not already visible. Note: exactly one between nodeId, backendNodeId
  179. // and objectId should be passed to identify the node.
  180. //
  181. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-scrollIntoViewIfNeeded
  182. //
  183. // parameters:
  184. func ScrollIntoViewIfNeeded() *ScrollIntoViewIfNeededParams {
  185. return &ScrollIntoViewIfNeededParams{}
  186. }
  187. // WithNodeID identifier of the node.
  188. func (p ScrollIntoViewIfNeededParams) WithNodeID(nodeID cdp.NodeID) *ScrollIntoViewIfNeededParams {
  189. p.NodeID = nodeID
  190. return &p
  191. }
  192. // WithBackendNodeID identifier of the backend node.
  193. func (p ScrollIntoViewIfNeededParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *ScrollIntoViewIfNeededParams {
  194. p.BackendNodeID = backendNodeID
  195. return &p
  196. }
  197. // WithObjectID JavaScript object id of the node wrapper.
  198. func (p ScrollIntoViewIfNeededParams) WithObjectID(objectID runtime.RemoteObjectID) *ScrollIntoViewIfNeededParams {
  199. p.ObjectID = objectID
  200. return &p
  201. }
  202. // WithRect the rect to be scrolled into view, relative to the node's border
  203. // box, in CSS pixels. When omitted, center of the node will be used, similar to
  204. // Element.scrollIntoView.
  205. func (p ScrollIntoViewIfNeededParams) WithRect(rect *Rect) *ScrollIntoViewIfNeededParams {
  206. p.Rect = rect
  207. return &p
  208. }
  209. // Do executes DOM.scrollIntoViewIfNeeded against the provided context.
  210. func (p *ScrollIntoViewIfNeededParams) Do(ctx context.Context) (err error) {
  211. return cdp.Execute(ctx, CommandScrollIntoViewIfNeeded, p, nil)
  212. }
  213. // DisableParams disables DOM agent for the given page.
  214. type DisableParams struct{}
  215. // Disable disables DOM agent for the given page.
  216. //
  217. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-disable
  218. func Disable() *DisableParams {
  219. return &DisableParams{}
  220. }
  221. // Do executes DOM.disable against the provided context.
  222. func (p *DisableParams) Do(ctx context.Context) (err error) {
  223. return cdp.Execute(ctx, CommandDisable, nil, nil)
  224. }
  225. // DiscardSearchResultsParams discards search results from the session with
  226. // the given id. getSearchResults should no longer be called for that search.
  227. type DiscardSearchResultsParams struct {
  228. SearchID string `json:"searchId"` // Unique search session identifier.
  229. }
  230. // DiscardSearchResults discards search results from the session with the
  231. // given id. getSearchResults should no longer be called for that search.
  232. //
  233. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-discardSearchResults
  234. //
  235. // parameters:
  236. //
  237. // searchID - Unique search session identifier.
  238. func DiscardSearchResults(searchID string) *DiscardSearchResultsParams {
  239. return &DiscardSearchResultsParams{
  240. SearchID: searchID,
  241. }
  242. }
  243. // Do executes DOM.discardSearchResults against the provided context.
  244. func (p *DiscardSearchResultsParams) Do(ctx context.Context) (err error) {
  245. return cdp.Execute(ctx, CommandDiscardSearchResults, p, nil)
  246. }
  247. // EnableParams enables DOM agent for the given page.
  248. type EnableParams struct {
  249. IncludeWhitespace EnableIncludeWhitespace `json:"includeWhitespace,omitempty"` // Whether to include whitespaces in the children array of returned Nodes.
  250. }
  251. // Enable enables DOM agent for the given page.
  252. //
  253. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-enable
  254. //
  255. // parameters:
  256. func Enable() *EnableParams {
  257. return &EnableParams{}
  258. }
  259. // WithIncludeWhitespace whether to include whitespaces in the children array
  260. // of returned Nodes.
  261. func (p EnableParams) WithIncludeWhitespace(includeWhitespace EnableIncludeWhitespace) *EnableParams {
  262. p.IncludeWhitespace = includeWhitespace
  263. return &p
  264. }
  265. // Do executes DOM.enable against the provided context.
  266. func (p *EnableParams) Do(ctx context.Context) (err error) {
  267. return cdp.Execute(ctx, CommandEnable, p, nil)
  268. }
  269. // FocusParams focuses the given element.
  270. type FocusParams struct {
  271. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
  272. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
  273. ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
  274. }
  275. // Focus focuses the given element.
  276. //
  277. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-focus
  278. //
  279. // parameters:
  280. func Focus() *FocusParams {
  281. return &FocusParams{}
  282. }
  283. // WithNodeID identifier of the node.
  284. func (p FocusParams) WithNodeID(nodeID cdp.NodeID) *FocusParams {
  285. p.NodeID = nodeID
  286. return &p
  287. }
  288. // WithBackendNodeID identifier of the backend node.
  289. func (p FocusParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *FocusParams {
  290. p.BackendNodeID = backendNodeID
  291. return &p
  292. }
  293. // WithObjectID JavaScript object id of the node wrapper.
  294. func (p FocusParams) WithObjectID(objectID runtime.RemoteObjectID) *FocusParams {
  295. p.ObjectID = objectID
  296. return &p
  297. }
  298. // Do executes DOM.focus against the provided context.
  299. func (p *FocusParams) Do(ctx context.Context) (err error) {
  300. return cdp.Execute(ctx, CommandFocus, p, nil)
  301. }
  302. // GetAttributesParams returns attributes for the specified node.
  303. type GetAttributesParams struct {
  304. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to retrieve attributes for.
  305. }
  306. // GetAttributes returns attributes for the specified node.
  307. //
  308. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getAttributes
  309. //
  310. // parameters:
  311. //
  312. // nodeID - Id of the node to retrieve attributes for.
  313. func GetAttributes(nodeID cdp.NodeID) *GetAttributesParams {
  314. return &GetAttributesParams{
  315. NodeID: nodeID,
  316. }
  317. }
  318. // GetAttributesReturns return values.
  319. type GetAttributesReturns struct {
  320. Attributes []string `json:"attributes,omitempty"` // An interleaved array of node attribute names and values.
  321. }
  322. // Do executes DOM.getAttributes against the provided context.
  323. //
  324. // returns:
  325. //
  326. // attributes - An interleaved array of node attribute names and values.
  327. func (p *GetAttributesParams) Do(ctx context.Context) (attributes []string, err error) {
  328. // execute
  329. var res GetAttributesReturns
  330. err = cdp.Execute(ctx, CommandGetAttributes, p, &res)
  331. if err != nil {
  332. return nil, err
  333. }
  334. return res.Attributes, nil
  335. }
  336. // GetBoxModelParams returns boxes for the given node.
  337. type GetBoxModelParams struct {
  338. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
  339. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
  340. ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
  341. }
  342. // GetBoxModel returns boxes for the given node.
  343. //
  344. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getBoxModel
  345. //
  346. // parameters:
  347. func GetBoxModel() *GetBoxModelParams {
  348. return &GetBoxModelParams{}
  349. }
  350. // WithNodeID identifier of the node.
  351. func (p GetBoxModelParams) WithNodeID(nodeID cdp.NodeID) *GetBoxModelParams {
  352. p.NodeID = nodeID
  353. return &p
  354. }
  355. // WithBackendNodeID identifier of the backend node.
  356. func (p GetBoxModelParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *GetBoxModelParams {
  357. p.BackendNodeID = backendNodeID
  358. return &p
  359. }
  360. // WithObjectID JavaScript object id of the node wrapper.
  361. func (p GetBoxModelParams) WithObjectID(objectID runtime.RemoteObjectID) *GetBoxModelParams {
  362. p.ObjectID = objectID
  363. return &p
  364. }
  365. // GetBoxModelReturns return values.
  366. type GetBoxModelReturns struct {
  367. Model *BoxModel `json:"model,omitempty"` // Box model for the node.
  368. }
  369. // Do executes DOM.getBoxModel against the provided context.
  370. //
  371. // returns:
  372. //
  373. // model - Box model for the node.
  374. func (p *GetBoxModelParams) Do(ctx context.Context) (model *BoxModel, err error) {
  375. // execute
  376. var res GetBoxModelReturns
  377. err = cdp.Execute(ctx, CommandGetBoxModel, p, &res)
  378. if err != nil {
  379. return nil, err
  380. }
  381. return res.Model, nil
  382. }
  383. // GetContentQuadsParams returns quads that describe node position on the
  384. // page. This method might return multiple quads for inline nodes.
  385. type GetContentQuadsParams struct {
  386. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
  387. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
  388. ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
  389. }
  390. // GetContentQuads returns quads that describe node position on the page.
  391. // This method might return multiple quads for inline nodes.
  392. //
  393. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getContentQuads
  394. //
  395. // parameters:
  396. func GetContentQuads() *GetContentQuadsParams {
  397. return &GetContentQuadsParams{}
  398. }
  399. // WithNodeID identifier of the node.
  400. func (p GetContentQuadsParams) WithNodeID(nodeID cdp.NodeID) *GetContentQuadsParams {
  401. p.NodeID = nodeID
  402. return &p
  403. }
  404. // WithBackendNodeID identifier of the backend node.
  405. func (p GetContentQuadsParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *GetContentQuadsParams {
  406. p.BackendNodeID = backendNodeID
  407. return &p
  408. }
  409. // WithObjectID JavaScript object id of the node wrapper.
  410. func (p GetContentQuadsParams) WithObjectID(objectID runtime.RemoteObjectID) *GetContentQuadsParams {
  411. p.ObjectID = objectID
  412. return &p
  413. }
  414. // GetContentQuadsReturns return values.
  415. type GetContentQuadsReturns struct {
  416. Quads []Quad `json:"quads,omitempty"` // Quads that describe node layout relative to viewport.
  417. }
  418. // Do executes DOM.getContentQuads against the provided context.
  419. //
  420. // returns:
  421. //
  422. // quads - Quads that describe node layout relative to viewport.
  423. func (p *GetContentQuadsParams) Do(ctx context.Context) (quads []Quad, err error) {
  424. // execute
  425. var res GetContentQuadsReturns
  426. err = cdp.Execute(ctx, CommandGetContentQuads, p, &res)
  427. if err != nil {
  428. return nil, err
  429. }
  430. return res.Quads, nil
  431. }
  432. // GetDocumentParams returns the root DOM node (and optionally the subtree)
  433. // to the caller. Implicitly enables the DOM domain events for the current
  434. // target.
  435. type GetDocumentParams struct {
  436. Depth int64 `json:"depth,omitempty"` // The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
  437. Pierce bool `json:"pierce,omitempty"` // Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
  438. }
  439. // GetDocument returns the root DOM node (and optionally the subtree) to the
  440. // caller. Implicitly enables the DOM domain events for the current target.
  441. //
  442. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getDocument
  443. //
  444. // parameters:
  445. func GetDocument() *GetDocumentParams {
  446. return &GetDocumentParams{}
  447. }
  448. // WithDepth the maximum depth at which children should be retrieved,
  449. // defaults to 1. Use -1 for the entire subtree or provide an integer larger
  450. // than 0.
  451. func (p GetDocumentParams) WithDepth(depth int64) *GetDocumentParams {
  452. p.Depth = depth
  453. return &p
  454. }
  455. // WithPierce whether or not iframes and shadow roots should be traversed
  456. // when returning the subtree (default is false).
  457. func (p GetDocumentParams) WithPierce(pierce bool) *GetDocumentParams {
  458. p.Pierce = pierce
  459. return &p
  460. }
  461. // GetDocumentReturns return values.
  462. type GetDocumentReturns struct {
  463. Root *cdp.Node `json:"root,omitempty"` // Resulting node.
  464. }
  465. // Do executes DOM.getDocument against the provided context.
  466. //
  467. // returns:
  468. //
  469. // root - Resulting node.
  470. func (p *GetDocumentParams) Do(ctx context.Context) (root *cdp.Node, err error) {
  471. // execute
  472. var res GetDocumentReturns
  473. err = cdp.Execute(ctx, CommandGetDocument, p, &res)
  474. if err != nil {
  475. return nil, err
  476. }
  477. return res.Root, nil
  478. }
  479. // GetNodesForSubtreeByStyleParams finds nodes with a given computed style in
  480. // a subtree.
  481. type GetNodesForSubtreeByStyleParams struct {
  482. NodeID cdp.NodeID `json:"nodeId"` // Node ID pointing to the root of a subtree.
  483. ComputedStyles []*CSSComputedStyleProperty `json:"computedStyles"` // The style to filter nodes by (includes nodes if any of properties matches).
  484. Pierce bool `json:"pierce,omitempty"` // Whether or not iframes and shadow roots in the same target should be traversed when returning the results (default is false).
  485. }
  486. // GetNodesForSubtreeByStyle finds nodes with a given computed style in a
  487. // subtree.
  488. //
  489. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getNodesForSubtreeByStyle
  490. //
  491. // parameters:
  492. //
  493. // nodeID - Node ID pointing to the root of a subtree.
  494. // computedStyles - The style to filter nodes by (includes nodes if any of properties matches).
  495. func GetNodesForSubtreeByStyle(nodeID cdp.NodeID, computedStyles []*CSSComputedStyleProperty) *GetNodesForSubtreeByStyleParams {
  496. return &GetNodesForSubtreeByStyleParams{
  497. NodeID: nodeID,
  498. ComputedStyles: computedStyles,
  499. }
  500. }
  501. // WithPierce whether or not iframes and shadow roots in the same target
  502. // should be traversed when returning the results (default is false).
  503. func (p GetNodesForSubtreeByStyleParams) WithPierce(pierce bool) *GetNodesForSubtreeByStyleParams {
  504. p.Pierce = pierce
  505. return &p
  506. }
  507. // GetNodesForSubtreeByStyleReturns return values.
  508. type GetNodesForSubtreeByStyleReturns struct {
  509. NodeIDs []cdp.NodeID `json:"nodeIds,omitempty"` // Resulting nodes.
  510. }
  511. // Do executes DOM.getNodesForSubtreeByStyle against the provided context.
  512. //
  513. // returns:
  514. //
  515. // nodeIDs - Resulting nodes.
  516. func (p *GetNodesForSubtreeByStyleParams) Do(ctx context.Context) (nodeIDs []cdp.NodeID, err error) {
  517. // execute
  518. var res GetNodesForSubtreeByStyleReturns
  519. err = cdp.Execute(ctx, CommandGetNodesForSubtreeByStyle, p, &res)
  520. if err != nil {
  521. return nil, err
  522. }
  523. return res.NodeIDs, nil
  524. }
  525. // GetNodeForLocationParams returns node id at given location. Depending on
  526. // whether DOM domain is enabled, nodeId is either returned or not.
  527. type GetNodeForLocationParams struct {
  528. X int64 `json:"x"` // X coordinate.
  529. Y int64 `json:"y"` // Y coordinate.
  530. IncludeUserAgentShadowDOM bool `json:"includeUserAgentShadowDOM,omitempty"` // False to skip to the nearest non-UA shadow root ancestor (default: false).
  531. IgnorePointerEventsNone bool `json:"ignorePointerEventsNone,omitempty"` // Whether to ignore pointer-events: none on elements and hit test them.
  532. }
  533. // GetNodeForLocation returns node id at given location. Depending on whether
  534. // DOM domain is enabled, nodeId is either returned or not.
  535. //
  536. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getNodeForLocation
  537. //
  538. // parameters:
  539. //
  540. // x - X coordinate.
  541. // y - Y coordinate.
  542. func GetNodeForLocation(x int64, y int64) *GetNodeForLocationParams {
  543. return &GetNodeForLocationParams{
  544. X: x,
  545. Y: y,
  546. }
  547. }
  548. // WithIncludeUserAgentShadowDOM false to skip to the nearest non-UA shadow
  549. // root ancestor (default: false).
  550. func (p GetNodeForLocationParams) WithIncludeUserAgentShadowDOM(includeUserAgentShadowDOM bool) *GetNodeForLocationParams {
  551. p.IncludeUserAgentShadowDOM = includeUserAgentShadowDOM
  552. return &p
  553. }
  554. // WithIgnorePointerEventsNone whether to ignore pointer-events: none on
  555. // elements and hit test them.
  556. func (p GetNodeForLocationParams) WithIgnorePointerEventsNone(ignorePointerEventsNone bool) *GetNodeForLocationParams {
  557. p.IgnorePointerEventsNone = ignorePointerEventsNone
  558. return &p
  559. }
  560. // GetNodeForLocationReturns return values.
  561. type GetNodeForLocationReturns struct {
  562. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Resulting node.
  563. FrameID cdp.FrameID `json:"frameId,omitempty"` // Frame this node belongs to.
  564. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node at given coordinates, only when enabled and requested document.
  565. }
  566. // Do executes DOM.getNodeForLocation against the provided context.
  567. //
  568. // returns:
  569. //
  570. // backendNodeID - Resulting node.
  571. // frameID - Frame this node belongs to.
  572. // nodeID - Id of the node at given coordinates, only when enabled and requested document.
  573. func (p *GetNodeForLocationParams) Do(ctx context.Context) (backendNodeID cdp.BackendNodeID, frameID cdp.FrameID, nodeID cdp.NodeID, err error) {
  574. // execute
  575. var res GetNodeForLocationReturns
  576. err = cdp.Execute(ctx, CommandGetNodeForLocation, p, &res)
  577. if err != nil {
  578. return 0, "", 0, err
  579. }
  580. return res.BackendNodeID, res.FrameID, res.NodeID, nil
  581. }
  582. // GetOuterHTMLParams returns node's HTML markup.
  583. type GetOuterHTMLParams struct {
  584. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
  585. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
  586. ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
  587. }
  588. // GetOuterHTML returns node's HTML markup.
  589. //
  590. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getOuterHTML
  591. //
  592. // parameters:
  593. func GetOuterHTML() *GetOuterHTMLParams {
  594. return &GetOuterHTMLParams{}
  595. }
  596. // WithNodeID identifier of the node.
  597. func (p GetOuterHTMLParams) WithNodeID(nodeID cdp.NodeID) *GetOuterHTMLParams {
  598. p.NodeID = nodeID
  599. return &p
  600. }
  601. // WithBackendNodeID identifier of the backend node.
  602. func (p GetOuterHTMLParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *GetOuterHTMLParams {
  603. p.BackendNodeID = backendNodeID
  604. return &p
  605. }
  606. // WithObjectID JavaScript object id of the node wrapper.
  607. func (p GetOuterHTMLParams) WithObjectID(objectID runtime.RemoteObjectID) *GetOuterHTMLParams {
  608. p.ObjectID = objectID
  609. return &p
  610. }
  611. // GetOuterHTMLReturns return values.
  612. type GetOuterHTMLReturns struct {
  613. OuterHTML string `json:"outerHTML,omitempty"` // Outer HTML markup.
  614. }
  615. // Do executes DOM.getOuterHTML against the provided context.
  616. //
  617. // returns:
  618. //
  619. // outerHTML - Outer HTML markup.
  620. func (p *GetOuterHTMLParams) Do(ctx context.Context) (outerHTML string, err error) {
  621. // execute
  622. var res GetOuterHTMLReturns
  623. err = cdp.Execute(ctx, CommandGetOuterHTML, p, &res)
  624. if err != nil {
  625. return "", err
  626. }
  627. return res.OuterHTML, nil
  628. }
  629. // GetRelayoutBoundaryParams returns the id of the nearest ancestor that is a
  630. // relayout boundary.
  631. type GetRelayoutBoundaryParams struct {
  632. NodeID cdp.NodeID `json:"nodeId"` // Id of the node.
  633. }
  634. // GetRelayoutBoundary returns the id of the nearest ancestor that is a
  635. // relayout boundary.
  636. //
  637. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getRelayoutBoundary
  638. //
  639. // parameters:
  640. //
  641. // nodeID - Id of the node.
  642. func GetRelayoutBoundary(nodeID cdp.NodeID) *GetRelayoutBoundaryParams {
  643. return &GetRelayoutBoundaryParams{
  644. NodeID: nodeID,
  645. }
  646. }
  647. // GetRelayoutBoundaryReturns return values.
  648. type GetRelayoutBoundaryReturns struct {
  649. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Relayout boundary node id for the given node.
  650. }
  651. // Do executes DOM.getRelayoutBoundary against the provided context.
  652. //
  653. // returns:
  654. //
  655. // nodeID - Relayout boundary node id for the given node.
  656. func (p *GetRelayoutBoundaryParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
  657. // execute
  658. var res GetRelayoutBoundaryReturns
  659. err = cdp.Execute(ctx, CommandGetRelayoutBoundary, p, &res)
  660. if err != nil {
  661. return 0, err
  662. }
  663. return res.NodeID, nil
  664. }
  665. // GetSearchResultsParams returns search results from given fromIndex to
  666. // given toIndex from the search with the given identifier.
  667. type GetSearchResultsParams struct {
  668. SearchID string `json:"searchId"` // Unique search session identifier.
  669. FromIndex int64 `json:"fromIndex"` // Start index of the search result to be returned.
  670. ToIndex int64 `json:"toIndex"` // End index of the search result to be returned.
  671. }
  672. // GetSearchResults returns search results from given fromIndex to given
  673. // toIndex from the search with the given identifier.
  674. //
  675. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getSearchResults
  676. //
  677. // parameters:
  678. //
  679. // searchID - Unique search session identifier.
  680. // fromIndex - Start index of the search result to be returned.
  681. // toIndex - End index of the search result to be returned.
  682. func GetSearchResults(searchID string, fromIndex int64, toIndex int64) *GetSearchResultsParams {
  683. return &GetSearchResultsParams{
  684. SearchID: searchID,
  685. FromIndex: fromIndex,
  686. ToIndex: toIndex,
  687. }
  688. }
  689. // GetSearchResultsReturns return values.
  690. type GetSearchResultsReturns struct {
  691. NodeIDs []cdp.NodeID `json:"nodeIds,omitempty"` // Ids of the search result nodes.
  692. }
  693. // Do executes DOM.getSearchResults against the provided context.
  694. //
  695. // returns:
  696. //
  697. // nodeIDs - Ids of the search result nodes.
  698. func (p *GetSearchResultsParams) Do(ctx context.Context) (nodeIDs []cdp.NodeID, err error) {
  699. // execute
  700. var res GetSearchResultsReturns
  701. err = cdp.Execute(ctx, CommandGetSearchResults, p, &res)
  702. if err != nil {
  703. return nil, err
  704. }
  705. return res.NodeIDs, nil
  706. }
  707. // MarkUndoableStateParams marks last undoable state.
  708. type MarkUndoableStateParams struct{}
  709. // MarkUndoableState marks last undoable state.
  710. //
  711. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-markUndoableState
  712. func MarkUndoableState() *MarkUndoableStateParams {
  713. return &MarkUndoableStateParams{}
  714. }
  715. // Do executes DOM.markUndoableState against the provided context.
  716. func (p *MarkUndoableStateParams) Do(ctx context.Context) (err error) {
  717. return cdp.Execute(ctx, CommandMarkUndoableState, nil, nil)
  718. }
  719. // MoveToParams moves node into the new container, places it before the given
  720. // anchor.
  721. type MoveToParams struct {
  722. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to move.
  723. TargetNodeID cdp.NodeID `json:"targetNodeId"` // Id of the element to drop the moved node into.
  724. InsertBeforeNodeID cdp.NodeID `json:"insertBeforeNodeId,omitempty"` // Drop node before this one (if absent, the moved node becomes the last child of targetNodeId).
  725. }
  726. // MoveTo moves node into the new container, places it before the given
  727. // anchor.
  728. //
  729. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-moveTo
  730. //
  731. // parameters:
  732. //
  733. // nodeID - Id of the node to move.
  734. // targetNodeID - Id of the element to drop the moved node into.
  735. func MoveTo(nodeID cdp.NodeID, targetNodeID cdp.NodeID) *MoveToParams {
  736. return &MoveToParams{
  737. NodeID: nodeID,
  738. TargetNodeID: targetNodeID,
  739. }
  740. }
  741. // WithInsertBeforeNodeID drop node before this one (if absent, the moved
  742. // node becomes the last child of targetNodeId).
  743. func (p MoveToParams) WithInsertBeforeNodeID(insertBeforeNodeID cdp.NodeID) *MoveToParams {
  744. p.InsertBeforeNodeID = insertBeforeNodeID
  745. return &p
  746. }
  747. // MoveToReturns return values.
  748. type MoveToReturns struct {
  749. NodeID cdp.NodeID `json:"nodeId,omitempty"` // New id of the moved node.
  750. }
  751. // Do executes DOM.moveTo against the provided context.
  752. //
  753. // returns:
  754. //
  755. // nodeID - New id of the moved node.
  756. func (p *MoveToParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
  757. // execute
  758. var res MoveToReturns
  759. err = cdp.Execute(ctx, CommandMoveTo, p, &res)
  760. if err != nil {
  761. return 0, err
  762. }
  763. return res.NodeID, nil
  764. }
  765. // PerformSearchParams searches for a given string in the DOM tree. Use
  766. // getSearchResults to access search results or cancelSearch to end this search
  767. // session.
  768. type PerformSearchParams struct {
  769. Query string `json:"query"` // Plain text or query selector or XPath search query.
  770. IncludeUserAgentShadowDOM bool `json:"includeUserAgentShadowDOM,omitempty"` // True to search in user agent shadow DOM.
  771. }
  772. // PerformSearch searches for a given string in the DOM tree. Use
  773. // getSearchResults to access search results or cancelSearch to end this search
  774. // session.
  775. //
  776. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-performSearch
  777. //
  778. // parameters:
  779. //
  780. // query - Plain text or query selector or XPath search query.
  781. func PerformSearch(query string) *PerformSearchParams {
  782. return &PerformSearchParams{
  783. Query: query,
  784. }
  785. }
  786. // WithIncludeUserAgentShadowDOM true to search in user agent shadow DOM.
  787. func (p PerformSearchParams) WithIncludeUserAgentShadowDOM(includeUserAgentShadowDOM bool) *PerformSearchParams {
  788. p.IncludeUserAgentShadowDOM = includeUserAgentShadowDOM
  789. return &p
  790. }
  791. // PerformSearchReturns return values.
  792. type PerformSearchReturns struct {
  793. SearchID string `json:"searchId,omitempty"` // Unique search session identifier.
  794. ResultCount int64 `json:"resultCount,omitempty"` // Number of search results.
  795. }
  796. // Do executes DOM.performSearch against the provided context.
  797. //
  798. // returns:
  799. //
  800. // searchID - Unique search session identifier.
  801. // resultCount - Number of search results.
  802. func (p *PerformSearchParams) Do(ctx context.Context) (searchID string, resultCount int64, err error) {
  803. // execute
  804. var res PerformSearchReturns
  805. err = cdp.Execute(ctx, CommandPerformSearch, p, &res)
  806. if err != nil {
  807. return "", 0, err
  808. }
  809. return res.SearchID, res.ResultCount, nil
  810. }
  811. // PushNodeByPathToFrontendParams requests that the node is sent to the
  812. // caller given its path. // FIXME, use XPath.
  813. type PushNodeByPathToFrontendParams struct {
  814. Path string `json:"path"` // Path to node in the proprietary format.
  815. }
  816. // PushNodeByPathToFrontend requests that the node is sent to the caller
  817. // given its path. // FIXME, use XPath.
  818. //
  819. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-pushNodeByPathToFrontend
  820. //
  821. // parameters:
  822. //
  823. // path - Path to node in the proprietary format.
  824. func PushNodeByPathToFrontend(path string) *PushNodeByPathToFrontendParams {
  825. return &PushNodeByPathToFrontendParams{
  826. Path: path,
  827. }
  828. }
  829. // PushNodeByPathToFrontendReturns return values.
  830. type PushNodeByPathToFrontendReturns struct {
  831. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node for given path.
  832. }
  833. // Do executes DOM.pushNodeByPathToFrontend against the provided context.
  834. //
  835. // returns:
  836. //
  837. // nodeID - Id of the node for given path.
  838. func (p *PushNodeByPathToFrontendParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
  839. // execute
  840. var res PushNodeByPathToFrontendReturns
  841. err = cdp.Execute(ctx, CommandPushNodeByPathToFrontend, p, &res)
  842. if err != nil {
  843. return 0, err
  844. }
  845. return res.NodeID, nil
  846. }
  847. // PushNodesByBackendIDsToFrontendParams requests that a batch of nodes is
  848. // sent to the caller given their backend node ids.
  849. type PushNodesByBackendIDsToFrontendParams struct {
  850. BackendNodeIDs []cdp.BackendNodeID `json:"backendNodeIds"` // The array of backend node ids.
  851. }
  852. // PushNodesByBackendIDsToFrontend requests that a batch of nodes is sent to
  853. // the caller given their backend node ids.
  854. //
  855. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-pushNodesByBackendIdsToFrontend
  856. //
  857. // parameters:
  858. //
  859. // backendNodeIDs - The array of backend node ids.
  860. func PushNodesByBackendIDsToFrontend(backendNodeIDs []cdp.BackendNodeID) *PushNodesByBackendIDsToFrontendParams {
  861. return &PushNodesByBackendIDsToFrontendParams{
  862. BackendNodeIDs: backendNodeIDs,
  863. }
  864. }
  865. // PushNodesByBackendIDsToFrontendReturns return values.
  866. type PushNodesByBackendIDsToFrontendReturns struct {
  867. NodeIDs []cdp.NodeID `json:"nodeIds,omitempty"` // The array of ids of pushed nodes that correspond to the backend ids specified in backendNodeIds.
  868. }
  869. // Do executes DOM.pushNodesByBackendIdsToFrontend against the provided context.
  870. //
  871. // returns:
  872. //
  873. // nodeIDs - The array of ids of pushed nodes that correspond to the backend ids specified in backendNodeIds.
  874. func (p *PushNodesByBackendIDsToFrontendParams) Do(ctx context.Context) (nodeIDs []cdp.NodeID, err error) {
  875. // execute
  876. var res PushNodesByBackendIDsToFrontendReturns
  877. err = cdp.Execute(ctx, CommandPushNodesByBackendIDsToFrontend, p, &res)
  878. if err != nil {
  879. return nil, err
  880. }
  881. return res.NodeIDs, nil
  882. }
  883. // QuerySelectorParams executes querySelector on a given node.
  884. type QuerySelectorParams struct {
  885. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to query upon.
  886. Selector string `json:"selector"` // Selector string.
  887. }
  888. // QuerySelector executes querySelector on a given node.
  889. //
  890. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-querySelector
  891. //
  892. // parameters:
  893. //
  894. // nodeID - Id of the node to query upon.
  895. // selector - Selector string.
  896. func QuerySelector(nodeID cdp.NodeID, selector string) *QuerySelectorParams {
  897. return &QuerySelectorParams{
  898. NodeID: nodeID,
  899. Selector: selector,
  900. }
  901. }
  902. // QuerySelectorReturns return values.
  903. type QuerySelectorReturns struct {
  904. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Query selector result.
  905. }
  906. // Do executes DOM.querySelector against the provided context.
  907. //
  908. // returns:
  909. //
  910. // nodeID - Query selector result.
  911. func (p *QuerySelectorParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
  912. // execute
  913. var res QuerySelectorReturns
  914. err = cdp.Execute(ctx, CommandQuerySelector, p, &res)
  915. if err != nil {
  916. return 0, err
  917. }
  918. return res.NodeID, nil
  919. }
  920. // QuerySelectorAllParams executes querySelectorAll on a given node.
  921. type QuerySelectorAllParams struct {
  922. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to query upon.
  923. Selector string `json:"selector"` // Selector string.
  924. }
  925. // QuerySelectorAll executes querySelectorAll on a given node.
  926. //
  927. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-querySelectorAll
  928. //
  929. // parameters:
  930. //
  931. // nodeID - Id of the node to query upon.
  932. // selector - Selector string.
  933. func QuerySelectorAll(nodeID cdp.NodeID, selector string) *QuerySelectorAllParams {
  934. return &QuerySelectorAllParams{
  935. NodeID: nodeID,
  936. Selector: selector,
  937. }
  938. }
  939. // QuerySelectorAllReturns return values.
  940. type QuerySelectorAllReturns struct {
  941. NodeIDs []cdp.NodeID `json:"nodeIds,omitempty"` // Query selector result.
  942. }
  943. // Do executes DOM.querySelectorAll against the provided context.
  944. //
  945. // returns:
  946. //
  947. // nodeIDs - Query selector result.
  948. func (p *QuerySelectorAllParams) Do(ctx context.Context) (nodeIDs []cdp.NodeID, err error) {
  949. // execute
  950. var res QuerySelectorAllReturns
  951. err = cdp.Execute(ctx, CommandQuerySelectorAll, p, &res)
  952. if err != nil {
  953. return nil, err
  954. }
  955. return res.NodeIDs, nil
  956. }
  957. // GetTopLayerElementsParams returns NodeIds of current top layer elements.
  958. // Top layer is rendered closest to the user within a viewport, therefore its
  959. // elements always appear on top of all other content.
  960. type GetTopLayerElementsParams struct{}
  961. // GetTopLayerElements returns NodeIds of current top layer elements. Top
  962. // layer is rendered closest to the user within a viewport, therefore its
  963. // elements always appear on top of all other content.
  964. //
  965. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getTopLayerElements
  966. func GetTopLayerElements() *GetTopLayerElementsParams {
  967. return &GetTopLayerElementsParams{}
  968. }
  969. // GetTopLayerElementsReturns return values.
  970. type GetTopLayerElementsReturns struct {
  971. NodeIDs []cdp.NodeID `json:"nodeIds,omitempty"` // NodeIds of top layer elements
  972. }
  973. // Do executes DOM.getTopLayerElements against the provided context.
  974. //
  975. // returns:
  976. //
  977. // nodeIDs - NodeIds of top layer elements
  978. func (p *GetTopLayerElementsParams) Do(ctx context.Context) (nodeIDs []cdp.NodeID, err error) {
  979. // execute
  980. var res GetTopLayerElementsReturns
  981. err = cdp.Execute(ctx, CommandGetTopLayerElements, nil, &res)
  982. if err != nil {
  983. return nil, err
  984. }
  985. return res.NodeIDs, nil
  986. }
  987. // RedoParams re-does the last undone action.
  988. type RedoParams struct{}
  989. // Redo re-does the last undone action.
  990. //
  991. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-redo
  992. func Redo() *RedoParams {
  993. return &RedoParams{}
  994. }
  995. // Do executes DOM.redo against the provided context.
  996. func (p *RedoParams) Do(ctx context.Context) (err error) {
  997. return cdp.Execute(ctx, CommandRedo, nil, nil)
  998. }
  999. // RemoveAttributeParams removes attribute with given name from an element
  1000. // with given id.
  1001. type RemoveAttributeParams struct {
  1002. NodeID cdp.NodeID `json:"nodeId"` // Id of the element to remove attribute from.
  1003. Name string `json:"name"` // Name of the attribute to remove.
  1004. }
  1005. // RemoveAttribute removes attribute with given name from an element with
  1006. // given id.
  1007. //
  1008. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-removeAttribute
  1009. //
  1010. // parameters:
  1011. //
  1012. // nodeID - Id of the element to remove attribute from.
  1013. // name - Name of the attribute to remove.
  1014. func RemoveAttribute(nodeID cdp.NodeID, name string) *RemoveAttributeParams {
  1015. return &RemoveAttributeParams{
  1016. NodeID: nodeID,
  1017. Name: name,
  1018. }
  1019. }
  1020. // Do executes DOM.removeAttribute against the provided context.
  1021. func (p *RemoveAttributeParams) Do(ctx context.Context) (err error) {
  1022. return cdp.Execute(ctx, CommandRemoveAttribute, p, nil)
  1023. }
  1024. // RemoveNodeParams removes node with given id.
  1025. type RemoveNodeParams struct {
  1026. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to remove.
  1027. }
  1028. // RemoveNode removes node with given id.
  1029. //
  1030. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-removeNode
  1031. //
  1032. // parameters:
  1033. //
  1034. // nodeID - Id of the node to remove.
  1035. func RemoveNode(nodeID cdp.NodeID) *RemoveNodeParams {
  1036. return &RemoveNodeParams{
  1037. NodeID: nodeID,
  1038. }
  1039. }
  1040. // Do executes DOM.removeNode against the provided context.
  1041. func (p *RemoveNodeParams) Do(ctx context.Context) (err error) {
  1042. return cdp.Execute(ctx, CommandRemoveNode, p, nil)
  1043. }
  1044. // RequestChildNodesParams requests that children of the node with given id
  1045. // are returned to the caller in form of setChildNodes events where not only
  1046. // immediate children are retrieved, but all children down to the specified
  1047. // depth.
  1048. type RequestChildNodesParams struct {
  1049. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to get children for.
  1050. Depth int64 `json:"depth,omitempty"` // The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
  1051. Pierce bool `json:"pierce,omitempty"` // Whether or not iframes and shadow roots should be traversed when returning the sub-tree (default is false).
  1052. }
  1053. // RequestChildNodes requests that children of the node with given id are
  1054. // returned to the caller in form of setChildNodes events where not only
  1055. // immediate children are retrieved, but all children down to the specified
  1056. // depth.
  1057. //
  1058. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-requestChildNodes
  1059. //
  1060. // parameters:
  1061. //
  1062. // nodeID - Id of the node to get children for.
  1063. func RequestChildNodes(nodeID cdp.NodeID) *RequestChildNodesParams {
  1064. return &RequestChildNodesParams{
  1065. NodeID: nodeID,
  1066. }
  1067. }
  1068. // WithDepth the maximum depth at which children should be retrieved,
  1069. // defaults to 1. Use -1 for the entire subtree or provide an integer larger
  1070. // than 0.
  1071. func (p RequestChildNodesParams) WithDepth(depth int64) *RequestChildNodesParams {
  1072. p.Depth = depth
  1073. return &p
  1074. }
  1075. // WithPierce whether or not iframes and shadow roots should be traversed
  1076. // when returning the sub-tree (default is false).
  1077. func (p RequestChildNodesParams) WithPierce(pierce bool) *RequestChildNodesParams {
  1078. p.Pierce = pierce
  1079. return &p
  1080. }
  1081. // Do executes DOM.requestChildNodes against the provided context.
  1082. func (p *RequestChildNodesParams) Do(ctx context.Context) (err error) {
  1083. return cdp.Execute(ctx, CommandRequestChildNodes, p, nil)
  1084. }
  1085. // RequestNodeParams requests that the node is sent to the caller given the
  1086. // JavaScript node object reference. All nodes that form the path from the node
  1087. // to the root are also sent to the client as a series of setChildNodes
  1088. // notifications.
  1089. type RequestNodeParams struct {
  1090. ObjectID runtime.RemoteObjectID `json:"objectId"` // JavaScript object id to convert into node.
  1091. }
  1092. // RequestNode requests that the node is sent to the caller given the
  1093. // JavaScript node object reference. All nodes that form the path from the node
  1094. // to the root are also sent to the client as a series of setChildNodes
  1095. // notifications.
  1096. //
  1097. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-requestNode
  1098. //
  1099. // parameters:
  1100. //
  1101. // objectID - JavaScript object id to convert into node.
  1102. func RequestNode(objectID runtime.RemoteObjectID) *RequestNodeParams {
  1103. return &RequestNodeParams{
  1104. ObjectID: objectID,
  1105. }
  1106. }
  1107. // RequestNodeReturns return values.
  1108. type RequestNodeReturns struct {
  1109. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Node id for given object.
  1110. }
  1111. // Do executes DOM.requestNode against the provided context.
  1112. //
  1113. // returns:
  1114. //
  1115. // nodeID - Node id for given object.
  1116. func (p *RequestNodeParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
  1117. // execute
  1118. var res RequestNodeReturns
  1119. err = cdp.Execute(ctx, CommandRequestNode, p, &res)
  1120. if err != nil {
  1121. return 0, err
  1122. }
  1123. return res.NodeID, nil
  1124. }
  1125. // ResolveNodeParams resolves the JavaScript node object for a given NodeId
  1126. // or BackendNodeId.
  1127. type ResolveNodeParams struct {
  1128. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node to resolve.
  1129. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Backend identifier of the node to resolve.
  1130. ObjectGroup string `json:"objectGroup,omitempty"` // Symbolic group name that can be used to release multiple objects.
  1131. ExecutionContextID runtime.ExecutionContextID `json:"executionContextId,omitempty"` // Execution context in which to resolve the node.
  1132. }
  1133. // ResolveNode resolves the JavaScript node object for a given NodeId or
  1134. // BackendNodeId.
  1135. //
  1136. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-resolveNode
  1137. //
  1138. // parameters:
  1139. func ResolveNode() *ResolveNodeParams {
  1140. return &ResolveNodeParams{}
  1141. }
  1142. // WithNodeID ID of the node to resolve.
  1143. func (p ResolveNodeParams) WithNodeID(nodeID cdp.NodeID) *ResolveNodeParams {
  1144. p.NodeID = nodeID
  1145. return &p
  1146. }
  1147. // WithBackendNodeID backend identifier of the node to resolve.
  1148. func (p ResolveNodeParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *ResolveNodeParams {
  1149. p.BackendNodeID = backendNodeID
  1150. return &p
  1151. }
  1152. // WithObjectGroup symbolic group name that can be used to release multiple
  1153. // objects.
  1154. func (p ResolveNodeParams) WithObjectGroup(objectGroup string) *ResolveNodeParams {
  1155. p.ObjectGroup = objectGroup
  1156. return &p
  1157. }
  1158. // WithExecutionContextID execution context in which to resolve the node.
  1159. func (p ResolveNodeParams) WithExecutionContextID(executionContextID runtime.ExecutionContextID) *ResolveNodeParams {
  1160. p.ExecutionContextID = executionContextID
  1161. return &p
  1162. }
  1163. // ResolveNodeReturns return values.
  1164. type ResolveNodeReturns struct {
  1165. Object *runtime.RemoteObject `json:"object,omitempty"` // JavaScript object wrapper for given node.
  1166. }
  1167. // Do executes DOM.resolveNode against the provided context.
  1168. //
  1169. // returns:
  1170. //
  1171. // object - JavaScript object wrapper for given node.
  1172. func (p *ResolveNodeParams) Do(ctx context.Context) (object *runtime.RemoteObject, err error) {
  1173. // execute
  1174. var res ResolveNodeReturns
  1175. err = cdp.Execute(ctx, CommandResolveNode, p, &res)
  1176. if err != nil {
  1177. return nil, err
  1178. }
  1179. return res.Object, nil
  1180. }
  1181. // SetAttributeValueParams sets attribute for an element with given id.
  1182. type SetAttributeValueParams struct {
  1183. NodeID cdp.NodeID `json:"nodeId"` // Id of the element to set attribute for.
  1184. Name string `json:"name"` // Attribute name.
  1185. Value string `json:"value"` // Attribute value.
  1186. }
  1187. // SetAttributeValue sets attribute for an element with given id.
  1188. //
  1189. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-setAttributeValue
  1190. //
  1191. // parameters:
  1192. //
  1193. // nodeID - Id of the element to set attribute for.
  1194. // name - Attribute name.
  1195. // value - Attribute value.
  1196. func SetAttributeValue(nodeID cdp.NodeID, name string, value string) *SetAttributeValueParams {
  1197. return &SetAttributeValueParams{
  1198. NodeID: nodeID,
  1199. Name: name,
  1200. Value: value,
  1201. }
  1202. }
  1203. // Do executes DOM.setAttributeValue against the provided context.
  1204. func (p *SetAttributeValueParams) Do(ctx context.Context) (err error) {
  1205. return cdp.Execute(ctx, CommandSetAttributeValue, p, nil)
  1206. }
  1207. // SetAttributesAsTextParams sets attributes on element with given id. This
  1208. // method is useful when user edits some existing attribute value and types in
  1209. // several attribute name/value pairs.
  1210. type SetAttributesAsTextParams struct {
  1211. NodeID cdp.NodeID `json:"nodeId"` // Id of the element to set attributes for.
  1212. Text string `json:"text"` // Text with a number of attributes. Will parse this text using HTML parser.
  1213. Name string `json:"name,omitempty"` // Attribute name to replace with new attributes derived from text in case text parsed successfully.
  1214. }
  1215. // SetAttributesAsText sets attributes on element with given id. This method
  1216. // is useful when user edits some existing attribute value and types in several
  1217. // attribute name/value pairs.
  1218. //
  1219. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-setAttributesAsText
  1220. //
  1221. // parameters:
  1222. //
  1223. // nodeID - Id of the element to set attributes for.
  1224. // text - Text with a number of attributes. Will parse this text using HTML parser.
  1225. func SetAttributesAsText(nodeID cdp.NodeID, text string) *SetAttributesAsTextParams {
  1226. return &SetAttributesAsTextParams{
  1227. NodeID: nodeID,
  1228. Text: text,
  1229. }
  1230. }
  1231. // WithName attribute name to replace with new attributes derived from text
  1232. // in case text parsed successfully.
  1233. func (p SetAttributesAsTextParams) WithName(name string) *SetAttributesAsTextParams {
  1234. p.Name = name
  1235. return &p
  1236. }
  1237. // Do executes DOM.setAttributesAsText against the provided context.
  1238. func (p *SetAttributesAsTextParams) Do(ctx context.Context) (err error) {
  1239. return cdp.Execute(ctx, CommandSetAttributesAsText, p, nil)
  1240. }
  1241. // SetFileInputFilesParams sets files for the given file input element.
  1242. type SetFileInputFilesParams struct {
  1243. Files []string `json:"files"` // Array of file paths to set.
  1244. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Identifier of the node.
  1245. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Identifier of the backend node.
  1246. ObjectID runtime.RemoteObjectID `json:"objectId,omitempty"` // JavaScript object id of the node wrapper.
  1247. }
  1248. // SetFileInputFiles sets files for the given file input element.
  1249. //
  1250. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-setFileInputFiles
  1251. //
  1252. // parameters:
  1253. //
  1254. // files - Array of file paths to set.
  1255. func SetFileInputFiles(files []string) *SetFileInputFilesParams {
  1256. return &SetFileInputFilesParams{
  1257. Files: files,
  1258. }
  1259. }
  1260. // WithNodeID identifier of the node.
  1261. func (p SetFileInputFilesParams) WithNodeID(nodeID cdp.NodeID) *SetFileInputFilesParams {
  1262. p.NodeID = nodeID
  1263. return &p
  1264. }
  1265. // WithBackendNodeID identifier of the backend node.
  1266. func (p SetFileInputFilesParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *SetFileInputFilesParams {
  1267. p.BackendNodeID = backendNodeID
  1268. return &p
  1269. }
  1270. // WithObjectID JavaScript object id of the node wrapper.
  1271. func (p SetFileInputFilesParams) WithObjectID(objectID runtime.RemoteObjectID) *SetFileInputFilesParams {
  1272. p.ObjectID = objectID
  1273. return &p
  1274. }
  1275. // Do executes DOM.setFileInputFiles against the provided context.
  1276. func (p *SetFileInputFilesParams) Do(ctx context.Context) (err error) {
  1277. return cdp.Execute(ctx, CommandSetFileInputFiles, p, nil)
  1278. }
  1279. // SetNodeStackTracesEnabledParams sets if stack traces should be captured
  1280. // for Nodes. See Node.getNodeStackTraces. Default is disabled.
  1281. type SetNodeStackTracesEnabledParams struct {
  1282. Enable bool `json:"enable"` // Enable or disable.
  1283. }
  1284. // SetNodeStackTracesEnabled sets if stack traces should be captured for
  1285. // Nodes. See Node.getNodeStackTraces. Default is disabled.
  1286. //
  1287. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-setNodeStackTracesEnabled
  1288. //
  1289. // parameters:
  1290. //
  1291. // enable - Enable or disable.
  1292. func SetNodeStackTracesEnabled(enable bool) *SetNodeStackTracesEnabledParams {
  1293. return &SetNodeStackTracesEnabledParams{
  1294. Enable: enable,
  1295. }
  1296. }
  1297. // Do executes DOM.setNodeStackTracesEnabled against the provided context.
  1298. func (p *SetNodeStackTracesEnabledParams) Do(ctx context.Context) (err error) {
  1299. return cdp.Execute(ctx, CommandSetNodeStackTracesEnabled, p, nil)
  1300. }
  1301. // GetNodeStackTracesParams gets stack traces associated with a Node. As of
  1302. // now, only provides stack trace for Node creation.
  1303. type GetNodeStackTracesParams struct {
  1304. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to get stack traces for.
  1305. }
  1306. // GetNodeStackTraces gets stack traces associated with a Node. As of now,
  1307. // only provides stack trace for Node creation.
  1308. //
  1309. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getNodeStackTraces
  1310. //
  1311. // parameters:
  1312. //
  1313. // nodeID - Id of the node to get stack traces for.
  1314. func GetNodeStackTraces(nodeID cdp.NodeID) *GetNodeStackTracesParams {
  1315. return &GetNodeStackTracesParams{
  1316. NodeID: nodeID,
  1317. }
  1318. }
  1319. // GetNodeStackTracesReturns return values.
  1320. type GetNodeStackTracesReturns struct {
  1321. Creation *runtime.StackTrace `json:"creation,omitempty"` // Creation stack trace, if available.
  1322. }
  1323. // Do executes DOM.getNodeStackTraces against the provided context.
  1324. //
  1325. // returns:
  1326. //
  1327. // creation - Creation stack trace, if available.
  1328. func (p *GetNodeStackTracesParams) Do(ctx context.Context) (creation *runtime.StackTrace, err error) {
  1329. // execute
  1330. var res GetNodeStackTracesReturns
  1331. err = cdp.Execute(ctx, CommandGetNodeStackTraces, p, &res)
  1332. if err != nil {
  1333. return nil, err
  1334. }
  1335. return res.Creation, nil
  1336. }
  1337. // GetFileInfoParams returns file information for the given File wrapper.
  1338. type GetFileInfoParams struct {
  1339. ObjectID runtime.RemoteObjectID `json:"objectId"` // JavaScript object id of the node wrapper.
  1340. }
  1341. // GetFileInfo returns file information for the given File wrapper.
  1342. //
  1343. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getFileInfo
  1344. //
  1345. // parameters:
  1346. //
  1347. // objectID - JavaScript object id of the node wrapper.
  1348. func GetFileInfo(objectID runtime.RemoteObjectID) *GetFileInfoParams {
  1349. return &GetFileInfoParams{
  1350. ObjectID: objectID,
  1351. }
  1352. }
  1353. // GetFileInfoReturns return values.
  1354. type GetFileInfoReturns struct {
  1355. Path string `json:"path,omitempty"`
  1356. }
  1357. // Do executes DOM.getFileInfo against the provided context.
  1358. //
  1359. // returns:
  1360. //
  1361. // path
  1362. func (p *GetFileInfoParams) Do(ctx context.Context) (path string, err error) {
  1363. // execute
  1364. var res GetFileInfoReturns
  1365. err = cdp.Execute(ctx, CommandGetFileInfo, p, &res)
  1366. if err != nil {
  1367. return "", err
  1368. }
  1369. return res.Path, nil
  1370. }
  1371. // SetInspectedNodeParams enables console to refer to the node with given id
  1372. // via $x (see Command Line API for more details $x functions).
  1373. type SetInspectedNodeParams struct {
  1374. NodeID cdp.NodeID `json:"nodeId"` // DOM node id to be accessible by means of $x command line API.
  1375. }
  1376. // SetInspectedNode enables console to refer to the node with given id via $x
  1377. // (see Command Line API for more details $x functions).
  1378. //
  1379. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-setInspectedNode
  1380. //
  1381. // parameters:
  1382. //
  1383. // nodeID - DOM node id to be accessible by means of $x command line API.
  1384. func SetInspectedNode(nodeID cdp.NodeID) *SetInspectedNodeParams {
  1385. return &SetInspectedNodeParams{
  1386. NodeID: nodeID,
  1387. }
  1388. }
  1389. // Do executes DOM.setInspectedNode against the provided context.
  1390. func (p *SetInspectedNodeParams) Do(ctx context.Context) (err error) {
  1391. return cdp.Execute(ctx, CommandSetInspectedNode, p, nil)
  1392. }
  1393. // SetNodeNameParams sets node name for a node with given id.
  1394. type SetNodeNameParams struct {
  1395. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to set name for.
  1396. Name string `json:"name"` // New node's name.
  1397. }
  1398. // SetNodeName sets node name for a node with given id.
  1399. //
  1400. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-setNodeName
  1401. //
  1402. // parameters:
  1403. //
  1404. // nodeID - Id of the node to set name for.
  1405. // name - New node's name.
  1406. func SetNodeName(nodeID cdp.NodeID, name string) *SetNodeNameParams {
  1407. return &SetNodeNameParams{
  1408. NodeID: nodeID,
  1409. Name: name,
  1410. }
  1411. }
  1412. // SetNodeNameReturns return values.
  1413. type SetNodeNameReturns struct {
  1414. NodeID cdp.NodeID `json:"nodeId,omitempty"` // New node's id.
  1415. }
  1416. // Do executes DOM.setNodeName against the provided context.
  1417. //
  1418. // returns:
  1419. //
  1420. // nodeID - New node's id.
  1421. func (p *SetNodeNameParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
  1422. // execute
  1423. var res SetNodeNameReturns
  1424. err = cdp.Execute(ctx, CommandSetNodeName, p, &res)
  1425. if err != nil {
  1426. return 0, err
  1427. }
  1428. return res.NodeID, nil
  1429. }
  1430. // SetNodeValueParams sets node value for a node with given id.
  1431. type SetNodeValueParams struct {
  1432. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to set value for.
  1433. Value string `json:"value"` // New node's value.
  1434. }
  1435. // SetNodeValue sets node value for a node with given id.
  1436. //
  1437. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-setNodeValue
  1438. //
  1439. // parameters:
  1440. //
  1441. // nodeID - Id of the node to set value for.
  1442. // value - New node's value.
  1443. func SetNodeValue(nodeID cdp.NodeID, value string) *SetNodeValueParams {
  1444. return &SetNodeValueParams{
  1445. NodeID: nodeID,
  1446. Value: value,
  1447. }
  1448. }
  1449. // Do executes DOM.setNodeValue against the provided context.
  1450. func (p *SetNodeValueParams) Do(ctx context.Context) (err error) {
  1451. return cdp.Execute(ctx, CommandSetNodeValue, p, nil)
  1452. }
  1453. // SetOuterHTMLParams sets node HTML markup, returns new node id.
  1454. type SetOuterHTMLParams struct {
  1455. NodeID cdp.NodeID `json:"nodeId"` // Id of the node to set markup for.
  1456. OuterHTML string `json:"outerHTML"` // Outer HTML markup to set.
  1457. }
  1458. // SetOuterHTML sets node HTML markup, returns new node id.
  1459. //
  1460. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-setOuterHTML
  1461. //
  1462. // parameters:
  1463. //
  1464. // nodeID - Id of the node to set markup for.
  1465. // outerHTML - Outer HTML markup to set.
  1466. func SetOuterHTML(nodeID cdp.NodeID, outerHTML string) *SetOuterHTMLParams {
  1467. return &SetOuterHTMLParams{
  1468. NodeID: nodeID,
  1469. OuterHTML: outerHTML,
  1470. }
  1471. }
  1472. // Do executes DOM.setOuterHTML against the provided context.
  1473. func (p *SetOuterHTMLParams) Do(ctx context.Context) (err error) {
  1474. return cdp.Execute(ctx, CommandSetOuterHTML, p, nil)
  1475. }
  1476. // UndoParams undoes the last performed action.
  1477. type UndoParams struct{}
  1478. // Undo undoes the last performed action.
  1479. //
  1480. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-undo
  1481. func Undo() *UndoParams {
  1482. return &UndoParams{}
  1483. }
  1484. // Do executes DOM.undo against the provided context.
  1485. func (p *UndoParams) Do(ctx context.Context) (err error) {
  1486. return cdp.Execute(ctx, CommandUndo, nil, nil)
  1487. }
  1488. // GetFrameOwnerParams returns iframe node that owns iframe with the given
  1489. // domain.
  1490. type GetFrameOwnerParams struct {
  1491. FrameID cdp.FrameID `json:"frameId"`
  1492. }
  1493. // GetFrameOwner returns iframe node that owns iframe with the given domain.
  1494. //
  1495. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getFrameOwner
  1496. //
  1497. // parameters:
  1498. //
  1499. // frameID
  1500. func GetFrameOwner(frameID cdp.FrameID) *GetFrameOwnerParams {
  1501. return &GetFrameOwnerParams{
  1502. FrameID: frameID,
  1503. }
  1504. }
  1505. // GetFrameOwnerReturns return values.
  1506. type GetFrameOwnerReturns struct {
  1507. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty"` // Resulting node.
  1508. NodeID cdp.NodeID `json:"nodeId,omitempty"` // Id of the node at given coordinates, only when enabled and requested document.
  1509. }
  1510. // Do executes DOM.getFrameOwner against the provided context.
  1511. //
  1512. // returns:
  1513. //
  1514. // backendNodeID - Resulting node.
  1515. // nodeID - Id of the node at given coordinates, only when enabled and requested document.
  1516. func (p *GetFrameOwnerParams) Do(ctx context.Context) (backendNodeID cdp.BackendNodeID, nodeID cdp.NodeID, err error) {
  1517. // execute
  1518. var res GetFrameOwnerReturns
  1519. err = cdp.Execute(ctx, CommandGetFrameOwner, p, &res)
  1520. if err != nil {
  1521. return 0, 0, err
  1522. }
  1523. return res.BackendNodeID, res.NodeID, nil
  1524. }
  1525. // GetContainerForNodeParams returns the query container of the given node
  1526. // based on container query conditions: containerName, physical, and logical
  1527. // axes. If no axes are provided, the style container is returned, which is the
  1528. // direct parent or the closest element with a matching container-name.
  1529. type GetContainerForNodeParams struct {
  1530. NodeID cdp.NodeID `json:"nodeId"`
  1531. ContainerName string `json:"containerName,omitempty"`
  1532. PhysicalAxes PhysicalAxes `json:"physicalAxes,omitempty"`
  1533. LogicalAxes LogicalAxes `json:"logicalAxes,omitempty"`
  1534. }
  1535. // GetContainerForNode returns the query container of the given node based on
  1536. // container query conditions: containerName, physical, and logical axes. If no
  1537. // axes are provided, the style container is returned, which is the direct
  1538. // parent or the closest element with a matching container-name.
  1539. //
  1540. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getContainerForNode
  1541. //
  1542. // parameters:
  1543. //
  1544. // nodeID
  1545. func GetContainerForNode(nodeID cdp.NodeID) *GetContainerForNodeParams {
  1546. return &GetContainerForNodeParams{
  1547. NodeID: nodeID,
  1548. }
  1549. }
  1550. // WithContainerName [no description].
  1551. func (p GetContainerForNodeParams) WithContainerName(containerName string) *GetContainerForNodeParams {
  1552. p.ContainerName = containerName
  1553. return &p
  1554. }
  1555. // WithPhysicalAxes [no description].
  1556. func (p GetContainerForNodeParams) WithPhysicalAxes(physicalAxes PhysicalAxes) *GetContainerForNodeParams {
  1557. p.PhysicalAxes = physicalAxes
  1558. return &p
  1559. }
  1560. // WithLogicalAxes [no description].
  1561. func (p GetContainerForNodeParams) WithLogicalAxes(logicalAxes LogicalAxes) *GetContainerForNodeParams {
  1562. p.LogicalAxes = logicalAxes
  1563. return &p
  1564. }
  1565. // GetContainerForNodeReturns return values.
  1566. type GetContainerForNodeReturns struct {
  1567. NodeID cdp.NodeID `json:"nodeId,omitempty"` // The container node for the given node, or null if not found.
  1568. }
  1569. // Do executes DOM.getContainerForNode against the provided context.
  1570. //
  1571. // returns:
  1572. //
  1573. // nodeID - The container node for the given node, or null if not found.
  1574. func (p *GetContainerForNodeParams) Do(ctx context.Context) (nodeID cdp.NodeID, err error) {
  1575. // execute
  1576. var res GetContainerForNodeReturns
  1577. err = cdp.Execute(ctx, CommandGetContainerForNode, p, &res)
  1578. if err != nil {
  1579. return 0, err
  1580. }
  1581. return res.NodeID, nil
  1582. }
  1583. // GetQueryingDescendantsForContainerParams returns the descendants of a
  1584. // container query container that have container queries against this container.
  1585. type GetQueryingDescendantsForContainerParams struct {
  1586. NodeID cdp.NodeID `json:"nodeId"` // Id of the container node to find querying descendants from.
  1587. }
  1588. // GetQueryingDescendantsForContainer returns the descendants of a container
  1589. // query container that have container queries against this container.
  1590. //
  1591. // See: https://chromedevtools.github.io/devtools-protocol/tot/DOM#method-getQueryingDescendantsForContainer
  1592. //
  1593. // parameters:
  1594. //
  1595. // nodeID - Id of the container node to find querying descendants from.
  1596. func GetQueryingDescendantsForContainer(nodeID cdp.NodeID) *GetQueryingDescendantsForContainerParams {
  1597. return &GetQueryingDescendantsForContainerParams{
  1598. NodeID: nodeID,
  1599. }
  1600. }
  1601. // GetQueryingDescendantsForContainerReturns return values.
  1602. type GetQueryingDescendantsForContainerReturns struct {
  1603. NodeIDs []cdp.NodeID `json:"nodeIds,omitempty"` // Descendant nodes with container queries against the given container.
  1604. }
  1605. // Do executes DOM.getQueryingDescendantsForContainer against the provided context.
  1606. //
  1607. // returns:
  1608. //
  1609. // nodeIDs - Descendant nodes with container queries against the given container.
  1610. func (p *GetQueryingDescendantsForContainerParams) Do(ctx context.Context) (nodeIDs []cdp.NodeID, err error) {
  1611. // execute
  1612. var res GetQueryingDescendantsForContainerReturns
  1613. err = cdp.Execute(ctx, CommandGetQueryingDescendantsForContainer, p, &res)
  1614. if err != nil {
  1615. return nil, err
  1616. }
  1617. return res.NodeIDs, nil
  1618. }
  1619. // Command names.
  1620. const (
  1621. CommandCollectClassNamesFromSubtree = "DOM.collectClassNamesFromSubtree"
  1622. CommandCopyTo = "DOM.copyTo"
  1623. CommandDescribeNode = "DOM.describeNode"
  1624. CommandScrollIntoViewIfNeeded = "DOM.scrollIntoViewIfNeeded"
  1625. CommandDisable = "DOM.disable"
  1626. CommandDiscardSearchResults = "DOM.discardSearchResults"
  1627. CommandEnable = "DOM.enable"
  1628. CommandFocus = "DOM.focus"
  1629. CommandGetAttributes = "DOM.getAttributes"
  1630. CommandGetBoxModel = "DOM.getBoxModel"
  1631. CommandGetContentQuads = "DOM.getContentQuads"
  1632. CommandGetDocument = "DOM.getDocument"
  1633. CommandGetNodesForSubtreeByStyle = "DOM.getNodesForSubtreeByStyle"
  1634. CommandGetNodeForLocation = "DOM.getNodeForLocation"
  1635. CommandGetOuterHTML = "DOM.getOuterHTML"
  1636. CommandGetRelayoutBoundary = "DOM.getRelayoutBoundary"
  1637. CommandGetSearchResults = "DOM.getSearchResults"
  1638. CommandMarkUndoableState = "DOM.markUndoableState"
  1639. CommandMoveTo = "DOM.moveTo"
  1640. CommandPerformSearch = "DOM.performSearch"
  1641. CommandPushNodeByPathToFrontend = "DOM.pushNodeByPathToFrontend"
  1642. CommandPushNodesByBackendIDsToFrontend = "DOM.pushNodesByBackendIdsToFrontend"
  1643. CommandQuerySelector = "DOM.querySelector"
  1644. CommandQuerySelectorAll = "DOM.querySelectorAll"
  1645. CommandGetTopLayerElements = "DOM.getTopLayerElements"
  1646. CommandRedo = "DOM.redo"
  1647. CommandRemoveAttribute = "DOM.removeAttribute"
  1648. CommandRemoveNode = "DOM.removeNode"
  1649. CommandRequestChildNodes = "DOM.requestChildNodes"
  1650. CommandRequestNode = "DOM.requestNode"
  1651. CommandResolveNode = "DOM.resolveNode"
  1652. CommandSetAttributeValue = "DOM.setAttributeValue"
  1653. CommandSetAttributesAsText = "DOM.setAttributesAsText"
  1654. CommandSetFileInputFiles = "DOM.setFileInputFiles"
  1655. CommandSetNodeStackTracesEnabled = "DOM.setNodeStackTracesEnabled"
  1656. CommandGetNodeStackTraces = "DOM.getNodeStackTraces"
  1657. CommandGetFileInfo = "DOM.getFileInfo"
  1658. CommandSetInspectedNode = "DOM.setInspectedNode"
  1659. CommandSetNodeName = "DOM.setNodeName"
  1660. CommandSetNodeValue = "DOM.setNodeValue"
  1661. CommandSetOuterHTML = "DOM.setOuterHTML"
  1662. CommandUndo = "DOM.undo"
  1663. CommandGetFrameOwner = "DOM.getFrameOwner"
  1664. CommandGetContainerForNode = "DOM.getContainerForNode"
  1665. CommandGetQueryingDescendantsForContainer = "DOM.getQueryingDescendantsForContainer"
  1666. )