├── .github └── workflows │ ├── publish.yml │ ├── static.yml │ └── test.yml ├── .gitignore ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── SUPPORT.md ├── ariaNotify-polyfill.js ├── examples ├── ariaNotify-polyfill.js ├── index.html ├── kanban │ ├── ariaNotify-polyfill.js │ └── index.html └── suggested-text │ ├── ariaNotify-polyfill.js │ └── index.html ├── package-lock.json ├── package.json ├── playwright.config.mjs ├── tests ├── guidepup │ ├── nvda.spec.mjs │ └── voiceover.spec.mjs └── web-test-runner │ ├── ariaNotify-polyfill.js │ ├── ariaNotify-polyfill.test.js │ ├── live-region-placement-body.test.html │ ├── live-region-placement-dialog-role.test.html │ └── live-region-placement-dialog.test.html └── web-test-runner.config.js /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | permissions: 8 | contents: read 9 | id-token: write 10 | 11 | jobs: 12 | test: 13 | name: Test 14 | uses: github/ariaNotify-polyfill/.github/workflows/test.yml@main 15 | secrets: inherit 16 | publish-npm: 17 | needs: [test] 18 | name: Publish to npm 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | - uses: actions/setup-node@v4 23 | with: 24 | node-version: 22 25 | registry-url: https://registry.npmjs.org/ 26 | cache: npm 27 | - run: npm ci --legacy-peer-deps 28 | - run: npm version ${TAG_NAME} --git-tag-version=false 29 | env: 30 | TAG_NAME: ${{ github.event.release.tag_name }} 31 | - run: npm whoami; npm --ignore-scripts publish --provenance --access public 32 | env: 33 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 34 | -------------------------------------------------------------------------------- /.github/workflows/static.yml: -------------------------------------------------------------------------------- 1 | # Simple workflow for deploying static content to GitHub Pages 2 | name: Deploy static content to Pages 3 | 4 | on: 5 | # Runs on pushes targeting the default branch 6 | push: 7 | branches: ["main"] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 13 | permissions: 14 | contents: read 15 | pages: write 16 | id-token: write 17 | 18 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. 19 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. 20 | concurrency: 21 | group: "pages" 22 | cancel-in-progress: false 23 | 24 | jobs: 25 | # Single deploy job since we're just deploying 26 | deploy: 27 | environment: 28 | name: github-pages 29 | url: ${{ steps.deployment.outputs.page_url }} 30 | runs-on: ubuntu-latest 31 | steps: 32 | - name: Checkout 33 | uses: actions/checkout@v4 34 | - name: Setup Pages 35 | uses: actions/configure-pages@v5 36 | - name: Upload artifact 37 | uses: actions/upload-pages-artifact@v3 38 | with: 39 | # Upload entire repository 40 | path: 'examples' 41 | - name: Deploy to GitHub Pages 42 | id: deployment 43 | uses: actions/deploy-pages@v4 44 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | workflow_call: 5 | pull_request: 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | test: 12 | name: Test 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | - uses: actions/setup-node@v4 17 | with: 18 | node-version: 22 19 | - run: npm ci --legacy-peer-deps 20 | - run: npm test -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | test-results 3 | coverage -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @github/accessibility-reviewers 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at . All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | [fork]: https://github.com/github/ariaNotify-polyfill/fork 4 | [pr]: https://github.com/github/ariaNotify-polyfill/compare 5 | 6 | Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. 7 | 8 | Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE.txt). 9 | 10 | Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. 11 | 12 | ## Submitting a pull request 13 | 14 | 1. [Fork][fork] and clone the repository 15 | 1. Configure and install the dependencies: `npm install` 16 | 1. Make sure the tests pass on your machine: `npm run test` 17 | 1. Create a new branch: `git checkout -b my-branch-name` 18 | 1. Make your change, add tests, and make sure the tests and linter still pass 19 | 1. Push to your fork and [submit a pull request][pr] 20 | 1. Pat yourself on the back and wait for your pull request to be reviewed and merged. 21 | 22 | Here are a few things you can do that will increase the likelihood of your pull request being accepted: 23 | 24 | - Write tests. 25 | - Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. 26 | - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). 27 | 28 | ## Resources 29 | 30 | - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) 31 | - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) 32 | - [GitHub Help](https://help.github.com) 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 GitHub 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ariaNotify-polyfill 2 | 3 | Polyfill for the [ARIA Notification API](https://github.com/WICG/accessible-notifications/blob/main/README.md) 4 | 5 | The goal of this library is to polyfill `ariaNotify` so that it can be used seamlessly across browsers that support the native functionality, and those that don't. This adds the `Element.prototype.ariaNotify` function if it does not exist, emulating the native functionality. 6 | 7 | This is used in production on github.com. 8 | 9 | ## Background 10 | 11 | In browsers where `ariaNotify` is supported it will emit a notification event. In browsers where it isn't supported this library will create a "fake" element that is an aria-live region, insert it into the DOM, and modify the text content of the element to place the given message in, achieving a similar effect to the native functionality. 12 | 13 | ## Requirements 14 | 15 | This is only meant to be used in a browser context. It should not be used on the server. To install this you will likely need `npm`. 16 | 17 | ```sh 18 | $ npm i @github/ariaNotify-polyfill 19 | ``` 20 | 21 | In your JavaScript you can introduce the polyfill using a "bare" import: 22 | 23 | ```js 24 | import "@github/ariaNotify-polyfill" 25 | ``` 26 | 27 | Then continue to use `ariaNotify` as if it were supported everywhere. A small contrived example: 28 | 29 | ```js 30 | button.ariaNotify("Saved") 31 | ``` 32 | 33 | ## License 34 | 35 | This project is licensed under the terms of the MIT open source license. Please refer to [MIT](./LICENSE) for the full terms. 36 | 37 | ## Maintainers 38 | 39 | The @github/accessibility and @github/primer teams maintain this library. 40 | 41 | ## Support 42 | 43 | This library is provided "as is". Please feel free to file issues; however, we offer no time frame for correspondence or resolution of any issues. 44 | 45 | ## Acknowledgement 46 | 47 | Special thanks to Microsoft and the ARIA Working Group for making `ariaNotify` a possibility. 48 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | Thanks for helping make GitHub safe for everyone. 2 | 3 | # Security 4 | 5 | GitHub takes the security of our software products and services seriously, including all of the open source code repositories managed through our GitHub organizations, such as [GitHub](https://github.com/GitHub). 6 | 7 | Even though [open source repositories are outside of the scope of our bug bounty program](https://bounty.github.com/index.html#scope) and therefore not eligible for bounty rewards, we will ensure that your finding gets passed along to the appropriate maintainers for remediation. 8 | 9 | ## Reporting Security Issues 10 | 11 | If you believe you have found a security vulnerability in any GitHub-owned repository, please report it to us through coordinated disclosure. 12 | 13 | **Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.** 14 | 15 | Instead, please send an email to opensource-security[@]github.com. 16 | 17 | Please include as much of the information listed below as you can to help us better understand and resolve the issue: 18 | 19 | * The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting) 20 | * Full paths of source file(s) related to the manifestation of the issue 21 | * The location of the affected source code (tag/branch/commit or direct URL) 22 | * Any special configuration required to reproduce the issue 23 | * Step-by-step instructions to reproduce the issue 24 | * Proof-of-concept or exploit code (if possible) 25 | * Impact of the issue, including how an attacker might exploit the issue 26 | 27 | This information will help us triage your report more quickly. 28 | 29 | ## Policy 30 | 31 | See [GitHub's Safe Harbor Policy](https://docs.github.com/en/site-policy/security-policies/github-bug-bounty-program-legal-safe-harbor#1-safe-harbor-terms) 32 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support 2 | 3 | ## How to file issues and get help 4 | 5 | This project uses GitHub issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or feature request as a new issue. 6 | 7 | For help or questions about using this project, please reach out [on the discussions page](https://github.com/github/ariaNotify-polyfill/discussions). 8 | 9 | ariaNotify-polyfill is under active development and maintained by GitHub staff **AND THE COMMUNITY**. We will do our best to respond to support, feature requests, and community questions in a timely manner. 10 | 11 | ## GitHub Support Policy 12 | 13 | Support for this project is limited to the resources listed above. 14 | -------------------------------------------------------------------------------- /ariaNotify-polyfill.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | if (!("ariaNotify" in Element.prototype)) { 4 | /** @type {string} */ 5 | let uniqueId = `${Date.now()}`; 6 | try { 7 | uniqueId = crypto.randomUUID(); 8 | } catch { } 9 | 10 | /** 11 | * A unique symbol to prevent unauthorized access to the 'live-region' element. 12 | * @type {Symbol} 13 | */ 14 | const passkey = Symbol(); 15 | 16 | /** @type {string} */ 17 | const liveRegionCustomElementName = `live-region-${uniqueId}`; 18 | 19 | /** 20 | * @param {number} ms 21 | * @returns {Promise} 22 | */ 23 | function sleep(ms) { 24 | return new Promise((resolve) => setTimeout(resolve, ms)); 25 | } 26 | 27 | class Message { 28 | /** @type {Element} */ 29 | element; 30 | 31 | /** @type {string} */ 32 | message; 33 | 34 | /** @type {"high" | "normal"} */ 35 | priority = "normal"; 36 | 37 | /** 38 | * @param {object} message 39 | * @param {Element} message.element 40 | * @param {string} message.message 41 | * @param {"high" | "normal"} message.priority 42 | */ 43 | constructor({ element, message, priority = "normal" }) { 44 | this.element = element; 45 | this.message = message; 46 | this.priority = priority; 47 | } 48 | 49 | /** 50 | * Whether this message can be announced. 51 | * @returns {boolean} 52 | */ 53 | #canAnnounce() { 54 | return ( 55 | this.element.isConnected && 56 | // Elements within inert containers should not be announced. 57 | !this.element.closest("[inert]") && 58 | // If there is a modal element on the page, everything outside of it is implicitly inert. 59 | // This can be checked by seeing if the element is within the modal, if the modal is present. 60 | (this.element.ownerDocument 61 | .querySelector(":modal") 62 | ?.contains(this.element) ?? 63 | true) 64 | ); 65 | } 66 | 67 | /** @returns {Promise} */ 68 | async announce() { 69 | // Skip an unannounceable message. 70 | if (!this.#canAnnounce()) { 71 | return; 72 | } 73 | 74 | // Get root element 75 | let root = /** @type {Element} */ ( 76 | this.element.closest("dialog") || this.element.closest("[role='dialog']") || this.element.getRootNode() 77 | ); 78 | if (!root || root instanceof Document) root = document.body; 79 | 80 | // Get 'live-region', if it already exists 81 | /** @type {LiveRegionCustomElement | null} */ 82 | let liveRegion = root.querySelector(liveRegionCustomElementName); 83 | 84 | // Create (or recreate) 'live-region', if it doesn’t exist 85 | if (!liveRegion) { 86 | liveRegion = /** @type {LiveRegionCustomElement} */ ( 87 | document.createElement(liveRegionCustomElementName) 88 | ); 89 | root.append(liveRegion); 90 | } 91 | 92 | await sleep(250); 93 | liveRegion.handleMessage(passkey, this.message); 94 | } 95 | } 96 | 97 | const queue = new (class MessageQueue { 98 | /** @type {Message[]} */ 99 | #queue = []; 100 | 101 | /** @type {Message | undefined | null} */ 102 | #currentMessage; 103 | 104 | /** 105 | * Add the given message to the queue. 106 | * @param {Message} message 107 | * @returns {void} 108 | */ 109 | enqueue(message) { 110 | const { priority } = message; 111 | 112 | if (priority === "high") { 113 | // Insert after the last high-priority message, or at the beginning 114 | // @ts-ignore: ts(2550) 115 | const lastHighPriorityMessage = this.#queue.findLastIndex( 116 | (message) => message.priority === "high" 117 | ); 118 | this.#queue.splice(lastHighPriorityMessage + 1, 0, message); 119 | } else { 120 | // Insert at the end 121 | this.#queue.push(message); 122 | } 123 | 124 | if (!this.#currentMessage) { 125 | this.#processNext(); 126 | } 127 | } 128 | 129 | async #processNext() { 130 | this.#currentMessage = this.#queue.shift(); 131 | if (!this.#currentMessage) return; 132 | await this.#currentMessage.announce(); 133 | this.#processNext(); 134 | } 135 | })(); 136 | 137 | class LiveRegionCustomElement extends HTMLElement { 138 | #shadowRoot = this.attachShadow({ mode: "closed" }); 139 | 140 | connectedCallback() { 141 | this.ariaLive = "polite"; 142 | this.ariaAtomic = "true"; 143 | this.style.marginLeft = "-1px"; 144 | this.style.marginTop = "-1px"; 145 | this.style.position = "absolute"; 146 | this.style.width = "1px"; 147 | this.style.height = "1px"; 148 | this.style.overflow = "hidden"; 149 | this.style.clipPath = "rect(0 0 0 0)"; 150 | this.style.overflowWrap = "normal"; 151 | } 152 | 153 | /** 154 | * @param {Symbol | null} key 155 | * @param {string} message 156 | */ 157 | handleMessage(key = null, message = "") { 158 | if (passkey !== key) return; 159 | // This is a hack due to the way the aria live API works. A screen reader 160 | // will not read a live region again if the text is the same. Adding a 161 | // space character tells the browser that the live region has updated, 162 | // which will cause it to read again, but with no audible difference. 163 | if (this.#shadowRoot.textContent == message) message += "\u00A0"; 164 | this.#shadowRoot.textContent = message; 165 | } 166 | } 167 | customElements.define(liveRegionCustomElementName, LiveRegionCustomElement); 168 | 169 | /** 170 | * @param {string} message 171 | * @param {object} options 172 | * @param {"high" | "normal"} [options.priority] 173 | */ 174 | Element.prototype["ariaNotify"] = function ( 175 | message, 176 | { priority = "normal" } = {} 177 | ) { 178 | queue.enqueue(new Message({ element: this, message, priority })); 179 | }; 180 | } 181 | -------------------------------------------------------------------------------- /examples/ariaNotify-polyfill.js: -------------------------------------------------------------------------------- 1 | ../ariaNotify-polyfill.js -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ariaNotify Polyfill Examples 5 | 28 | 29 | 30 |
31 |

