A browser session lifecycle an agent can reason about
Create, inspect, connect and close Cloudflare Browser Run sessions without confusing access links with persistent browser state.
Capture bounded JPEG screenshots, pair them with page observations and avoid treating a picture as proof of an action outcome.
Use a screenshot when layout, a visible warning, a selected control or the human's current view matters to the decision. Lupin's screenshot action captures a JPEG of the current viewport and returns image_base64 with mime_type. It does not create a full-page document archive or a session recording. A screenshot can show that a confirmation banner was visible at a moment; it cannot alone prove which server accepted a transaction or whether an off-screen field was saved. State the narrow observation the picture supports before deciding to capture it.
List tabs or use the tab_id from your immediately preceding page read. Pass it explicitly to screenshot so a new popup cannot silently change the subject. Read the page before or alongside the image to preserve the source URL, title and retrieval time that the screenshot payload itself may not include. If the page changed between those two operations, label the observations separately instead of asserting perfect synchronization. For a long document, explain which viewport the image shows. Scrolling and recapturing produces another observation, not an automatic stitched record of the entire page.
The current API returns JPEG data rather than a public image URL. A client should decode that data only where it needs to display or store the evidence. MCP returns screenshots as native image content, which can avoid forcing a model to reason over a long encoded string. The screenshot implementation rejects image data larger than its current bound, so screenshot_too_large is a real output failure rather than a missing page. Do not solve it by repeatedly capturing the same unchanged viewport; inspect the page and choose another evidence method if necessary.
{"action":"screenshot","tab_id":"TARGET_ID_FROM_TABS"}Before capturing an authenticated page, consider whether a text read or a small set of extracted observations answers the question with less private data. A viewport can contain names, account numbers, notifications and unrelated browser content. Store images with access controls appropriate to that material and avoid placing the encoded payload in ordinary logs. If the task requires a sanitized image, use an approved image-processing step and retain a clear record of what was removed. Do not claim a screenshot is redacted merely because the visible summary omitted sensitive text.
After an action, compare the page's current URL, visible status text and relevant application state with the intended result. Capture a screenshot when it resolves visual ambiguity, such as an overlay hiding the actual button. If the action response was lost, a picture may help determine the current state but does not authorize replaying a submission. Save the image with the task step and source observation, then end the session when work is complete. Lupin disables session recording, so a deliberate evidence plan matters: later playback is not a recovery option for an observation you never captured.
Reviewed against the current Lupin route, provider adapter and shared input contracts, plus the linked official references. Examples were not run against live services.
Prepared with AI assistance by Lupin editorial. How we research and maintain these guides.