Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(accessibility): snapshot the accessibility tree #3470

Merged
merged 11 commits into from
Nov 2, 2018
51 changes: 51 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
* [page.$$eval(selector, pageFunction[, ...args])](#pageevalselector-pagefunction-args)
* [page.$eval(selector, pageFunction[, ...args])](#pageevalselector-pagefunction-args-1)
* [page.$x(expression)](#pagexexpression)
* [page.accessibility](#pageaccessibility)
* [page.addScriptTag(options)](#pageaddscripttagoptions)
* [page.addStyleTag(options)](#pageaddstyletagoptions)
* [page.authenticate(credentials)](#pageauthenticatecredentials)
Expand Down Expand Up @@ -156,6 +157,8 @@
* [worker.evaluateHandle(pageFunction, ...args)](#workerevaluatehandlepagefunction-args)
* [worker.executionContext()](#workerexecutioncontext)
* [worker.url()](#workerurl)
- [class: Accessibility](#class-accessibility)
* [accessibility.snapshot([options])](#accessibilitysnapshotoptions)
- [class: Keyboard](#class-keyboard)
* [keyboard.down(key[, options])](#keyboarddownkey-options)
* [keyboard.press(key[, options])](#keyboardpresskey-options)
Expand Down Expand Up @@ -1047,6 +1050,9 @@ The method evaluates the XPath expression.

Shortcut for [page.mainFrame().$x(expression)](#framexexpression)

#### page.accessibility
- returns: <[Accessibility]>

#### page.addScriptTag(options)
- `options` <[Object]>
- `url` <[string]> URL of a script to be added.
Expand Down Expand Up @@ -1982,6 +1988,50 @@ Shortcut for [(await worker.executionContext()).evaluateHandle(pageFunction, ...
#### worker.url()
- returns: <[string]>

### class: Accessibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might have wildly different output.

Blink - Chrome's rendering engine - has a concept of "accessibility tree", which is than translated into different platform-specific APIs. Accessibility namespace gives users
access to the Blink Accessibility Tree.

Most of the accessibility tree gets filtered out when converting from Blink AX Tree to Platform-specific AX-Tree or by screen readers themselves. By default, Puppeteer tries to approximate this filtering, exposing only the "interesting" nodes of the tree.


The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by assistive technology such as a [screen readers](https://en.wikipedia.org/wiki/Screen_reader).


#### accessibility.snapshot([options])
- `options` <[Object]>
- `interestingOnly` <[boolean]> Prune uninteresting nodes from the tree. Defaults to `true`.
JoelEinbinder marked this conversation as resolved.
Show resolved Hide resolved
- returns: <[Promise]<[Object]>>
JoelEinbinder marked this conversation as resolved.
Show resolved Hide resolved
- `role` <[string]> The [role](https://www.w3.org/TR/wai-aria/#usage_intro).
- `name` <[string]> A human readable name for the node.
- `value` <[string]|[number]> The current value of the node.
- `description` <[string]> An additional human readable description of the node.
- `keyshortcuts` <[string]> Keyboard shortcuts associated with this node.
- `roledescription` <[string]> A human readable alternative to the role.
- `valuetext` <[string]> A description of the current value.
- `disabled` <[boolean]> Whether the node is disabled.
- `expanded` <[boolean]> Whether the node is expanded or collapsed.
- `focused` <[boolean]> Whether the node is focused.
- `modal` <[boolean]> Whether the node is [modal](https://en.wikipedia.org/wiki/Modal_window).
- `multiline` <[boolean]> Whether the node text input supports multiline.
- `multiselectable` <[boolean]> Whether more than one child can be selected.
- `readonly` <[boolean]> Whether the node is read only.
- `required` <[boolean]> Whether the node is required.
- `selected` <[boolean]> Whether the node is selected in it's parent node.
JoelEinbinder marked this conversation as resolved.
Show resolved Hide resolved
- `checked` <[boolean]|[string]> Whether the checkbox is checked, or "mixed".
- `pressed` <[boolean]|[string]> Whether the checkbox is checked, or "mixed".
JoelEinbinder marked this conversation as resolved.
Show resolved Hide resolved
- `level` <[number]> The level of a heading.
- `valuemin` <[number]> The minimum value in a node.
- `valuemax` <[number]> the maximum value in a node.
JoelEinbinder marked this conversation as resolved.
Show resolved Hide resolved
- `autocomplete` <[string]> What kind of autocomplete is supported by a control.
- `hasPopup` <[string]> What kind of popup is currently being shown for a node.
JoelEinbinder marked this conversation as resolved.
Show resolved Hide resolved
- `invalid` <[string]> Whether and in what way is this node's value invalid.
JoelEinbinder marked this conversation as resolved.
Show resolved Hide resolved
- `orientation` <[string]> Whether the node is oriented horizontally or vertically.
- `children` <[Array]<[Object]>> Child nodes of this node, if any.
JoelEinbinder marked this conversation as resolved.
Show resolved Hide resolved

Captures the current state of the accessibility tree. The returned object represents the root
accessible node of the page.

```js
const snapshot = await page.accessibility.snapshot();
JoelEinbinder marked this conversation as resolved.
Show resolved Hide resolved
console.log(snapshot);
```

### class: Keyboard

Keyboard provides an api for managing a virtual keyboard. The high level api is [`keyboard.type`](#keyboardtypetext-options), which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page.
Expand Down Expand Up @@ -3431,3 +3481,4 @@ TimeoutError is emitted whenever certain operations are terminated due to timeou
[UnixTime]: https://en.wikipedia.org/wiki/Unix_time "Unix Time"
[SecurityDetails]: #class-securitydetails "SecurityDetails"
[Worker]: #class-worker "Worker"
[Accessibility]: #class-accessibility "Accessibility"