---
title: "What Playwright's accessibility tree missed on my Astro blog"
date: 2026-11-27
description: "A Playwright run against a site nothing had ever checked. Three defects, including a zero pixel gap the accessibility tree reported as healthy."
tags: ["playwright", "agents", "astro", "testing"]
draft: false
---

I pointed an agent at my own Astro blog, which nothing had ever checked, and it found
three defects in four minutes. One of them was two nodes the accessibility tree reported
as healthy, rendering flush against each other with a 0 pixel gap.

In [the post about driving Claude Code under tui-test](/posts/giving-agents-vision/) I
wrote a dozen broken terminal diagrams because I could not see them. The fix there was a
headless terminal and a per-cell attribute dump, which is a lot of machinery to recover
the fact that row 3 has a different background.

The web hands you that structure for free. Playwright returns an accessibility tree:
roles, names, nesting, hrefs. The agent does not reconstruct meaning from pixels, it
queries a tree. That turns out to be half the job: a tree of roles and names answers
whether a thing is present and has no opinion about how it sits. The web is the easy case
for structure, not for appearance.

Here is the run, so you can do it to your own site.

## Build it and serve the real output

Check the built site, not the dev server. The dev server transforms on request; the build
is what ships.

```sh
cd /path/to/your/astro-blog
npm ci && npm run build && npx astro preview --port 4321
```

```
06:15:27 [build] ✓ Completed in 322ms.
06:15:27 [raw-markdown] copied 1 raw markdown post(s) to posts/
06:15:27 [build] 3 page(s) built in 663ms
```

Astro 7.4.13, node v24.1.0. The first thing that happened was not in the plan: port 4321
answered 200 before my server started.

```
$ lsof -nP -iTCP:4321 -sTCP:LISTEN
node    41398 jonathan   15u  IPv4  TCP 127.0.0.1:4321 (LISTEN)
```

A preview daemon from a session two days earlier, still serving a `dist/` I had just
deleted. Every assertion below would have run against a stale build and passed or failed
for the wrong reason. `npx astro preview stop` and a `kill` on the orphan cleared it.

The general form of that trap: confirm the server you are talking to is the one you
started. A 200 is not evidence.

## Cheap checks first

Before the browser, curl. Status codes and content types need no DOM.

```sh
for p in / /posts/hello-world/ /no-such-page /posts/hello-world.md; do
  printf '%-24s ' "$p"
  curl -sS -o /dev/null \
    -w 'status=%{http_code}  type=%{content_type}\n' \
    "http://localhost:4321$p"
done
```

```
/                        status=200  type=text/html
/posts/hello-world/      status=200  type=text/html
/no-such-page            status=404  type=text/html
/posts/hello-world.md    status=200  type=text/markdown
```

This site copies each post's markdown source into the build so agents can read the source
instead of a re-serialization. The claim is that it is a byte copy, which is a claim with
a one-line test:

```sh
curl -sS http://localhost:4321/posts/hello-world.md -o served.md
shasum -a 256 served.md src/content/posts/hello-world.md
```

Both `c2e93e04...0eab`. Identical, frontmatter intact, served as `text/markdown`.

## The snapshot is the point

