accessibility.go 14 KB

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