Niklhut/browser run accessibility tree types - #6928
Open
niklhut wants to merge 3 commits into
Open
Conversation
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.
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the missing
accessibilityTreequick action to theBrowserRunbinding types, and corrects thesnapshotaction's response shape.The
accessibilityTreequick action is live and documented, but has no overload intypes/defines/browser-run.d.ts, so the binding snippet published on the docs page does not compile:quickActionis 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
accessibilityTreeoverload. Adds the overload plus three supporting types:BrowserRunAccessibilityTreeOptionsBrowserRunCommonOptionsplusinterestingOnly?androot?BrowserRunAccessibilityTreeSuccessResponseaccessibilityTreeis nullable — see belowBrowserRunSerializedAXNoderolerequired, all others optionalTwo API behaviours worth noting in review:
rootselector matching no element returnsaccessibilityTree: nullwith HTTP 200, so the field is typed as nullable rather than optional.interestingOnlyhas no static default. The server computesinterestingOnly ?? (root ? false : true), so no default is documented on the field.snapshotresponse shape. The existing declaration omittedformatsand typedresult.content/result.screenshotas always present. Per the API,formatsselects which keys appear, andresultplus every field in it is optional. AddsBrowserRunSnapshotFormat("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.elementshandles its own minimum. A tuple type would enforce length while the server actually checks distinctness, so it would give false confidence and break dynamically builtformatsarrays.Notes
src/cloudflare/internal/br-api.tswrapsfetcher.fetch()and has no per-action code, so there is no runtime change.accessibilityTree, matchingPOST /v1/accessibilityTree. Only the SDK method is kebab-case.just generate-types; no unrelated churn.Validation
BrowserRunSerializedAXNodemirrors the server'sSerializedAxNodeSchemafield for field, includingroleas the only required field andvalueas astring | numberunion.tsc --strictagainst the defines, with@ts-expect-errorassertions covering unknown option keys, wrong option types, and a missingurl. Verified the assertions actually bite by making one case valid and confirmingTS2578.formats: ["markdown", "accessibilityTree"]returns only those keys, and that arootselector matching nothing yieldsaccessibilityTree: nullat HTTP 200.wrangler typesand exercisedquickAction("accessibilityTree", { url })through a deployed binding.