feat(snapshot): add ref annotation bounding boxes to snapshot response - #5724
Open
melxusgid wants to merge 1 commit into
Open
feat(snapshot): add ref annotation bounding boxes to snapshot response#5724melxusgid wants to merge 1 commit into
melxusgid wants to merge 1 commit into
Conversation
Adds a new query parameter annotateScreenshot=true to the
GET /tabs/{tabId}/snapshot endpoint. When set along with
includeScreenshot=true, the response includes a
screenshotAnnotations array with {refId, role, name, x, y, width, height}
for each accessible element ref that has a bounding box on the page.
This makes human-in-the-loop workflows possible by letting clients
overlay ref IDs on the screenshot image.
New helper function getRefAnnotations(page, refs) resolves each ref
to its Playwright bounding box using the same refToLocator logic
used by click/type endpoints.
Works in all three snapshot paths: cached offset, Google SERP,
and full ariaSnapshot.
Fixes jo-inc#5086
Contributor
|
thanks for this—the human-in-the-loop motivation makes sense. I’m thinking a little more about the right API boundary here, particularly annotated images versus returning geometry without making the capture path brittle. stay tuned. |
Contributor
|
Thanks for this feature work. We do not want to extend the core snapshot response with screenshot-ref annotation rendering. Please move this into a plugin or a separate plugin-owned endpoint, so the annotation implementation and its screenshot contract can evolve without coupling to the core snapshot/reference pipeline. For a reworked version, please also:
Please re-open or update this PR with the plugin design rather than adding the feature to the core snapshot route. |
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.
Feature
Adds
annotateScreenshot=truequery parameter toGET /tabs/{tabId}/snapshot.When set, the response includes a
screenshotAnnotationsarray with element bounding boxes:{ "screenshotAnnotations": [ { "refId": "e1", "role": "button", "name": "Search", "x": 120, "y": 45, "width": 200, "height": 40 }, { "refId": "e2", "role": "link", "name": "Sign in", "x": 800, "y": 20, "width": 80, "height": 24 } ] }This makes human-in-the-loop workflows possible: clients can overlay ref IDs on the screenshot image.
Implementation
New helper
getRefAnnotations(page, refs)resolves each ref to its bounding box using the samerefToLocatorlogic already used by click/type endpoints. Skips elements that are no longer visible.Works in all three snapshot paths:
No new dependencies. Pure Playwright boundingBox() calls.
Fixes #5086