dom.go 71 KB

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