Now the browser. With the
[Playwright MCP server](https://github.com/microsoft/playwright-mcp)
(`npx -y @playwright/mcp@latest`, 0.0.86 as I write this), one navigate and one snapshot:

```
- banner:
  - link "Jonathan Laperle": /url: /
  - navigation:
    - link "github.com/laperlej": /url: https://github.com/laperlej
- main:
  - heading "Jonathan Laperle" [level=1]
  - paragraph: "Notes on software: what broke, what fixed it."
  - list:
    - listitem:
      - link "Hello world": /url: /posts/hello-world/
      - time: Nov 26, 2026
      - paragraph: Placeholder post. Delete this file once ...
- contentinfo:
  - paragraph: jonathanlaperle.com
```

That is the entire homepage in twelve lines. Landmarks are named, the heading level is
there, the post link carries its href. An agent can answer "does the index list posts"
without looking at an image. Compare [the terminal](/posts/zellij-plugin-testing/), where the
equivalent is a 110x30 grid of characters and you are grepping for a box-drawing
character.

Drive the page the way the tree describes it. `browser_click` on the post link navigates
by accessible name, and the post page comes back with its headings, its table as
`row`/`cell`, its code spans, and the `markdown source` link pointing at
`/posts/hello-world.md`. No selectors written by hand.

## Assert numbers, not impressions

Snapshots prove structure. For layout and theme, evaluate JavaScript and get back numbers
you can compare.

Dark theme, with `browser_emulate_media` set to `colorScheme: dark`:

```js
() => ({
  scheme: matchMedia('(prefers-color-scheme: dark)').matches
    ? 'dark'
    : 'light',
  bodyBg: getComputedStyle(document.body).backgroundColor,
  preBg: getComputedStyle(document.querySelector('pre')).backgroundColor,
})
```

```json
{"scheme": "dark",
 "bodyBg": "rgb(22, 22, 22)",
 "preBg": "rgb(36, 41, 46)"}
```

`#161616` for the page and `#24292e` for the code block, which is Shiki's github-dark
background. The dual-theme CSS works. That is a pass, stated with the value that makes it
checkable.

Phone width is where a number beats an eyeball. Resize to 400px and ask the document how
wide it is, then name the elements sticking out:

```js
() => {
  const de = document.documentElement;
  const offenders = [...document.querySelectorAll('body *')]
    .map(el => [el, el.getBoundingClientRect()])
    .filter(([, r]) => r.right > de.clientWidth + 0.5)
    .map(([el, r]) => ({
      tag: el.tagName,
      right: Math.round(r.right),
      text: el.textContent.slice(0, 40),
    }));
  return {
    viewport: de.clientWidth,
    scrollWidth: de.scrollWidth,
    offenders,
  };
}
```

```json
{"viewport": 400, "scrollWidth": 935,
 "offenders": [{"tag": "CODE", "right": 935,
                "text": "https://raw.githubusercontent.com/lape"}]}
```

535 pixels of horizontal scroll on the post page, from one inline `<code>` holding a long
URL with no break opportunity. The homepage at the same width reports `scrollWidth: 400`,
so this is content-dependent, not a broken container. One rule in `src/styles/global.css`
fixes it: `code { overflow-wrap: anywhere; }`.

## What the tree could not see

The 404 route returns status 404 with the custom page, and its tree is correct. Its title
is not:

```
Page Title: 404 &middot; Jonathan Laperle
```

In `src/pages/404.astro` the title was passed as a component attribute,
`<Base title="404 &middot; Jonathan Laperle">`, and Astro 7.4.13 escapes the ampersand on
that path: the built `404.html` carried
`<title>404 &amp;middot; Jonathan Laperle</title>`. The same entity in markdown body text
builds to a real `·`, which is why nobody notices; only the attribute path breaks.
Writing the character directly in the attribute fixes it.

The third one is the interesting one, because the accessibility tree reported it as
healthy:

```
- link "Hello world": /url: /posts/hello-world/
- time: Nov 26, 2026
```

Two nodes, correct roles, correct names. The screenshot showed `Hello worldNov 26, 2026`
with the title and date touching. Measuring confirmed it:

```json
{"linkRight": 123.52, "timeLeft": 123.52, "gapPx": 0}
```

The generated HTML was `</a><time>` with nothing between them, because Astro's JSX-style
templates strip whitespace between elements written on separate lines. An explicit
`{" "}` after the link in `src/pages/index.astro` puts the space back.

This is where the web and the terminal converge. Structured state, a tree or a grid of
cells, tells you what is present. It does not tell you how it looks, and a tree of roles
and names has no opinion about a zero pixel gap. You still have to render the artifact
and either look at it or measure it.

## What was fine

Most of it. Zero console errors on the homepage and the post page. The post page makes
two network requests, the HTML and `site.webmanifest`, with zero `<script>` tags and the
stylesheet inlined. The 404 page's canonical pointed at
`https://jonathanlaperle.com/404/`, which is not a real route; the layout takes a
`canonical={null}` prop now, so pages with no URL of their own emit none.

Three defects, three one-line fixes: one CSS rule in `global.css`, one `{" "}` in
`index.astro`, one character in `404.astro`. One of the three was invisible to the
accessibility tree, and it is the one I would have shipped.

## Doing this to your site

Serve the build, confirm the port is yours, curl the status codes, snapshot the
accessibility tree, then evaluate for the things the tree omits: computed colors,
`scrollWidth` against `clientWidth`, bounding boxes of elements that should not touch.
Screenshot at the end and open the image.

The loop is the same four steps as
[the terminal post](/posts/giving-agents-vision/). The web hands you the first three and
still leaves you the fourth.
