Add back in extract({screenshot:true}) functionality - #2435
Open
monadoid wants to merge 2 commits into
Open
Conversation
|
monadoid
marked this pull request as ready for review
July 26, 2026 13:45
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Architecture diagram
sequenceDiagram
participant Client as Client (TS/Python SDK)
participant ExtractSvc as extractService
participant Page as Page (Browser)
participant Inference as inference.ts
participant LLM as LLM Service (server or client)
participant AISDK as AI SDK Converter
participant Cache as Cache Service
Note over Client,Cache: NEW: Screenshot-backed extraction flow
Client->>ExtractSvc: extract({ screenshot: true, ... })
ExtractSvc->>ExtractSvc: check timeout (start)
ExtractSvc->>Cache: withCache (check cache)
Cache-->>ExtractSvc: cache miss (or skip)
ExtractSvc->>Page: captureSnapshot()
Page-->>ExtractSvc: accessibility tree
ExtractSvc->>Page: screenshot({ fullPage: false, type: "png" })
Page-->>ExtractSvc: Uint8Array (PNG bytes)
ExtractSvc->>ExtractSvc: ensureTimeRemaining() -- NEW: check timeout after screenshot
alt Timeout exceeded
ExtractSvc-->>Client: throw TimeoutError("extract() timed out")
else Still time remaining
ExtractSvc->>ExtractSvc: convert PNG bytes to LLMImageContent (base64 data)
ExtractSvc->>Inference: extract({ ..., screenshot: LLMImageContent })
Inference->>LLM: generateStructured() with systemPrompt + userPrompt (including screenshot)
Note over Inference,LLM: NEW: userPrompt is now an LLMMessage with content array (text + image)
alt Client-provided LLM (clientLLMGenerate)
LLM->>AISDK: generateWithAiSdk() (converts protocol image block to AI SDK image part)
AISDK->>AISDK: map image.type -> image.image, mimeType -> mediaType
AISDK-->>LLM: AI SDK call result
else Server-side LLM (direct model)
LLM->>LLM: call model with image content
end
LLM-->>Inference: structured result + metadata
Inference-->>ExtractSvc: extracted data + metadata
ExtractSvc->>Cache: store result in cache
ExtractSvc-->>Client: final result (data + metadata)
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
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
Until now,
extract({ screenshot: true })was just a no-op returning an error - this brings over the functionality from v3 exactly, and we base64 encode the image to serialize it over the wire.Summary by cubic
Adds screenshot-backed extraction in v4: when
extract({ screenshot: true })is used, we capture a viewport PNG and send it to the LLM alongside the accessibility tree using protocol-nativeLLMImageContent. Works with direct and client-provided LLMs, keeps cache/timeout behavior, and exposes image content in the Python SDK.LLMImageContent.LLMImageContentfromstagehandPython SDK and add cross-stack tests.Written for commit 16f6ba4. Summary will update on new commits.