ariaNotify Polyfill Examples

32 |

33 | ariaNotify is a new API for announcing notifications to assistive technologies. 34 | It allows developers to queue individual notifications using different queing strategies. 35 | Try it out below! 36 |

37 |

38 | View the code on GitHub: 39 | github/ariaNotify-polyfill 42 | (Only accessible to GitHub employees, for now) 43 |

44 | 45 |

Example components

46 | 50 | 51 |

Playground

52 |

53 | This playground allows you to queue a set of messages of different types, and then dispatch them all at once to see 54 | how priority effects the queue order. 55 |

56 | 57 | 75 | 76 | 77 | 78 | 79 | 80 |
    81 |
82 | 83 |

84 | Pressing enqueue will dispatch all ariaNotify() method calls, at once, on the button. 85 |

86 | 87 |
88 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /examples/kanban/ariaNotify-polyfill.js: -------------------------------------------------------------------------------- 1 | ../../ariaNotify-polyfill.js -------------------------------------------------------------------------------- /examples/kanban/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Kanban - ariaNotify Polyfill Examples 5 | 6 | 7 |
8 |

ariaNotify Polyfill Examples - Kanban

9 | 10 | 59 | 60 | 63 | 129 |
    130 |
  1. 131 |

    To Do

    132 |
      133 |
    1. Implement drag and drop
    2. 134 |
    3. Add drag and drop announcements
    4. 135 |
    5. Publish to GitHub pages?
    6. 136 |
    137 |
  2. 138 |
  3. 139 |

    Doing

    140 |
      141 |
    1. Figure out CSS grid
    2. 142 |
    143 |
  4. 144 |
  5. 145 |

    Done

    146 |
      147 |
    1. Create a repo
    2. 148 |
    3. Create "examples" directory
    4. 149 |
    150 |
  6. 151 |
