Accessibility

Two surfaces in one plugin. announce, title and focus let a page speak through the platform's accessibility layer. trusted, prompt and elementCount ask whether the OS will expose the app's own accessibility tree. The first is how you reach a screen reader; the second is a diagnostic about the tree itself. A third surface is page-local: window.crust.a11y reads and focuses the page's own DOM without crossing the bridge.

Registered by the macOS runtime with darwinAccessibilityAdapter().

Commands

commandargumentsanswer
announce{ text, priority? }{ ok: true, announced, trusted, priority, reason }
title{ text, label? }{ ok: true, titled, reason }
focus{ label? }{ ok: true, focused, reason }
trustednone{ ok: true, trusted }
promptnone{ ok: true, trusted, prompted: true }
elementCountnone{ ok: true, count }

Speaking through the platform

await window.crust.invoke("accessibility", "announce", {
	text: "Report saved",
	priority: "polite",
});

macOS posts NSAccessibilityAnnouncementRequestedNotification through NSAccessibilityPostNotificationWithUserInfo, with NSAccessibilityAnnouncementKey and NSAccessibilityPriorityKey in the user-info dictionary. priority: "assertive" is priority 90 and interrupts; "polite" is 50 and waits for a gap. Anything that is not assertive is polite, which is also the default.

An untrusted process still announces. The post is accepted and macOS drops it, so the answer is announced: true with trusted beside it rather than a refusal that claims a policy the OS does not apply. Read both fields: announced says the call was made, trusted says whether anything will be spoken.

announce is not a live region. Nothing is inserted into the DOM, so there is no role="status" element to find and no 50 ms clear-and-set dance — the platform speaks the string.

Naming the window

await window.crust.invoke("accessibility", "title", { text: "Settings — Main" });

Sets the window's accessible name via -setAccessibilityLabel:, which is the string a screen reader reads when it lands on the window. It is deliberately separate from the visible title: -setTitle: is untouched, so the title bar and the spoken name can differ. Omit label to mean the key window.

Moving assistive focus

await window.crust.invoke("accessibility", "focus", { label: "main" });

The native half attempts to set AXFocusedWindow and AXFocused, then posts AXFocusedWindowChanged and AXFocusedUIElementChanged. focus takes no text — a page cannot type into another app through it. Do not read focused: true as proof that a screen reader moved: the current native unit does not check the three AXUIElementSetAttributeValue results, so a matching window can report success even when the AX server refused every set. Confirm assistive focus in the app itself where it matters.

A label matches a window's title or its existing accessible name. An unknown label answers a typed { ok: false, code: "bad-request", message }, not a focused: false value and not a throw.

Platforms without an announcement surface

platformannounce answers
macOSposts the notification
Linuxnot-implemented, requires: "gtk_widget_announce"
Windowsnot-implemented, requires: "NotifyWinEvent EVENT_OBJECT_LIVEREGIONCHANGED"

The Linux answer names GTK 3, not GTK 4: gtk_widget_announce arrived in GTK 4 and crust's Linux shim loads libgtk-3.so.0, so the call does not exist in the toolkit the app actually links.

The Windows answer is a deliberate refusal. NotifyWinEvent with EVENT_OBJECT_LIVEREGIONCHANGED is a live-region change event, which a screen reader may read on its own schedule; it is not a request to speak a particular string. Wiring it up and calling it an announcement would be the dishonest answer, so it is named and refused.

The trust probe

const { trusted } = await window.crust.invoke("accessibility", "trusted");

A read: it never raises a dialog. Use it before a call that needs the AX API, so the app can explain itself instead of failing opaquely. trusted: false should mean AXIsProcessTrusted() answered false. The current native adapter also returns false when its C unit could not be compiled, so the two states are not yet distinguishable here; elementCount names that compile failure in its refusal reason if you need to tell them apart.

const { trusted, prompted } = await window.crust.invoke("accessibility", "prompt");

prompt raises the one system dialog that grants trust and answers the state after it. A human answers that dialog, so trusted: false is the common result of the first call. prompted is always true — it records that the dialog was raised, not that it was accepted.

