FDE Times dataFDE jobs open 932▼14 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 62Companies hiring 202Remote-friendly 24%Median US pay $201kTop hirer Databricks 92
中文VI

The newspaper of the Forward Deployed Engineer

Books & courses

Why a working chatbot can stay silent to a screen reader

The culprit may be an announcement region created too late, a fault that anyone looking at the screen will struggle to notice.

ShareLinkedInFacebookX

In brief

  • A live region must be in the DOM when the page loads; otherwise its content may not be read correctly.
  • For LLM chat, Eric Bailey advises waiting until the stream finishes before announcing the whole message.
  • Automated testing is a first step; the chat flow still has to be tried with a keyboard and a screen reader.
Comparison of two ways to set up a live region across three points: page load, first chunk and stream end. If the region is created only when the first chunk arrives, screen reader users may hear nothing. If an empty region exists from page load and receives the content once streaming ends, they hear the whole answer in one go.
Put an empty live region in the HTML at page load, then add the answer only once streaming ends. Schematic, timing not to scale. Source: web.dev (Learn Accessibility), MDN, Eric Bailey in Smashing Magazine.

One line in the JavaScript module of Learn Accessibility deserves rereading before every chatbot demo: for content to be read correctly, the live region or alert must be present in the DOM from page load. A widget that creates the region only when the first answer arrives does the opposite.

Anyone looking at the screen will struggle to spot the fault, because the text keeps flowing. Someone listening through a screen reader may be told nothing at all. FDEs should find this kind of bug before the acceptance session, while the fix is still a matter of a few lines of code.

A course from 2022, a bug that persists

Carie Fisher wrote the course for web.dev. Seven modules launched first, with the rest planned for release in batches through the end of 2022; web.dev later announced that the full set was available. It covers the core knowledge needed to build accessible websites and web apps.

Several years on, it is still worth taking, because a chatbot is still made of HTML, focus and DOM updates. The skill it builds is a practical one for FDEs: putting an interface into a client’s environment without abandoning keyboard users.

Take it if you have written frontend code but never tried your product with a screen reader. Those who work only on the backend can start with the testing modules to learn how to run acceptance.

A sensible order for a busy FDE is ARIA and HTML, Keyboard focus, JavaScript, automated testing, then testing with assistive technology. The first three modules help you fix problems; the last two help you prove they are fixed.

First idea: less ARIA, correct focus

The ARIA and HTML module advises that in most cases HTML elements are fine to use as they are. Applied to your code, that means the send button should be a button and the input box a labeled textarea. Clear out any div posing as a button before you add a single attribute.

Focus comes next. Fisher requires the default order to be logical, intuitive and consistent with the visual order; in a modal, keyboard users must not be able to slip out until they choose to close it.

Check that second rule first in the dialog where an agent asks permission to act: if the Tab key slides into the background, users can lose track of the decision waiting for them.

A chat panel beside the page, however, is not necessarily a modal, and users need to move between question and answer. Eric Bailey, in Smashing Magazine, describes using F6 and Shift+F6 to jump from the input box to the LLM’s response and back.

Try this shortcut in the client’s build once the Tab order is right.

Second idea: stream for the eye, read once for the ear

Correct focus is still insufficient, because new messages appear where focus is not.

WCAG 2.2 criterion 4.1.3, at level AA, requires status messages to be determinable through a role or properties, so that assistive technology can present them without their receiving focus.

So do not move focus to a “processing” line just to make the screen reader say it.

The W3C has a pattern close to chat: technique ARIA23 puts role="log" on the history area so that new messages are announced.

For LLM chat, Bailey goes further: wait until a message has finished streaming, then announce all of it through a separate live region instead of aria-live on each message. Both approaches aim to let users hear new messages; Bailey’s waits until the answer is complete.

Take a hypothetical answer made up of 120 streamed chunks. The visible area updates 120 times; if that area is itself the live region, the screen reader may have to process all 120 updates. Under Bailey’s advice, the announcement region receives content only once.

The abridged code below keeps the two paths apart. renderVisible is the application’s display function, and visually-hidden is a CSS class that hides the region from sight while leaving it available to screen readers:

<div id="chat-history"></div>
<div id="announcer" aria-live="polite" class="visually-hidden"></div>
const announcer = document.querySelector('#announcer');

async function showReply(stream) {
  let reply = '';
  announcer.textContent = '';
  try {
    for await (const chunk of stream) {
      reply += chunk;
      renderVisible(reply);
    }
    announcer.textContent = reply;
  } catch (error) {
    const status = 'The answer was interrupted. Please send your question again.';
    const message = reply ? `${reply}\n\n${status}` : status;
    renderVisible(message);
    announcer.textContent = message;
  }
}

The announcer region is empty but present from the start, in line with MDN’s advice: create it first, let assistive technology notice it, and only then update it.

The region is cleared before each turn, so two identical answers still produce two updates. If the connection drops, it receives what is showing on screen: the part of the answer that arrived, followed by the error line.

If you also add role="log" to the chat history, a message risks being read twice. Choose one mechanism, then test it for real.

Third idea: a green scan does not mean done

How do you know the code above works? The course treats automated testing as a very good starting point, but not every check can be automated.

The module on assistive technology sets a clear goal: when testing with a screen reader, you are looking for faults in the code that get in the way of use.

On site, turn that into a short script: open the chat, send a question, listen to the answer, move to the response, return to the input box, then close a confirmation dialog. No mouse.

Agree on the script with the client before acceptance day, on the very build they will receive, and record the browser and screen reader their users have. “Pass” then means the same thing to both sides.

For the 120-chunk answer above, one line of the bug log looks like this:

Step Expected Heard Cause
Send a question, wait for the stream to end, press no other key The whole answer, once Nothing The announcement region is created only when the first chunk arrives

The last column, filled in after tracing the code, shows where to make the fix: put the empty region in the initial HTML, then rerun the same step in front of the client. The first step where what you hear departs from what you expect is the bug to fix first.

The script is also better professional evidence than the name of a course. In job postings, look for phrases such as “WCAG”, “customer-facing UI” or “keyboard navigation”. On your CV, spell out the flow you tested, the bugs you found and the changes you made, with a link to code or video if permitted.

Before your next demo, switch off the screen, turn on the reader and fill in the “Heard” column down to the last step. Any cell where you have to write “nothing” marks a place where the client’s users may be left behind too.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
11 sources
Read next on the roadmap · Stage 1: FoundationsWhy backend engineers can skip to chapter 8 of Eloquent JavaScriptA script that delivers 960 orders but reports just one runs through four chapters on the skills that decide whether an integration works.