152 |
153 |
154 |
155 | 289 | 304 | 305 | 306 | 307 | -------------------------------------------------------------------------------- /examples/suggested-text/ariaNotify-polyfill.js: -------------------------------------------------------------------------------- 1 | ../../ariaNotify-polyfill.js -------------------------------------------------------------------------------- /examples/suggested-text/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Suggested Text - ariaNotify Polyfill Examples 6 | 42 | 43 | 44 |
45 | 46 |
47 | 48 | 81 | 82 | 83 | 84 |
85 |
86 | 114 | 233 | 418 | 419 | 420 | 421 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@github/arianotify-polyfill", 3 | "version": "0.0.0-development", 4 | "description": "Polyfill for the ARIA Notification API", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/github/ariaNotify-polyfill.git" 8 | }, 9 | "keywords": [], 10 | "license": "MIT", 11 | "author": "GitHub Inc.", 12 | "main": "ariaNotify-polyfill.js", 13 | "module": "ariaNotify-polyfill.js", 14 | "type": "module", 15 | "directories": { 16 | "example": "examples" 17 | }, 18 | "files": [], 19 | "scripts": { 20 | "test": "web-test-runner", 21 | "test:guidepup": "npx playwright test" 22 | }, 23 | "devDependencies": { 24 | "@esm-bundle/chai": "^4.3.4-fix.0", 25 | "@guidepup/guidepup": "^0.24.0", 26 | "@guidepup/playwright": "^0.14.1", 27 | "@playwright/test": "^1.48.0", 28 | "@web/test-runner": "^0.20.1" 29 | } 30 | } -------------------------------------------------------------------------------- /playwright.config.mjs: -------------------------------------------------------------------------------- 1 | import { screenReaderConfig } from "@guidepup/playwright"; 2 | import { devices } from "@playwright/test"; 3 | import * as url from "node:url"; 4 | 5 | const config = { 6 | ...screenReaderConfig, 7 | reportSlowTests: null, 8 | timeout: 3 * 60 * 1000, 9 | retries: 0, 10 | projects: [ 11 | { 12 | name: "Microsoft Edge", 13 | use: { 14 | ...devices["Desktop Edge"], 15 | channel: "msedge", 16 | }, 17 | }, 18 | ], 19 | quiet: false, 20 | }; 21 | 22 | export default config; 23 | -------------------------------------------------------------------------------- /tests/guidepup/nvda.spec.mjs: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import { test as baseTest, expect } from "@playwright/test"; 4 | import { nvda, WindowsKeyCodes, WindowsModifiers } from "@guidepup/guidepup"; 5 | import path from "node:path"; 6 | 7 | // Pre-requisites: 8 | // - Install NVDA 9 | // - Install the NVDA Remote Access addon (https://nvdaremote.com/download/) 10 | // - In NVDA Tools > Remote > Options…: 11 | // - Check "Auto-connect to control server on startup" 12 | // - Select "Host control server" 13 | // - Set "Port" to "6837" 14 | // - Set "Key" to "guidepup" 15 | // (settings are from https://github.com/guidepup/nvda/blob/main/nvda/userConfig/remote.ini) 16 | // - In Windows Settings, turn on “Developer Mode” (this allows symbolic links) 17 | // - In an PowerShell (Administrator session): 18 | // - Run `mkdir "C:\Program Files (x86)\NVDA\userConfig"` 19 | // - Run `cmd /c mklink /d "C:\Program Files (x86)\NVDA\userConfig\addons" "%APPDATA%\nvda\addons"` 20 | // - Check out this repo 21 | // - In cmd: 22 | // - Run `REG ADD HKCU\Software\Guidepup\Nvda` 23 | // - Run `REG ADD HKCU\Software\Guidepup\Nvda /v guidepup_nvda_0.1.1-2021.3.1 /t REG_SZ /d "C:\Program Files (x86)\NVDA\\"` 24 | // (version is from https://github.com/guidepup/setup/blob/82179ec8915680344d0db320422dd18e29593eb9/package.json#L60C27-L60C41) 25 | 26 | const test = baseTest.extend({ 27 | context: async ({ context }, run) => { 28 | await context.route("**/*", (route, request) => 29 | route.fulfill({ 30 | path: path.join( 31 | import.meta.dirname, 32 | "..", 33 | new URL(request.url()).pathname 34 | ), 35 | }) 36 | ); 37 | await run(context); 38 | }, 39 | }); 40 | 41 | if (process.platform === "win32") { 42 | test.beforeEach(async ({ page }) => { 43 | // Navigate to suggested test example page 44 | await page.goto( 45 | "http://localhost:3333/examples/suggested-text/index.html", 46 | { 47 | waitUntil: "load", 48 | } 49 | ); 50 | 51 | // Start NVDA 52 | await nvda.start(); 53 | 54 | // Adapted from https://github.com/guidepup/guidepup-playwright/blob/34c3973dd98e19c81f468352e13bac5b8434b28f/src/nvdaTest.ts#L137-L167: 55 | 56 | // Make sure NVDA is not in focus mode. 57 | await nvda.perform(nvda.keyboardCommands.exitFocusMode); 58 | 59 | // Ensure the document is ready and focused. 60 | await page.bringToFront(); 61 | await page.locator("body").waitFor(); 62 | await page.locator("body").focus(); 63 | 64 | // Navigate to the beginning of the web content. 65 | await nvda.perform(nvda.keyboardCommands.readNextFocusableItem); 66 | await nvda.perform(nvda.keyboardCommands.toggleBetweenBrowseAndFocusMode); 67 | await nvda.perform(nvda.keyboardCommands.toggleBetweenBrowseAndFocusMode); 68 | await nvda.perform(nvda.keyboardCommands.exitFocusMode); 69 | await nvda.perform({ 70 | keyCode: [WindowsKeyCodes.Home], 71 | modifiers: [WindowsModifiers.Control], 72 | }); 73 | 74 | // Clear out logs. 75 | await nvda.clearItemTextLog(); 76 | await nvda.clearSpokenPhraseLog(); 77 | }); 78 | 79 | test.afterEach(async () => { 80 | // Stop NVDA; suppressing errors 81 | try { 82 | await nvda.stop(); 83 | } catch {} 84 | }); 85 | 86 | test("SuggestedText", async ({ page }) => { 87 | // Type a completable string in the textarea 88 | await nvda.type("a"); 89 | 90 | // Wait for the suggestion to appear 91 | await page.waitForTimeout(4000); 92 | 93 | // Assert that the spoken phrases are as expected 94 | const spokenPhraseLog = JSON.stringify(await nvda.spokenPhraseLog()); 95 | expect(spokenPhraseLog.includes("Suggestion: acceptable")).toBe(true); 96 | // expect(spokenPhraseLog.includes("Press right arrow to commit suggestion")).toBe(true); // FIXME: Commenting because this fails, though it _should_ pass. 97 | }); 98 | } else { 99 | test("Skipping Windows tests", () => {}); 100 | } 101 | -------------------------------------------------------------------------------- /tests/guidepup/voiceover.spec.mjs: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import { test as baseTest, expect } from "@playwright/test"; 4 | import { voiceOver } from "@guidepup/guidepup"; 5 | import path from "node:path"; 6 | 7 | // Pre-requisites: 8 | // - Run `defaults write com.apple.VoiceOver4/default SCREnableAppleScript 1` 9 | 10 | const test = baseTest.extend({ 11 | context: async ({ context }, run) => { 12 | await context.route("**/*", (route, request) => 13 | route.fulfill({ 14 | path: path.join( 15 | import.meta.dirname, 16 | "..", 17 | new URL(request.url()).pathname 18 | ), 19 | }) 20 | ); 21 | await run(context); 22 | }, 23 | }); 24 | 25 | if (process.platform === "darwin") { 26 | test.beforeAll(async () => { 27 | // Start VoiceOver 28 | await voiceOver.start(); 29 | }); 30 | 31 | test.beforeEach(async ({ page }) => { 32 | // Navigate to suggested text example page 33 | await page.goto( 34 | "http://localhost:3333/examples/suggested-text/index.html", 35 | { 36 | waitUntil: "load", 37 | } 38 | ); 39 | 40 | // From https://github.com/guidepup/guidepup-playwright/blob/34c3973dd98e19c81f468352e13bac5b8434b28f/src/voiceOverTest.ts#L97-L110: 41 | 42 | // Ensure the document is ready and focused. 43 | await page.bringToFront(); 44 | await page.locator("body").waitFor(); 45 | await page.locator("body").focus(); 46 | 47 | // Navigate to the beginning of the web content. 48 | await voiceOver.interact(); 49 | await voiceOver.perform(voiceOver.keyboardCommands.jumpToLeftEdge); 50 | 51 | // Clear out logs. 52 | await voiceOver.clearItemTextLog(); 53 | await voiceOver.clearSpokenPhraseLog(); 54 | }); 55 | 56 | test.afterAll(async () => { 57 | // Stop VoiceOver 58 | await voiceOver.stop(); 59 | }); 60 | 61 | test("SuggestedText", async ({ page }) => { 62 | // Type a completable string in the textarea 63 | await voiceOver.type("a"); 64 | 65 | // Wait for the suggestion to appear 66 | await page.waitForTimeout(4000); 67 | 68 | // Assert that the spoken phrases are as expected 69 | const lastSpokenPhrase = await voiceOver.lastSpokenPhrase(); 70 | expect(lastSpokenPhrase.startsWith("a")).toBe(true); 71 | expect(lastSpokenPhrase.includes("Suggestion: acceptable")).toBe(true); 72 | expect( 73 | lastSpokenPhrase.includes("Press right arrow to commit suggestion") 74 | ).toBe(true); 75 | }); 76 | } else { 77 | test("Skipping macOS tests", () => {}); 78 | } 79 | -------------------------------------------------------------------------------- /tests/web-test-runner/ariaNotify-polyfill.js: -------------------------------------------------------------------------------- 1 | ../../ariaNotify-polyfill.js -------------------------------------------------------------------------------- /tests/web-test-runner/ariaNotify-polyfill.test.js: -------------------------------------------------------------------------------- 1 | import { expect } from "@esm-bundle/chai"; 2 | 3 | export async function tests() { 4 | describe("ariaNotify polyfill", () => { 5 | it(" placement", () => { 6 | let count = 0; 7 | for (const container of document.querySelectorAll("[data-should-contain-live-region]")) { 8 | container.ariaNotify("Hello, world!"); 9 | const liveRegion = Array.from(container.childNodes).find((node) => node.nodeType === Node.ELEMENT_NODE && node.tagName.match(/^live-region/i)); 10 | expect(liveRegion).to.not.be.undefined; 11 | count++; 12 | } 13 | expect(count).to.be.above(0); 14 | }); 15 | }); 16 | } -------------------------------------------------------------------------------- /tests/web-test-runner/live-region-placement-body.test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/web-test-runner/live-region-placement-dialog-role.test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | 6 | -------------------------------------------------------------------------------- /tests/web-test-runner/live-region-placement-dialog.test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /web-test-runner.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | files: "tests/web-test-runner/*.test.html", 3 | coverage: true, 4 | nodeResolve: true, 5 | plugins: [ 6 | { 7 | name: "include-polyfill", 8 | transform(context) { 9 | if (context.response.is("html")) { 10 | return context.body.replace( 11 | /<\/body>/, 12 | ` 13 | 14 | 19 | 20 | ` 21 | ); 22 | } 23 | }, 24 | }, 25 | ], 26 | }; --------------------------------------------------------------------------------