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