accessibility.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. // Package accessibility provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Accessibility domain.
  3. //
  4. // Generated by the cdproto-gen command.
  5. package accessibility
  6. // Code generated by cdproto-gen. DO NOT EDIT.
  7. import (
  8. "context"
  9. "github.com/chromedp/cdproto/cdp"
  10. "github.com/chromedp/cdproto/runtime"
  11. )
  12. // DisableParams disables the accessibility domain.
  13. type DisableParams struct{}
  14. // Disable disables the accessibility domain.
  15. //
  16. // See: https://chromedevtools.github.io/devtools-protocol/tot/Accessibility#method-disable
  17. func Disable() *DisableParams {
  18. return &DisableParams{}
  19. }
  20. // Do executes Accessibility.disable against the provided context.
  21. func (p *DisableParams) Do(ctx context.Context) (err error) {
  22. return cdp.Execute(ctx, CommandDisable, nil, nil)
  23. }
  24. // EnableParams enables the accessibility domain which causes AXNodeIds to
  25. // remain consistent between method calls. This turns on accessibility for the
  26. // page, which can impact performance until accessibility is disabled.
  27. type EnableParams struct{}
  28. // Enable enables the accessibility domain which causes AXNodeIds to remain
  29. // consistent between method calls. This turns on accessibility for the page,
  30. // which can impact performance until accessibility is disabled.
  31. //
  32. // See: https://chromedevtools.github.io/devtools-protocol/tot/Accessibility#method-enable
  33. func Enable() *EnableParams {
  34. return &EnableParams{}
  35. }
  36. // Do executes Accessibility.enable against the provided context.
  37. func (p *EnableParams) Do(ctx context.Context) (err error) {
  38. return cdp.Execute(ctx, CommandEnable, nil, nil)
  39. }
  40. // GetPartialAXTreeParams fetches the accessibility node and partial
  41. // accessibility tree for this DOM node, if it exists.
  42. type GetPartialAXTreeParams struct {
  43. NodeID cdp.NodeID `json:"nodeId,omitempty,omitzero"` // Identifier of the node to get the partial accessibility tree for.
  44. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty,omitzero"` // Identifier of the backend node to get the partial accessibility tree for.
  45. ObjectID runtime.RemoteObjectID `json:"objectId,omitempty,omitzero"` // JavaScript object id of the node wrapper to get the partial accessibility tree for.
  46. FetchRelatives bool `json:"fetchRelatives"` // Whether to fetch this node's ancestors, siblings and children. Defaults to true.
  47. }
  48. // GetPartialAXTree fetches the accessibility node and partial accessibility
  49. // tree for this DOM node, if it exists.
  50. //
  51. // See: https://chromedevtools.github.io/devtools-protocol/tot/Accessibility#method-getPartialAXTree
  52. //
  53. // parameters:
  54. func GetPartialAXTree() *GetPartialAXTreeParams {
  55. return &GetPartialAXTreeParams{
  56. FetchRelatives: true,
  57. }
  58. }
  59. // WithNodeID identifier of the node to get the partial accessibility tree
  60. // for.
  61. func (p GetPartialAXTreeParams) WithNodeID(nodeID cdp.NodeID) *GetPartialAXTreeParams {
  62. p.NodeID = nodeID
  63. return &p
  64. }
  65. // WithBackendNodeID identifier of the backend node to get the partial
  66. // accessibility tree for.
  67. func (p GetPartialAXTreeParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *GetPartialAXTreeParams {
  68. p.BackendNodeID = backendNodeID
  69. return &p
  70. }
  71. // WithObjectID JavaScript object id of the node wrapper to get the partial
  72. // accessibility tree for.
  73. func (p GetPartialAXTreeParams) WithObjectID(objectID runtime.RemoteObjectID) *GetPartialAXTreeParams {
  74. p.ObjectID = objectID
  75. return &p
  76. }
  77. // WithFetchRelatives whether to fetch this node's ancestors, siblings and
  78. // children. Defaults to true.
  79. func (p GetPartialAXTreeParams) WithFetchRelatives(fetchRelatives bool) *GetPartialAXTreeParams {
  80. p.FetchRelatives = fetchRelatives
  81. return &p
  82. }
  83. // GetPartialAXTreeReturns return values.
  84. type GetPartialAXTreeReturns struct {
  85. Nodes []*Node `json:"nodes,omitempty,omitzero"` // The Accessibility.AXNode for this DOM node, if it exists, plus its ancestors, siblings and children, if requested.
  86. }
  87. // Do executes Accessibility.getPartialAXTree against the provided context.
  88. //
  89. // returns:
  90. //
  91. // nodes - The Accessibility.AXNode for this DOM node, if it exists, plus its ancestors, siblings and children, if requested.
  92. func (p *GetPartialAXTreeParams) Do(ctx context.Context) (nodes []*Node, err error) {
  93. // execute
  94. var res GetPartialAXTreeReturns
  95. err = cdp.Execute(ctx, CommandGetPartialAXTree, p, &res)
  96. if err != nil {
  97. return nil, err
  98. }
  99. return res.Nodes, nil
  100. }
  101. // GetFullAXTreeParams fetches the entire accessibility tree for the root
  102. // Document.
  103. type GetFullAXTreeParams struct {
  104. Depth int64 `json:"depth,omitempty,omitzero"` // The maximum depth at which descendants of the root node should be retrieved. If omitted, the full tree is returned.
  105. FrameID cdp.FrameID `json:"frameId,omitempty,omitzero"` // The frame for whose document the AX tree should be retrieved. If omitted, the root frame is used.
  106. }
  107. // GetFullAXTree fetches the entire accessibility tree for the root Document.
  108. //
  109. // See: https://chromedevtools.github.io/devtools-protocol/tot/Accessibility#method-getFullAXTree
  110. //
  111. // parameters:
  112. func GetFullAXTree() *GetFullAXTreeParams {
  113. return &GetFullAXTreeParams{}
  114. }
  115. // WithDepth the maximum depth at which descendants of the root node should
  116. // be retrieved. If omitted, the full tree is returned.
  117. func (p GetFullAXTreeParams) WithDepth(depth int64) *GetFullAXTreeParams {
  118. p.Depth = depth
  119. return &p
  120. }
  121. // WithFrameID the frame for whose document the AX tree should be retrieved.
  122. // If omitted, the root frame is used.
  123. func (p GetFullAXTreeParams) WithFrameID(frameID cdp.FrameID) *GetFullAXTreeParams {
  124. p.FrameID = frameID
  125. return &p
  126. }
  127. // GetFullAXTreeReturns return values.
  128. type GetFullAXTreeReturns struct {
  129. Nodes []*Node `json:"nodes,omitempty,omitzero"`
  130. }
  131. // Do executes Accessibility.getFullAXTree against the provided context.
  132. //
  133. // returns:
  134. //
  135. // nodes
  136. func (p *GetFullAXTreeParams) Do(ctx context.Context) (nodes []*Node, err error) {
  137. // execute
  138. var res GetFullAXTreeReturns
  139. err = cdp.Execute(ctx, CommandGetFullAXTree, p, &res)
  140. if err != nil {
  141. return nil, err
  142. }
  143. return res.Nodes, nil
  144. }
  145. // GetRootAXNodeParams fetches the root node. Requires enable() to have been
  146. // called previously.
  147. type GetRootAXNodeParams struct {
  148. FrameID cdp.FrameID `json:"frameId,omitempty,omitzero"` // The frame in whose document the node resides. If omitted, the root frame is used.
  149. }
  150. // GetRootAXNode fetches the root node. Requires enable() to have been called
  151. // previously.
  152. //
  153. // See: https://chromedevtools.github.io/devtools-protocol/tot/Accessibility#method-getRootAXNode
  154. //
  155. // parameters:
  156. func GetRootAXNode() *GetRootAXNodeParams {
  157. return &GetRootAXNodeParams{}
  158. }
  159. // WithFrameID the frame in whose document the node resides. If omitted, the
  160. // root frame is used.
  161. func (p GetRootAXNodeParams) WithFrameID(frameID cdp.FrameID) *GetRootAXNodeParams {
  162. p.FrameID = frameID
  163. return &p
  164. }
  165. // GetRootAXNodeReturns return values.
  166. type GetRootAXNodeReturns struct {
  167. Node *Node `json:"node,omitempty,omitzero"`
  168. }
  169. // Do executes Accessibility.getRootAXNode against the provided context.
  170. //
  171. // returns:
  172. //
  173. // node
  174. func (p *GetRootAXNodeParams) Do(ctx context.Context) (node *Node, err error) {
  175. // execute
  176. var res GetRootAXNodeReturns
  177. err = cdp.Execute(ctx, CommandGetRootAXNode, p, &res)
  178. if err != nil {
  179. return nil, err
  180. }
  181. return res.Node, nil
  182. }
  183. // GetAXNodeAndAncestorsParams fetches a node and all ancestors up to and
  184. // including the root. Requires enable() to have been called previously.
  185. type GetAXNodeAndAncestorsParams struct {
  186. NodeID cdp.NodeID `json:"nodeId,omitempty,omitzero"` // Identifier of the node to get.
  187. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty,omitzero"` // Identifier of the backend node to get.
  188. ObjectID runtime.RemoteObjectID `json:"objectId,omitempty,omitzero"` // JavaScript object id of the node wrapper to get.
  189. }
  190. // GetAXNodeAndAncestors fetches a node and all ancestors up to and including
  191. // the root. Requires enable() to have been called previously.
  192. //
  193. // See: https://chromedevtools.github.io/devtools-protocol/tot/Accessibility#method-getAXNodeAndAncestors
  194. //
  195. // parameters:
  196. func GetAXNodeAndAncestors() *GetAXNodeAndAncestorsParams {
  197. return &GetAXNodeAndAncestorsParams{}
  198. }
  199. // WithNodeID identifier of the node to get.
  200. func (p GetAXNodeAndAncestorsParams) WithNodeID(nodeID cdp.NodeID) *GetAXNodeAndAncestorsParams {
  201. p.NodeID = nodeID
  202. return &p
  203. }
  204. // WithBackendNodeID identifier of the backend node to get.
  205. func (p GetAXNodeAndAncestorsParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *GetAXNodeAndAncestorsParams {
  206. p.BackendNodeID = backendNodeID
  207. return &p
  208. }
  209. // WithObjectID JavaScript object id of the node wrapper to get.
  210. func (p GetAXNodeAndAncestorsParams) WithObjectID(objectID runtime.RemoteObjectID) *GetAXNodeAndAncestorsParams {
  211. p.ObjectID = objectID
  212. return &p
  213. }
  214. // GetAXNodeAndAncestorsReturns return values.
  215. type GetAXNodeAndAncestorsReturns struct {
  216. Nodes []*Node `json:"nodes,omitempty,omitzero"`
  217. }
  218. // Do executes Accessibility.getAXNodeAndAncestors against the provided context.
  219. //
  220. // returns:
  221. //
  222. // nodes
  223. func (p *GetAXNodeAndAncestorsParams) Do(ctx context.Context) (nodes []*Node, err error) {
  224. // execute
  225. var res GetAXNodeAndAncestorsReturns
  226. err = cdp.Execute(ctx, CommandGetAXNodeAndAncestors, p, &res)
  227. if err != nil {
  228. return nil, err
  229. }
  230. return res.Nodes, nil
  231. }
  232. // GetChildAXNodesParams fetches a particular accessibility node by AXNodeId.
  233. // Requires enable() to have been called previously.
  234. type GetChildAXNodesParams struct {
  235. ID NodeID `json:"id"`
  236. FrameID cdp.FrameID `json:"frameId,omitempty,omitzero"` // The frame in whose document the node resides. If omitted, the root frame is used.
  237. }
  238. // GetChildAXNodes fetches a particular accessibility node by AXNodeId.
  239. // Requires enable() to have been called previously.
  240. //
  241. // See: https://chromedevtools.github.io/devtools-protocol/tot/Accessibility#method-getChildAXNodes
  242. //
  243. // parameters:
  244. //
  245. // id
  246. func GetChildAXNodes(id NodeID) *GetChildAXNodesParams {
  247. return &GetChildAXNodesParams{
  248. ID: id,
  249. }
  250. }
  251. // WithFrameID the frame in whose document the node resides. If omitted, the
  252. // root frame is used.
  253. func (p GetChildAXNodesParams) WithFrameID(frameID cdp.FrameID) *GetChildAXNodesParams {
  254. p.FrameID = frameID
  255. return &p
  256. }
  257. // GetChildAXNodesReturns return values.
  258. type GetChildAXNodesReturns struct {
  259. Nodes []*Node `json:"nodes,omitempty,omitzero"`
  260. }
  261. // Do executes Accessibility.getChildAXNodes against the provided context.
  262. //
  263. // returns:
  264. //
  265. // nodes
  266. func (p *GetChildAXNodesParams) Do(ctx context.Context) (nodes []*Node, err error) {
  267. // execute
  268. var res GetChildAXNodesReturns
  269. err = cdp.Execute(ctx, CommandGetChildAXNodes, p, &res)
  270. if err != nil {
  271. return nil, err
  272. }
  273. return res.Nodes, nil
  274. }
  275. // QueryAXTreeParams query a DOM node's accessibility subtree for accessible
  276. // name and role. This command computes the name and role for all nodes in the
  277. // subtree, including those that are ignored for accessibility, and returns
  278. // those that match the specified name and role. If no DOM node is specified, or
  279. // the DOM node does not exist, the command returns an error. If neither
  280. // accessibleName or role is specified, it returns all the accessibility nodes
  281. // in the subtree.
  282. type QueryAXTreeParams struct {
  283. NodeID cdp.NodeID `json:"nodeId,omitempty,omitzero"` // Identifier of the node for the root to query.
  284. BackendNodeID cdp.BackendNodeID `json:"backendNodeId,omitempty,omitzero"` // Identifier of the backend node for the root to query.
  285. ObjectID runtime.RemoteObjectID `json:"objectId,omitempty,omitzero"` // JavaScript object id of the node wrapper for the root to query.
  286. AccessibleName string `json:"accessibleName,omitempty,omitzero"` // Find nodes with this computed name.
  287. Role string `json:"role,omitempty,omitzero"` // Find nodes with this computed role.
  288. }
  289. // QueryAXTree query a DOM node's accessibility subtree for accessible name
  290. // and role. This command computes the name and role for all nodes in the
  291. // subtree, including those that are ignored for accessibility, and returns
  292. // those that match the specified name and role. If no DOM node is specified, or
  293. // the DOM node does not exist, the command returns an error. If neither
  294. // accessibleName or role is specified, it returns all the accessibility nodes
  295. // in the subtree.
  296. //
  297. // See: https://chromedevtools.github.io/devtools-protocol/tot/Accessibility#method-queryAXTree
  298. //
  299. // parameters:
  300. func QueryAXTree() *QueryAXTreeParams {
  301. return &QueryAXTreeParams{}
  302. }
  303. // WithNodeID identifier of the node for the root to query.
  304. func (p QueryAXTreeParams) WithNodeID(nodeID cdp.NodeID) *QueryAXTreeParams {
  305. p.NodeID = nodeID
  306. return &p
  307. }
  308. // WithBackendNodeID identifier of the backend node for the root to query.
  309. func (p QueryAXTreeParams) WithBackendNodeID(backendNodeID cdp.BackendNodeID) *QueryAXTreeParams {
  310. p.BackendNodeID = backendNodeID
  311. return &p
  312. }
  313. // WithObjectID JavaScript object id of the node wrapper for the root to
  314. // query.
  315. func (p QueryAXTreeParams) WithObjectID(objectID runtime.RemoteObjectID) *QueryAXTreeParams {
  316. p.ObjectID = objectID
  317. return &p
  318. }
  319. // WithAccessibleName find nodes with this computed name.
  320. func (p QueryAXTreeParams) WithAccessibleName(accessibleName string) *QueryAXTreeParams {
  321. p.AccessibleName = accessibleName
  322. return &p
  323. }
  324. // WithRole find nodes with this computed role.
  325. func (p QueryAXTreeParams) WithRole(role string) *QueryAXTreeParams {
  326. p.Role = role
  327. return &p
  328. }
  329. // QueryAXTreeReturns return values.
  330. type QueryAXTreeReturns struct {
  331. Nodes []*Node `json:"nodes,omitempty,omitzero"` // A list of Accessibility.AXNode matching the specified attributes, including nodes that are ignored for accessibility.
  332. }
  333. // Do executes Accessibility.queryAXTree against the provided context.
  334. //
  335. // returns:
  336. //
  337. // nodes - A list of Accessibility.AXNode matching the specified attributes, including nodes that are ignored for accessibility.
  338. func (p *QueryAXTreeParams) Do(ctx context.Context) (nodes []*Node, err error) {
  339. // execute
  340. var res QueryAXTreeReturns
  341. err = cdp.Execute(ctx, CommandQueryAXTree, p, &res)
  342. if err != nil {
  343. return nil, err
  344. }
  345. return res.Nodes, nil
  346. }
  347. // Command names.
  348. const (
  349. CommandDisable = "Accessibility.disable"
  350. CommandEnable = "Accessibility.enable"
  351. CommandGetPartialAXTree = "Accessibility.getPartialAXTree"
  352. CommandGetFullAXTree = "Accessibility.getFullAXTree"
  353. CommandGetRootAXNode = "Accessibility.getRootAXNode"
  354. CommandGetAXNodeAndAncestors = "Accessibility.getAXNodeAndAncestors"
  355. CommandGetChildAXNodes = "Accessibility.getChildAXNodes"
  356. CommandQueryAXTree = "Accessibility.queryAXTree"
  357. )