Chrome screenshots can be saved for the human

This commit is contained in:
Ian Gulliver
2026-10-18 11:57:14 -07:00
parent e170da1c3a
commit aac99c48f9
4 changed files with 13 additions and 5 deletions
+3
View File
@@ -728,5 +728,8 @@ func chromeTool(_ args: [String: Any]) async throws -> [Content] {
let shot = try await c.send("Page.captureScreenshot", ["format": "png"], session: t.session)
let (png, shotNote) = try shrink(Data(base64Encoded: shot.string("data") ?? "") ?? Data(), maxEdge)
log.append(shotNote)
if args.bool("save") {
log.append("saved to \(try save(png))")
}
return [.text(log.joined(separator: "\n")), .png(png)]
}
+6 -2
View File
@@ -139,10 +139,14 @@ func captureTool(_ args: [String: Any]) async throws -> [Content] {
guard args.bool("save") else {
return [.text(shot.note), .png(shot.png)]
}
return [.text("\(shot.note); saved to \(try save(shot.png))"), .png(shot.png)]
}
func save(_ png: Data) throws -> String {
guard let dir = mediaDir else {
throw ToolError("save needs byre's media folder, and this byre-hands has none")
}
let url = URL(filePath: dir).appending(path: "capture-\(UUID().uuidString.prefix(8).lowercased()).png")
try shot.png.write(to: url)
return [.text("\(shot.note); saved to \(url.path)"), .png(shot.png)]
try png.write(to: url)
return url.path
}
+2 -1
View File
@@ -123,7 +123,8 @@ let tools: [Tool] = [
"wait_ms": {"type": "integer", "description": "Wait this long after the op, before wait_for and capture."},
"timeout_ms": {"type": "integer", "description": "How long navigate waits for the load (default 15000) and wait_for waits (default 10000). Giving up is reported, not an error."},
"capture": {"type": "boolean", "description": "Finish with a screenshot of the tab's page."},
"max_edge": {"type": "number", "description": "Longest edge of the screenshot in pixels, 16 to 8192 (default 1568, which is as much as you can see)."}
"max_edge": {"type": "number", "description": "Longest edge of the screenshot in pixels, 16 to 8192 (default 1568, which is as much as you can see)."},
"save": {"type": "boolean", "description": "With capture, also save the screenshot as a PNG in the task's media folder; the reply gives its path, which a Markdown image in your final message can show."}
}, "required": ["op"]}
""",
run: chromeTool