Repository navigation
Add the snapshot and screenshot queries - #624
vishnuv688 wants to merge 3 commits into
Conversation
traceSnapshot and traceScreenshot give an agent the page at an action, named after @wdio/mcp's trace tools. The snapshot is the accessibility tree with locators, scoped to a subtree by locator or text and paged within its budget; the screenshot is the image with the size it fits at and what it costs in tokens, left to the caller to downscale. Both say whose capture they show. The reader now records, outside the wire contract, which capture each action shows, which action took it and the image it stored, from the zip's own frame-snapshot claims, so an action that took none shows the latest earlier one and the two queries always agree. A trace from another tool, whose frames claim no action, falls back to the latest screencast frame at or before the action, never a later one. The A11y tab's line parser moves into shared, reading a name or locator that contains an arrow or a quote whole. Closes #606
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
[Medium impact] The PR appears safe to merge; all previous findings are addressed and no new actionable issues were found. SummaryAdds snapshot and screenshot queries with capture details, scoped snapshot pages, image sizes, and token estimates.
Reviews (3) · Last reviewed commit: "Read pre-escaping snapshot names literal..." · Reviewed by Greptile |
| for (let at = text.indexOf('"', start); at !== -1;) { | ||
| const after = at + 1 | ||
| if ( | ||
| after === text.length || | ||
| closers.some((closer) => text.startsWith(closer, after)) | ||
| ) { | ||
| return { value: text.slice(start, at), end: after } |
There was a problem hiding this comment.
A name containing a quote followed by the locator separator is split too early. The writer can produce button "Press " → next" → #go, but this parser returns next" → #go as the locator instead of #go. The A11y tab then copies and highlights the wrong locator, and traceSnapshot finds no match for { locator: "#go" }.
Make names and purposes unambiguous when written and read, and add a round-trip test for this case.
Knowledge Base Used:
There was a problem hiding this comment.
Fixed in f5eb5a0: both serializers now write names and purposes through the shared snapshotNodeLabel, which escapes quotes and backslashes, and parseSnapshotLine skips escaped quotes while still reading older unescaped traces. Tests in packages/shared and packages/trace round-trip Press " → next to the locator #go.
Generated by Claude Code
| bytes, | ||
| size, | ||
| fit, | ||
| tokens: Math.ceil((fit.width * fit.height) / IMAGE_PIXELS_PER_TOKEN) |
There was a problem hiding this comment.
Large images appear too expensive
tokens overstates the documented image cost when maxEdge exceeds 1568. The supported { maxEdge: 4000 } case keeps a 1080×2400 image and returns 3456 tokens, while the README says that image bills about 1480 after the API scales it down. Callers may reject an image that would fit their token budget.
Keep fit at the requested size, but apply the documented API scaling when calculating tokens, and test a large maxEdge.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Fixed in f5eb5a0: fit stays at the requested size, but tokens is now computed after scaling it to the API's 1568-pixel long edge, so { maxEdge: 4000 } on a 1080x2400 frame returns 1477. A test covers that case.
Generated by Claude Code
A name holding a quote followed by the locator separator was read back with part of the name as its locator, so the A11y tab and traceSnapshot used the wrong one; serializers now escape quotes and backslashes, and the reader still accepts traces written before. traceScreenshot counted tokens at the fitted size even above 1568 pixels, overstating what the API bills after it scales the image down. Addresses review comments on #624
| !escapedAt(text, at, start) && | ||
| (after === text.length || | ||
| closers.some((closer) => text.startsWith(closer, after))) | ||
| ) { | ||
| return { | ||
| value: text.slice(start, at).replace(/\\([\\"])/g, '$1'), |
There was a problem hiding this comment.
Older traces stored backslashes literally, but quotedAt now always treats them as escapes. A saved name ending in a backslash loses its name because the closing quote is skipped. Two literal backslashes also become one. This changes names shown in the A11y tab and breaks reveal-by-name matching.
Distinguish the new encoding from older snapshot text before applying escape rules.
Knowledge Base Used: Shared contracts and transport
There was a problem hiding this comment.
Fixed in adbe162: a name or purpose that needs escaping now opens with a backslash (\"...), which no older trace writes there, so older lines are read literally (a trailing backslash and \\ keep their text) and plain names are written exactly as before. Tests in packages/shared/tests/snapshot-format.test.ts cover both older-trace cases and the new round trip.
Generated by Claude Code
| function quoteSnapshotText(text: string): string { | ||
| return `"${text.replace(/[\\"]/g, '\\$&')}"` |
There was a problem hiding this comment.
Escaping names and purposes changes what traceSnapshot finds by text. For example, { text: 'Say "hi"' } no longer finds a node named Say "hi" because matcherOf searches the escaped node.label, not the decoded name. Callers can get an empty snapshot even though the element was captured.
Match against the decoded role, name and purpose, and add a scoped-query test containing quotes and backslashes.
Knowledge Base Used: Shared contracts and transport
There was a problem hiding this comment.
Fixed in adbe162: matcherOf in packages/trace-query/src/snapshot-scope.ts now matches the decoded role, name and purpose instead of the escaped label, as SnapshotScope.text documents. A scoped-query test finds Say "hi" and C:\dir by text.
Generated by Claude Code
Escaping every quoted name changed how older traces read: a stored name ending in a backslash lost its name and a double backslash collapsed. A value that needs escaping now opens with a backslash, which no older trace writes there, so older lines keep their literal reading and plain names are written exactly as before. A snapshot text search matched the escaped label, so a name holding a quote was missed; it now matches the decoded role, name and purpose, as its documentation says. Addresses review comments on #624
What & why
The page at an action, for an agent debugging a failed run from its trace (#493), named after
@wdio/mcp's trace tools:traceSnapshot(handle, callId, { locator, text, maxChars, cursor })locatorortextwhen scoped, paged within the budgettraceScreenshot(handle, callId, { maxEdge })maxEdge(1024 by default) and the token cost at that size, or why none came backBoth say which capture they show (
capture: its time, the action that took it, and whether that is the action asked about), since an action that took no capture of its own, such as a read, shows the latest earlier one, as the player does. The library returns the image and leaves downscaling to@wdio/mcp, which already depends onsharp; token cost depends only on the pixels the model receives, so it is the same whichever side resizes, and resizing here would add a native or very large dependency to a package whose only dependency isfflate.Closes #606
Type of change
Packages touched
shared(types and contracts)core(framework-agnostic capture/reporting)elements(published element/snapshot API:@wdio/elements)service(WebdriverIO adapter)nightwatch-devtools(Nightwatch adapter)selenium-devtools(Selenium adapter)selenium-devtools-py(Selenium Python adapter)backend(server)app(UI)script(page-injected runtime)trace(Trace mode)Also
trace-query, which the list does not name.Capability matrix
Not applicable yet: no adapter behaviour and no user-facing tool. Whether the trace tools get a row is decided with the docs in #608.
Notes for reviewers
TracePlayerData.snapshotSourcesmaps each action'scallIdto the capture it shows, the action whose frame-snapshot claimed it first, and the image entry it stored (this writer's screenshot override, or the copy an older writer stored under the capture's stamp). It lives onTracePlayerData, which is not in the wire schema, soCommandLog,wire-schema.jsonand the Python adapter's wire types are untouched. An earlier version put the stamp onCommandLog, which would have forced a PyPI release for a field Python never sends.maxCharsfrom the 1000-character floor up, header and title fitted to the serialized budget so escape-heavy text cannot overrun it; the every-budget test pages scoped and unscoped snapshots on every fixture and a hostile trace. A screenshot over 16 MB declared size is not read (unavailablesays why).unavailablereason, go throughreturnedTextwith their own kinds.parseSnapshotLine, a linear scan (a regular expression would be quadratic on a hostile line), and the serializers and parser share one locator separator. The tab reads names and locators containing→or"whole, no longer takes a quoted string in a locator for a missing name, and still shows and reveals a nameless node by its purpose.@wdio/devtools-appgets a patch changeset.pnpm build,pnpm test(374 files, 5222 tests),pnpm lint(0 errors) andpnpm typecheckpass; leak grep clean on thetrace-querydist. The new A11y-tab component test runs in CI'scomponent-tests.Screenshots / recordings
Not applicable: the A11y tab looks as before, apart from names and locators it used to misread.
🤖 Generated with Claude Code