From 4112234371f21cd07494a5b6f3689fcb110561fe Mon Sep 17 00:00:00 2001 From: jaydenfyi <213395523+jaydenfyi@users.noreply.github.com> Date: Sun, 18 Jan 2026 10:18:06 +0800 Subject: [PATCH] fix(cli): Output screenshot as base64 string when no path provided (#83) * fix(cli): print screenshot base64 when no path * chore(docs): update docs and SKILL.md * add test for screenshot with path arg * more minimal readme + skill change --- README.md | 2 +- cli/src/commands.rs | 14 +++++++++++++- cli/src/output.rs | 5 +++++ docs/src/app/quick-start/page.tsx | 3 ++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c742b0..5fe49b1 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ agent-browser scroll [px] # Scroll (up/down/left/right) agent-browser scrollintoview # Scroll element into view (alias: scrollinto) agent-browser drag # Drag and drop agent-browser upload # Upload files -agent-browser screenshot [path] # Take screenshot (--full for full page) +agent-browser screenshot [path] # Take screenshot (--full for full page, base64 png to stdout if no path) agent-browser pdf # Save as PDF agent-browser snapshot # Accessibility tree with refs (best for AI) agent-browser eval # Run JavaScript diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 25c2e0d..e14713e 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -273,7 +273,11 @@ pub fn parse_command(args: &[String], flags: &Flags) -> Result { - Ok(json!({ "id": id, "action": "screenshot", "path": rest.get(0), "fullPage": flags.full })) + let mut cmd = json!({ "id": id, "action": "screenshot", "fullPage": flags.full }); + if let Some(path) = rest.get(0) { + cmd["path"] = json!(path); + } + Ok(cmd) } "pdf" => { let path = rest.get(0).ok_or_else(|| ParseError::MissingArguments { @@ -1286,6 +1290,14 @@ mod tests { fn test_screenshot() { let cmd = parse_command(&args("screenshot"), &default_flags()).unwrap(); assert_eq!(cmd["action"], "screenshot"); + assert!(cmd.get("path").is_none()); + } + + #[test] + fn test_screenshot_path() { + let cmd = parse_command(&args("screenshot out.png"), &default_flags()).unwrap(); + assert_eq!(cmd["action"], "screenshot"); + assert_eq!(cmd["path"], "out.png"); } #[test] diff --git a/cli/src/output.rs b/cli/src/output.rs index 31b98d8..77b4df1 100644 --- a/cli/src/output.rs +++ b/cli/src/output.rs @@ -208,6 +208,11 @@ pub fn print_response(resp: &Response, json_mode: bool) { println!("\x1b[32m✓\x1b[0m Screenshot saved to {}", path); return; } + // Screenshot base64 + if let Some(base64) = data.get("base64").and_then(|v| v.as_str()) { + println!("{}", base64); + return; + } // Default success println!("\x1b[32m✓\x1b[0m Done"); } diff --git a/docs/src/app/quick-start/page.tsx b/docs/src/app/quick-start/page.tsx index 825b5a3..00545c6 100644 --- a/docs/src/app/quick-start/page.tsx +++ b/docs/src/app/quick-start/page.tsx @@ -12,7 +12,8 @@ agent-browser snapshot # Get accessibility tree with refs agent-browser click @e2 # Click by ref from snapshot agent-browser fill @e3 "test@example.com" # Fill by ref agent-browser get text @e1 # Get text by ref -agent-browser screenshot page.png +agent-browser screenshot # Base64 png to stdout +agent-browser screenshot page.png # Save to file agent-browser close`} />

Traditional selectors