Skip to content

Niklhut/browser run accessibility tree types - #6928

Open
niklhut wants to merge 3 commits into
cloudflare:mainfrom
niklhut:niklhut/browser-run-accessibility-tree-types
Open

Niklhut/browser run accessibility tree types#6928
niklhut wants to merge 3 commits into
cloudflare:mainfrom
niklhut:niklhut/browser-run-accessibility-tree-types

Conversation

@niklhut

@niklhut niklhut commented Aug 7, 2026

Copy link
Copy Markdown

Summary

Adds the missing accessibilityTree quick action to the BrowserRun binding types, and corrects the snapshot action's response shape.

The accessibilityTree quick action is live and documented, but has no overload in types/defines/browser-run.d.ts, so the binding snippet published on the docs page does not compile:

// Argument of type '"accessibilityTree"' is not assignable to parameter of type '"markdown"'
await env.BROWSER.quickAction("accessibilityTree", { url });

quickAction is declared as explicit overloads, one per action, so a missing action surfaces as a mismatch against whichever overload happens to be last. The "markdown" in the message is incidental — the action is simply absent from the overload set.

Changes

accessibilityTree overload. Adds the overload plus three supporting types:

Type Notes
BrowserRunAccessibilityTreeOptions BrowserRunCommonOptions plus interestingOnly? and root?
BrowserRunAccessibilityTreeSuccessResponse accessibilityTree is nullable — see below
BrowserRunSerializedAXNode Recursive ARIA node, 26 fields; role required, all others optional

Two API behaviours worth noting in review:

  • A root selector matching no element returns accessibilityTree: null with HTTP 200, so the field is typed as nullable rather than optional.
  • interestingOnly has no static default. The server computes interestingOnly ?? (root ? false : true), so no default is documented on the field.

snapshot response shape. The existing declaration omitted formats and typed result.content / result.screenshot as always present. Per the API, formats selects which keys appear, and result plus every field in it is optional. Adds BrowserRunSnapshotFormat ("content" | "screenshot" | "markdown" | "accessibilityTree") and makes the result fields optional.

The server requires at least two distinct formats and rejects a single-format request, directing callers to that format's dedicated action. That constraint is documented in JSDoc rather than encoded in the type, matching how scrape.elements handles its own minimum. A tuple type would enforce length while the server actually checks distinctness, so it would give false confidence and break dynamically built formats arrays.

Notes

  • Types-only. src/cloudflare/internal/br-api.ts wraps fetcher.fetch() and has no per-action code, so there is no runtime change.
  • The action name is camelCase accessibilityTree, matching POST /v1/accessibilityTree. Only the SDK method is kebab-case.
  • Generated snapshots regenerated with just generate-types; no unrelated churn.

Validation

  • BrowserRunSerializedAXNode mirrors the server's SerializedAxNodeSchema field for field, including role as the only required field and value as a string | number union.
  • tsc --strict against the defines, with @ts-expect-error assertions covering unknown option keys, wrong option types, and a missing url. Verified the assertions actually bite by making one case valid and confirming TS2578.
  • Cross-checked the declared node shape against live API responses; no undeclared fields returned.
  • Confirmed formats: ["markdown", "accessibilityTree"] returns only those keys, and that a root selector matching nothing yields accessibilityTree: null at HTTP 200.
  • Built these types into a real Worker project via wrangler types and exercised quickAction("accessibilityTree", { url }) through a deployed binding.

niklhut added 3 commits August 7, 2026 10:57
The Browser Run REST API exposes POST /accessibilityTree, returning the
page's accessibility tree as puppeteer serializes it. Add the matching
quickAction overload, its options type, and BrowserRunSerializedAXNode
describing a tree node.

interestingOnly has no static default: the API prunes semantically
uninteresting nodes by default, but flips to keeping them when root is
set so the requested subtree comes back as-is. A root selector that
matches nothing yields accessibilityTree: null with HTTP 200 rather than
an error, hence the nullable result field.
The snapshot action takes a formats array selecting which representations
of the page to return, defaulting to content plus screenshot but also
accepting markdown and accessibilityTree. The types omitted the field
entirely and declared result.content and result.screenshot as always
present, so requesting any other combination produced a response the
declared type could not describe.

Add formats, and make result and its fields optional since each is
returned only when its format was requested.
Picks up the accessibilityTree quick action and the corrected snapshot
action response shape from types/defines/browser-run.d.ts.
@niklhut
niklhut requested review from a team as code owners August 7, 2026 15:15
@niklhut
niklhut requested a review from penalosa August 7, 2026 15:15
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@niklhut

niklhut commented Aug 7, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant