Repository navigation
Conversation
The extract prompt asks the model to return link element IDs, but `injectUrls` only resolves IDs for `z.string().url()` schema paths. Plain `z.string()` fields carrying a link leak the raw accessibility-tree ID (e.g. "0-74" or "[0-74]\n[0-112]") to the caller. Add `resolveUrlIds`, which walks the extracted value after the existing `.url()` resolution and replaces any bare or bracketed ID that is actually present in the snapshot's URL map. IDs that are not real links (a score of "3-2") are left unchanged. Closes browserbase#3234
🦋 Changeset detectedLatest commit: ac375bd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
|
Checking in on this one — the failing link-ID lookup is still present on |
Closes #3234
Problem
extract()can return accessibility-tree element IDs instead of URLs when aschema uses a plain
z.string()field for a link.The extract system prompt (
packages/extension/prompt.ts) asks the model toreturn link element IDs rather than hrefs, but
injectUrlsinutils.tsonlyresolves IDs for schema paths that are marked as URL fields
(
z.string().url()). A plainz.string()field carrying a link thereforeleaks the raw ID (
"0-74", or"[0-74]\n[0-112]"for multi-link strings) tothe caller.
Change
After the existing
.url()resolution, walk the extracted value with a newresolveUrlIdshelper and replace any bare or bracketed element ID that isactually present in the snapshot's URL map (
idToUrlMapping). IDs that are notreal links are left untouched, so a value like a score of
"3-2"is preservedexactly as requested in the issue.
Verification
extract.test.tscovering plain-string resolution,.url()fields, bracketed multi-ID strings, and the"3-2"non-link case.resolveUrlIdshelper was exercised in an isolated vitest run (8 casespass) plus a strict
tsc --noEmitbefore submission.extract.test.tscould not be executed in thisenvironment (no full monorepo checkout is possible here), but it is a
pure-mock test (
vi.fnstubs forcaptureSnapshot/generate, no realbrowser) and is covered by CI's unit-test job.
Known trade-off
If a plain string field legitimately contains a value that happens to equal a
real link element ID from the page's accessibility tree, it will be resolved to
that link's href. This is the intended behaviour described in the issue (the
discriminator is "the ID is present in the snapshot's URL map"), but it is a
semantic edge case worth surfacing to maintainers.
AI use
Drafted with an AI coding agent; the isolated helper test and strict typecheck
were run locally before submission.
Summary by cubic
Fixes
extract()returning raw accessibility-tree element IDs like"0-74"instead of URLs when a link lands in a plainz.string()field. Link IDs are now resolved to hrefs via the snapshot's URL map, while non-link values like a score of"3-2"stay unchanged.Details
z.string().url()paths were resolved beforehand.resolveUrlIdshelper recursively walks the extracted value and replaces bare or bracketed IDs present in the URL map..url()fields, bracketed multi-ID strings, and the"3-2"non-link case.Written for commit ac375bd. Summary will update on new commits.