Chrome screenshots can be saved for the human
This commit is contained in:
@@ -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)]
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user