Accessibility
VoiceOver, Voice Control and UI tests reading offscreen pages as they read windowed ones.
var pageConfiguration = CefPage.Configuration()
pageConfiguration.rendering = .offscreen
pageConfiguration.offscreenAccessibility = .automatic // built when something reads it
Gallery: OffscreenOverlayDemo. SelfTest’s accessibility group checks the tree.
Offscreen accessibility
VoiceOver, Voice Control, Full Keyboard Access, Accessibility Inspector and
UI tests read an offscreen page as they read a windowed one. The view is an
AXGroup whose child is the page’s AXWebArea, and below it are the
page’s headings, links, buttons, text fields, checkboxes, lists, tables,
images, landmarks and frames, with their frames on screen, hit testing,
keyboard focus, and the notifications assistive apps follow (focus, value,
selected text, layout, load complete and live-region announcements).
Chromium builds the tree only when something reads it, because keeping it
costs renderer time and memory on every change. offscreenAccessibility
decides when:
| Value | The tree is built |
|---|---|
.automatic (default) |
When VoiceOver is running, when an assistive app first asks the view for its children, hit-tests it or asks for its focused element, or when an app sets AXEnhancedUserInterface or AXManualAccessibility on the application, as Voice Control and automation tools do. It then stays on for the page’s lifetime. |
.enabled |
From creation. |
.disabled |
Never. The page is a single element. |
pageConfiguration.offscreenAccessibility = .enabled
setAccessibilityEnabled(_:) turns the tree on or off at any time,
whatever the option says, and isAccessibilityEnabled reports it.
Actions from assistive apps reach the page as the user’s own input would:
pressing clicks the element’s centre, incrementing and decrementing press
the arrow keys, and setting a text field’s value selects its text and
inserts the new text as an input method does. Focusing an element and
scrolling it into view use the DevTools protocol’s DOM.focus and
DOM.scrollIntoViewIfNeeded.
A host of your own reads the same model: page.accessibilityTree is a
CefAccessibilityTree of CefAccessibilityNodes with frames in view
points, offscreenAccessibilityTreeDidChange(_:) reports each change, and
page.performAccessibilityAction(_:on:) carries out actions. For tests
and diagnostics, CefOffscreenPageView.didPostAccessibilityNotification
reports every notification the view posts.
Offscreen accessibility
Windowed pages expose Chromium’s own NSAccessibility objects. For
offscreen pages Chromium only computes the tree (“tree only” mode) and
hands it to CEF’s accessibility handler, which the render handler returns
from get_accessibility_handler:
set_accessibility_state(STATE_ENABLED)starts the tree. WithCefPage.AccessibilityPolicy.automatic,CefOffscreenPageViewcalls it on the first sign of an assistive app: VoiceOver running, the first children, hit-test or focus query on the view, orCefApplicationreceivingAXEnhancedUserInterfaceorAXManualAccessibility, which arrive through the informal accessibility protocol.on_accessibility_tree_changedelivers serializedAXTreeUpdates, one tree per frame, with node data, child lists, relative bounds, tree data (focus, selection, load state) and events.on_accessibility_location_changedelivers moved nodes. Both arrive ascef_value_ttrees, which CEF lets any thread use. Reading a large page’s tree value by value takes hundreds of milliseconds, so the main thread only copies it (cef_value_t.copy, one call), a serial background queue reads the copy intoCefJSON, and the main thread applies the results in the order Chromium sent them. The copy takes about a quarter of the main thread’s time that writing the tree as JSON text and decoding the text took (design notes).CefAccessibilityTreeapplies the updates as Chromium’sAXTreedoes (clearing, reparenting, removing orphaned subtrees) and joins the frames’ trees through each<iframe>node’schildTreeId. A tree without a parent is the main document; a new one replaces the old one and its frames. Frames are resolved on demand: relative bounds plus each offset container’s origin, less its scroll offset, with transforms applied, then offset by the hosting<iframe>, and divided by the device scale factor, since Chromium reports physical pixels.- Chromium’s scroll updates travel separately from location updates and
CEF does not forward them, so the document’s scroll position, which the
render handler’s
on_scroll_offset_changedreports, is written into the root node. CefOffscreenPageViewkeeps oneNSAccessibilityElementper node. Elements hold only a node identifier and read the tree on every query; the role table follows Chromium’s macOS mapping. Ignored nodes are skipped, and leaves (text, images, buttons, plain text fields) hide their insides. Each change becomes the matchingNSAccessibilitynotification; layout notifications are coalesced to one per 100 ms.
CEF’s C API has no way to perform accessibility actions, so actions go
through input: clicks at the node’s centre, arrow keys, and text committed
as an input method commits it (ime_commit_text, replacing the field’s
whole value), with Input.insertText only for a field that takes no
input-method text. Focus and scrolling use DOM.focus and
DOM.scrollIntoViewIfNeeded. Those need a DOM node, which the serialized
tree does not carry; the DevTools Accessibility domain shares Chromium’s
node identifiers with it, so Accessibility.getChildAXNodes on the node’s
parent yields the node’s backendDOMNodeId. Only the main frame’s nodes
are looked up this way: a frame in another renderer process numbers its
nodes independently, so a number from it could name a different node in
the main frame’s process. Nodes in frames are clicked instead.
When the page closes or the tree is turned off, the tree is emptied
and the view posts AXUIElementDestroyed for every element it handed out.
Offscreen accessibility updates
Chromium’s accessibility updates arrive as cef_value_t trees on the
main thread. A 28 000-node page (-benchmark axingest, 2026-11-13, the
two ways alternating in one build, with other builds running, so the
absolute times vary from batch to batch):
| Batch | Way | Main thread | Background | Tree ready |
|---|---|---|---|---|
| 1 | cef_write_json, text decoded, parsed on a queue |
63 ms | 315 ms | 971 ms |
| 1 | copy(), read value by value on a queue |
19 ms | 542 ms | 1 132–1 203 ms |
| 2 | cef_write_json, text decoded, parsed on a queue |
110–127 ms | 554–673 ms | 1 652–2 140 ms |
| 2 | copy(), read value by value on a queue |
32 ms | 826–835 ms | 1 838–1 844 ms |
The copy keeps the main thread free for three quarters of the time; the tree is ready at about the same time either way, the slower background read making up for the shorter main-thread step. CefKit copies. Reading the original tree value by value on the main thread, without a copy, took 452 ms there for a 15 000-node page in an earlier measurement.