Counting the app's own tree

const { count } = await window.crust.invoke("accessibility", "elementCount");

The walk starts at the app's own AX element and counts the children of its first window. A window with no children answers count: 0, which is a real answer.

Two states are not a count, and both answer not-implemented rather than 0:

requiresmeaning
AXUIElementCopyAttributeValue (AXWindows)AX listed no windows for this process
AXUIElementCopyAttributeValuethe AX API refused the walk

A count of zero from a window that does not exist is not evidence of anything, which is why the two are separated.

The page's own tree and DOM focus

elementCount cannot say what is inside the page: it walks the app's AX element in a process that is not trusted by default, and the content tree belongs to WebKit and VoiceOver. The page half closes the part it can honestly close — two page-local commands on window.crust.a11y, with no bridge call and no native half:

const { nodes, note } = window.crust.a11y.pageTree("main");
const focus = window.crust.a11y.focusElement("#save");

pageTree(selector?) walks a subtree (default body) in reading order and reports each element as { role, label, focusable, readingOrder }. role is the explicit role attribute or the implicit role from the tag (input[type=checkbox] → checkbox, <h1> → heading, <div> → generic); label comes from aria-label, aria-labelledby, alt, title, then text content; focusable is tab reachability, not programmatic focusability. The answer carries source: "dom" and a note: this is the page's own view, not the operating system's accessibility tree, so a populated tree is not evidence a screen reader can reach the page. Reading another process's tree still needs a trusted process and code this plugin does not ship.

focusElement(selector) calls .focus() on the first match, then reads document.activeElement. It answers { ok: true, focused: true, active: { role, label } } with what actually took focus, not what was asked to. A browser refuses a <div> without tabindex, so that case answers { ok: false, code: "not-focusable" } with a message naming tabindex; an unmatched or empty selector answers not-found or bad-request. This is keyboard/DOM focus, distinct from the plugin's accessibility.focus command, which moves assistive focus to a window.

Both commands answer { ok: false, code: "no-document" } when the page has no document. The bridge's document snippet and crust/vite's dev-page snippet both install them, so every served page has crust.a11y.

A window is in AX only when the app is active

AppKit lists only windows on the active Space, and a window joins that Space only when its app is active. -[NSApplication activate] is silently refused for a process LaunchServices did not launch — which is how crust dev and the parity harness run — so a window can be visible, clickable and absent from AXWindows for every other process while AXIsProcessTrusted is true.

crust therefore sends -activateIgnoringOtherApps: when the app is not already active, guarded on isActive so creating a second window does not pull the app forward. app.activate decides when that happens: "always" (the default) on every window create, "first" only for the first window create of the process, and "never" not at all.

isActive alone cannot express "first": it is false whenever the human is in another app, so a window created by the page would pull the app back in front. Measured on a built bundle with lsappinfo info -only name $(lsappinfo front) — front was Activation crust at t1.5 for the driver window, Ghostty at t3 after focus was handed away, and Activation crust again at t8 for a window the page created; a control run with window creation disabled showed no transition. "first" therefore uses one process-wide flag, and the cost is that a later window created while the app is inactive stays out of AXWindows until the user clicks the app — the same symptom "never" has for every such window. Measured on one window from a separate trusted process:

before  external=windows:0,children:-1,status:0
after   external=windows:1,children:4,status:0

So a zero is not by itself proof that the tree is missing: check trusted first, then whether the app is active. The gate is activation, not the window.

Failure shape

Without an adapter — every platform but macOS — each command answers not-implemented with the call that platform would need: AXIsProcessTrusted on macOS, gtk_widget_announce and the ATK calls on Linux, IUIAutomation and the UIA calls on Windows. An app that passes its own adapter without one of the three page-facing methods gets not-implemented naming that method's call, never a silent success.

Limits

elementCount walks the app's own element only. Reading another process's tree needs trusted: true and code this plugin does not ship. announce speaks; it does not read a screen reader's state. crust.a11y.pageTree reports the DOM, not the OS tree; crust.a11y.focusElement reports what took DOM focus, not where assistive focus is — the plugin's focus still only moves it.