add sub --help flag
This commit is contained in:
+14
-2
@@ -21,7 +21,7 @@ use commands::{gen_id, parse_command, ParseError};
|
|||||||
use connection::{ensure_daemon, send_command};
|
use connection::{ensure_daemon, send_command};
|
||||||
use flags::{clean_args, parse_flags};
|
use flags::{clean_args, parse_flags};
|
||||||
use install::run_install;
|
use install::run_install;
|
||||||
use output::{print_help, print_response};
|
use output::{print_command_help, print_help, print_response};
|
||||||
|
|
||||||
fn run_session(args: &[String], session: &str, json_mode: bool) {
|
fn run_session(args: &[String], session: &str, json_mode: bool) {
|
||||||
let subcommand = args.get(1).map(|s| s.as_str());
|
let subcommand = args.get(1).map(|s| s.as_str());
|
||||||
@@ -98,7 +98,19 @@ fn main() {
|
|||||||
let flags = parse_flags(&args);
|
let flags = parse_flags(&args);
|
||||||
let clean = clean_args(&args);
|
let clean = clean_args(&args);
|
||||||
|
|
||||||
if clean.is_empty() || args.iter().any(|a| a == "--help" || a == "-h") {
|
let has_help = args.iter().any(|a| a == "--help" || a == "-h");
|
||||||
|
|
||||||
|
if clean.is_empty() {
|
||||||
|
print_help();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if has_help {
|
||||||
|
if let Some(cmd) = clean.get(0) {
|
||||||
|
if print_command_help(cmd) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
print_help();
|
print_help();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,6 +145,961 @@ pub fn print_response(resp: &Response, json_mode: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print command-specific help. Returns true if help was printed, false if command unknown.
|
||||||
|
pub fn print_command_help(command: &str) -> bool {
|
||||||
|
let help = match command {
|
||||||
|
// === Navigation ===
|
||||||
|
"open" | "goto" | "navigate" => r##"
|
||||||
|
agent-browser open - Navigate to a URL
|
||||||
|
|
||||||
|
Usage: agent-browser open <url>
|
||||||
|
|
||||||
|
Navigates the browser to the specified URL. If no protocol is provided,
|
||||||
|
https:// is automatically prepended.
|
||||||
|
|
||||||
|
Aliases: goto, navigate
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
--headed Show browser window
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser open example.com
|
||||||
|
agent-browser open https://github.com
|
||||||
|
agent-browser open localhost:3000
|
||||||
|
"##,
|
||||||
|
"back" => r##"
|
||||||
|
agent-browser back - Navigate back in history
|
||||||
|
|
||||||
|
Usage: agent-browser back
|
||||||
|
|
||||||
|
Goes back one page in the browser history, equivalent to clicking
|
||||||
|
the browser's back button.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser back
|
||||||
|
"##,
|
||||||
|
"forward" => r##"
|
||||||
|
agent-browser forward - Navigate forward in history
|
||||||
|
|
||||||
|
Usage: agent-browser forward
|
||||||
|
|
||||||
|
Goes forward one page in the browser history, equivalent to clicking
|
||||||
|
the browser's forward button.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser forward
|
||||||
|
"##,
|
||||||
|
"reload" => r##"
|
||||||
|
agent-browser reload - Reload the current page
|
||||||
|
|
||||||
|
Usage: agent-browser reload
|
||||||
|
|
||||||
|
Reloads the current page, equivalent to pressing F5 or clicking
|
||||||
|
the browser's reload button.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser reload
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Core Actions ===
|
||||||
|
"click" => r##"
|
||||||
|
agent-browser click - Click an element
|
||||||
|
|
||||||
|
Usage: agent-browser click <selector>
|
||||||
|
|
||||||
|
Clicks on the specified element. The selector can be a CSS selector,
|
||||||
|
XPath, or an element reference from snapshot (e.g., @e1).
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser click "#submit-button"
|
||||||
|
agent-browser click @e1
|
||||||
|
agent-browser click "button.primary"
|
||||||
|
agent-browser click "//button[@type='submit']"
|
||||||
|
"##,
|
||||||
|
"dblclick" => r##"
|
||||||
|
agent-browser dblclick - Double-click an element
|
||||||
|
|
||||||
|
Usage: agent-browser dblclick <selector>
|
||||||
|
|
||||||
|
Double-clicks on the specified element. Useful for text selection
|
||||||
|
or triggering double-click handlers.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser dblclick "#editable-text"
|
||||||
|
agent-browser dblclick @e5
|
||||||
|
"##,
|
||||||
|
"fill" => r##"
|
||||||
|
agent-browser fill - Clear and fill an input field
|
||||||
|
|
||||||
|
Usage: agent-browser fill <selector> <text>
|
||||||
|
|
||||||
|
Clears the input field and fills it with the specified text.
|
||||||
|
This replaces any existing content in the field.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser fill "#email" "user@example.com"
|
||||||
|
agent-browser fill @e3 "Hello World"
|
||||||
|
agent-browser fill "input[name='search']" "query"
|
||||||
|
"##,
|
||||||
|
"type" => r##"
|
||||||
|
agent-browser type - Type text into an element
|
||||||
|
|
||||||
|
Usage: agent-browser type <selector> <text>
|
||||||
|
|
||||||
|
Types text into the specified element character by character.
|
||||||
|
Unlike fill, this does not clear existing content first.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser type "#search" "hello"
|
||||||
|
agent-browser type @e2 "additional text"
|
||||||
|
"##,
|
||||||
|
"hover" => r##"
|
||||||
|
agent-browser hover - Hover over an element
|
||||||
|
|
||||||
|
Usage: agent-browser hover <selector>
|
||||||
|
|
||||||
|
Moves the mouse to hover over the specified element. Useful for
|
||||||
|
triggering hover states or dropdown menus.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser hover "#dropdown-trigger"
|
||||||
|
agent-browser hover @e4
|
||||||
|
"##,
|
||||||
|
"focus" => r##"
|
||||||
|
agent-browser focus - Focus an element
|
||||||
|
|
||||||
|
Usage: agent-browser focus <selector>
|
||||||
|
|
||||||
|
Sets keyboard focus to the specified element.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser focus "#input-field"
|
||||||
|
agent-browser focus @e2
|
||||||
|
"##,
|
||||||
|
"check" => r##"
|
||||||
|
agent-browser check - Check a checkbox
|
||||||
|
|
||||||
|
Usage: agent-browser check <selector>
|
||||||
|
|
||||||
|
Checks a checkbox element. If already checked, no action is taken.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser check "#terms-checkbox"
|
||||||
|
agent-browser check @e7
|
||||||
|
"##,
|
||||||
|
"uncheck" => r##"
|
||||||
|
agent-browser uncheck - Uncheck a checkbox
|
||||||
|
|
||||||
|
Usage: agent-browser uncheck <selector>
|
||||||
|
|
||||||
|
Unchecks a checkbox element. If already unchecked, no action is taken.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser uncheck "#newsletter-opt-in"
|
||||||
|
agent-browser uncheck @e8
|
||||||
|
"##,
|
||||||
|
"select" => r##"
|
||||||
|
agent-browser select - Select a dropdown option
|
||||||
|
|
||||||
|
Usage: agent-browser select <selector> <value>
|
||||||
|
|
||||||
|
Selects an option in a <select> dropdown by its value attribute.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser select "#country" "US"
|
||||||
|
agent-browser select @e5 "option2"
|
||||||
|
"##,
|
||||||
|
"drag" => r##"
|
||||||
|
agent-browser drag - Drag and drop
|
||||||
|
|
||||||
|
Usage: agent-browser drag <source> <target>
|
||||||
|
|
||||||
|
Drags an element from source to target location.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser drag "#draggable" "#drop-zone"
|
||||||
|
agent-browser drag @e1 @e2
|
||||||
|
"##,
|
||||||
|
"upload" => r##"
|
||||||
|
agent-browser upload - Upload files
|
||||||
|
|
||||||
|
Usage: agent-browser upload <selector> <files...>
|
||||||
|
|
||||||
|
Uploads one or more files to a file input element.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser upload "#file-input" ./document.pdf
|
||||||
|
agent-browser upload @e3 ./image1.png ./image2.png
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Keyboard ===
|
||||||
|
"press" | "key" => r##"
|
||||||
|
agent-browser press - Press a key or key combination
|
||||||
|
|
||||||
|
Usage: agent-browser press <key>
|
||||||
|
|
||||||
|
Presses a key or key combination. Supports special keys and modifiers.
|
||||||
|
|
||||||
|
Aliases: key
|
||||||
|
|
||||||
|
Special Keys:
|
||||||
|
Enter, Tab, Escape, Backspace, Delete, Space
|
||||||
|
ArrowUp, ArrowDown, ArrowLeft, ArrowRight
|
||||||
|
Home, End, PageUp, PageDown
|
||||||
|
F1-F12
|
||||||
|
|
||||||
|
Modifiers (combine with +):
|
||||||
|
Control, Alt, Shift, Meta
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser press Enter
|
||||||
|
agent-browser press Tab
|
||||||
|
agent-browser press Control+a
|
||||||
|
agent-browser press Control+Shift+s
|
||||||
|
agent-browser press Escape
|
||||||
|
"##,
|
||||||
|
"keydown" => r##"
|
||||||
|
agent-browser keydown - Press a key down (without release)
|
||||||
|
|
||||||
|
Usage: agent-browser keydown <key>
|
||||||
|
|
||||||
|
Presses a key down without releasing it. Use keyup to release.
|
||||||
|
Useful for holding modifier keys.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser keydown Shift
|
||||||
|
agent-browser keydown Control
|
||||||
|
"##,
|
||||||
|
"keyup" => r##"
|
||||||
|
agent-browser keyup - Release a key
|
||||||
|
|
||||||
|
Usage: agent-browser keyup <key>
|
||||||
|
|
||||||
|
Releases a key that was pressed with keydown.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser keyup Shift
|
||||||
|
agent-browser keyup Control
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Scroll ===
|
||||||
|
"scroll" => r##"
|
||||||
|
agent-browser scroll - Scroll the page
|
||||||
|
|
||||||
|
Usage: agent-browser scroll [direction] [amount]
|
||||||
|
|
||||||
|
Scrolls the page in the specified direction.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
direction up, down, left, right (default: down)
|
||||||
|
amount Pixels to scroll (default: 300)
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser scroll
|
||||||
|
agent-browser scroll down 500
|
||||||
|
agent-browser scroll up 200
|
||||||
|
agent-browser scroll left 100
|
||||||
|
"##,
|
||||||
|
"scrollintoview" | "scrollinto" => r##"
|
||||||
|
agent-browser scrollintoview - Scroll element into view
|
||||||
|
|
||||||
|
Usage: agent-browser scrollintoview <selector>
|
||||||
|
|
||||||
|
Scrolls the page until the specified element is visible in the viewport.
|
||||||
|
|
||||||
|
Aliases: scrollinto
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser scrollintoview "#footer"
|
||||||
|
agent-browser scrollintoview @e15
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Wait ===
|
||||||
|
"wait" => r##"
|
||||||
|
agent-browser wait - Wait for condition
|
||||||
|
|
||||||
|
Usage: agent-browser wait <selector|ms|option>
|
||||||
|
|
||||||
|
Waits for an element to appear, a timeout, or other conditions.
|
||||||
|
|
||||||
|
Modes:
|
||||||
|
<selector> Wait for element to appear
|
||||||
|
<ms> Wait for specified milliseconds
|
||||||
|
--url <pattern> Wait for URL to match pattern
|
||||||
|
--load <state> Wait for load state (load, domcontentloaded, networkidle)
|
||||||
|
--fn <expression> Wait for JavaScript expression to be truthy
|
||||||
|
--text <text> Wait for text to appear on page
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser wait "#loading-spinner"
|
||||||
|
agent-browser wait 2000
|
||||||
|
agent-browser wait --url "**/dashboard"
|
||||||
|
agent-browser wait --load networkidle
|
||||||
|
agent-browser wait --fn "window.appReady === true"
|
||||||
|
agent-browser wait --text "Welcome back"
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Screenshot/PDF ===
|
||||||
|
"screenshot" => r##"
|
||||||
|
agent-browser screenshot - Take a screenshot
|
||||||
|
|
||||||
|
Usage: agent-browser screenshot [path]
|
||||||
|
|
||||||
|
Captures a screenshot of the current page. If no path is provided,
|
||||||
|
outputs base64-encoded image data.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--full, -f Capture full page (not just viewport)
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser screenshot
|
||||||
|
agent-browser screenshot ./screenshot.png
|
||||||
|
agent-browser screenshot --full ./full-page.png
|
||||||
|
"##,
|
||||||
|
"pdf" => r##"
|
||||||
|
agent-browser pdf - Save page as PDF
|
||||||
|
|
||||||
|
Usage: agent-browser pdf <path>
|
||||||
|
|
||||||
|
Saves the current page as a PDF file.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser pdf ./page.pdf
|
||||||
|
agent-browser pdf ~/Documents/report.pdf
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Snapshot ===
|
||||||
|
"snapshot" => r##"
|
||||||
|
agent-browser snapshot - Get accessibility tree snapshot
|
||||||
|
|
||||||
|
Usage: agent-browser snapshot [options]
|
||||||
|
|
||||||
|
Returns an accessibility tree representation of the page with element
|
||||||
|
references (like @e1, @e2) that can be used in subsequent commands.
|
||||||
|
Designed for AI agents to understand page structure.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-i, --interactive Only include interactive elements
|
||||||
|
-c, --compact Remove empty structural elements
|
||||||
|
-d, --depth <n> Limit tree depth
|
||||||
|
-s, --selector <sel> Scope snapshot to CSS selector
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser snapshot
|
||||||
|
agent-browser snapshot -i
|
||||||
|
agent-browser snapshot --compact --depth 5
|
||||||
|
agent-browser snapshot -s "#main-content"
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Eval ===
|
||||||
|
"eval" => r##"
|
||||||
|
agent-browser eval - Execute JavaScript
|
||||||
|
|
||||||
|
Usage: agent-browser eval <script>
|
||||||
|
|
||||||
|
Executes JavaScript code in the browser context and returns the result.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser eval "document.title"
|
||||||
|
agent-browser eval "window.location.href"
|
||||||
|
agent-browser eval "document.querySelectorAll('a').length"
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Close ===
|
||||||
|
"close" | "quit" | "exit" => r##"
|
||||||
|
agent-browser close - Close the browser
|
||||||
|
|
||||||
|
Usage: agent-browser close
|
||||||
|
|
||||||
|
Closes the browser instance for the current session.
|
||||||
|
|
||||||
|
Aliases: quit, exit
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser close
|
||||||
|
agent-browser close --session mysession
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Get ===
|
||||||
|
"get" => r##"
|
||||||
|
agent-browser get - Retrieve information from elements or page
|
||||||
|
|
||||||
|
Usage: agent-browser get <subcommand> [args]
|
||||||
|
|
||||||
|
Retrieves various types of information from elements or the page.
|
||||||
|
|
||||||
|
Subcommands:
|
||||||
|
text <selector> Get text content of element
|
||||||
|
html <selector> Get inner HTML of element
|
||||||
|
value <selector> Get value of input element
|
||||||
|
attr <selector> <name> Get attribute value
|
||||||
|
title Get page title
|
||||||
|
url Get current URL
|
||||||
|
count <selector> Count matching elements
|
||||||
|
box <selector> Get bounding box (x, y, width, height)
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser get text @e1
|
||||||
|
agent-browser get html "#content"
|
||||||
|
agent-browser get value "#email-input"
|
||||||
|
agent-browser get attr "#link" href
|
||||||
|
agent-browser get title
|
||||||
|
agent-browser get url
|
||||||
|
agent-browser get count "li.item"
|
||||||
|
agent-browser get box "#header"
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Is ===
|
||||||
|
"is" => r##"
|
||||||
|
agent-browser is - Check element state
|
||||||
|
|
||||||
|
Usage: agent-browser is <subcommand> <selector>
|
||||||
|
|
||||||
|
Checks the state of an element and returns true/false.
|
||||||
|
|
||||||
|
Subcommands:
|
||||||
|
visible <selector> Check if element is visible
|
||||||
|
enabled <selector> Check if element is enabled (not disabled)
|
||||||
|
checked <selector> Check if checkbox/radio is checked
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser is visible "#modal"
|
||||||
|
agent-browser is enabled "#submit-btn"
|
||||||
|
agent-browser is checked "#agree-checkbox"
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Find ===
|
||||||
|
"find" => r##"
|
||||||
|
agent-browser find - Find and interact with elements by locator
|
||||||
|
|
||||||
|
Usage: agent-browser find <locator> <value> [action] [text]
|
||||||
|
|
||||||
|
Finds elements using semantic locators and optionally performs an action.
|
||||||
|
|
||||||
|
Locators:
|
||||||
|
role <role> Find by ARIA role (--name <n>, --exact)
|
||||||
|
text <text> Find by text content (--exact)
|
||||||
|
label <label> Find by associated label (--exact)
|
||||||
|
placeholder <text> Find by placeholder text (--exact)
|
||||||
|
alt <text> Find by alt text (--exact)
|
||||||
|
title <text> Find by title attribute (--exact)
|
||||||
|
testid <id> Find by data-testid attribute
|
||||||
|
first <selector> First matching element
|
||||||
|
last <selector> Last matching element
|
||||||
|
nth <index> <selector> Nth matching element (0-based)
|
||||||
|
|
||||||
|
Actions (default: click):
|
||||||
|
click, fill, type, hover, focus, check, uncheck
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--name <name> Filter role by accessible name
|
||||||
|
--exact Require exact text match
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser find role button click --name Submit
|
||||||
|
agent-browser find text "Sign In" click
|
||||||
|
agent-browser find label "Email" fill "user@example.com"
|
||||||
|
agent-browser find placeholder "Search..." type "query"
|
||||||
|
agent-browser find testid "login-form" click
|
||||||
|
agent-browser find first "li.item" click
|
||||||
|
agent-browser find nth 2 ".card" hover
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Mouse ===
|
||||||
|
"mouse" => r##"
|
||||||
|
agent-browser mouse - Low-level mouse operations
|
||||||
|
|
||||||
|
Usage: agent-browser mouse <subcommand> [args]
|
||||||
|
|
||||||
|
Performs low-level mouse operations for precise control.
|
||||||
|
|
||||||
|
Subcommands:
|
||||||
|
move <x> <y> Move mouse to coordinates
|
||||||
|
down [button] Press mouse button (left, right, middle)
|
||||||
|
up [button] Release mouse button
|
||||||
|
wheel <dy> [dx] Scroll mouse wheel
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser mouse move 100 200
|
||||||
|
agent-browser mouse down
|
||||||
|
agent-browser mouse up
|
||||||
|
agent-browser mouse down right
|
||||||
|
agent-browser mouse wheel 100
|
||||||
|
agent-browser mouse wheel -50 0
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Set ===
|
||||||
|
"set" => r##"
|
||||||
|
agent-browser set - Configure browser settings
|
||||||
|
|
||||||
|
Usage: agent-browser set <setting> [args]
|
||||||
|
|
||||||
|
Configures various browser settings and emulation options.
|
||||||
|
|
||||||
|
Settings:
|
||||||
|
viewport <w> <h> Set viewport size
|
||||||
|
device <name> Emulate device (e.g., "iPhone 12")
|
||||||
|
geo <lat> <lng> Set geolocation
|
||||||
|
offline [on|off] Toggle offline mode
|
||||||
|
headers <json> Set extra HTTP headers
|
||||||
|
credentials <user> <pass> Set HTTP authentication
|
||||||
|
media [dark|light] Set color scheme preference
|
||||||
|
[reduced-motion] Enable reduced motion
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser set viewport 1920 1080
|
||||||
|
agent-browser set device "iPhone 12"
|
||||||
|
agent-browser set geo 37.7749 -122.4194
|
||||||
|
agent-browser set offline on
|
||||||
|
agent-browser set headers '{"X-Custom": "value"}'
|
||||||
|
agent-browser set credentials admin secret123
|
||||||
|
agent-browser set media dark
|
||||||
|
agent-browser set media light reduced-motion
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Network ===
|
||||||
|
"network" => r##"
|
||||||
|
agent-browser network - Network interception and monitoring
|
||||||
|
|
||||||
|
Usage: agent-browser network <subcommand> [args]
|
||||||
|
|
||||||
|
Intercept, mock, or monitor network requests.
|
||||||
|
|
||||||
|
Subcommands:
|
||||||
|
route <url> [options] Intercept requests matching URL pattern
|
||||||
|
--abort Abort matching requests
|
||||||
|
--body <json> Respond with custom body
|
||||||
|
unroute [url] Remove route (all if no URL)
|
||||||
|
requests [options] List captured requests
|
||||||
|
--clear Clear request log
|
||||||
|
--filter <pattern> Filter by URL pattern
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser network route "**/api/*" --abort
|
||||||
|
agent-browser network route "**/data.json" --body '{"mock": true}'
|
||||||
|
agent-browser network unroute
|
||||||
|
agent-browser network requests
|
||||||
|
agent-browser network requests --filter "api"
|
||||||
|
agent-browser network requests --clear
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Storage ===
|
||||||
|
"storage" => r##"
|
||||||
|
agent-browser storage - Manage web storage
|
||||||
|
|
||||||
|
Usage: agent-browser storage <type> [operation] [key] [value]
|
||||||
|
|
||||||
|
Manage localStorage and sessionStorage.
|
||||||
|
|
||||||
|
Types:
|
||||||
|
local localStorage
|
||||||
|
session sessionStorage
|
||||||
|
|
||||||
|
Operations:
|
||||||
|
get [key] Get all storage or specific key
|
||||||
|
set <key> <value> Set a key-value pair
|
||||||
|
clear Clear all storage
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser storage local
|
||||||
|
agent-browser storage local get authToken
|
||||||
|
agent-browser storage local set theme "dark"
|
||||||
|
agent-browser storage local clear
|
||||||
|
agent-browser storage session get userId
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Cookies ===
|
||||||
|
"cookies" => r##"
|
||||||
|
agent-browser cookies - Manage browser cookies
|
||||||
|
|
||||||
|
Usage: agent-browser cookies [operation] [args]
|
||||||
|
|
||||||
|
Manage browser cookies for the current context.
|
||||||
|
|
||||||
|
Operations:
|
||||||
|
get Get all cookies (default)
|
||||||
|
set <name> <value> Set a cookie
|
||||||
|
clear Clear all cookies
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser cookies
|
||||||
|
agent-browser cookies get
|
||||||
|
agent-browser cookies set session_id "abc123"
|
||||||
|
agent-browser cookies clear
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Tabs ===
|
||||||
|
"tab" => r##"
|
||||||
|
agent-browser tab - Manage browser tabs
|
||||||
|
|
||||||
|
Usage: agent-browser tab [operation] [args]
|
||||||
|
|
||||||
|
Manage browser tabs in the current window.
|
||||||
|
|
||||||
|
Operations:
|
||||||
|
list List all tabs (default)
|
||||||
|
new [url] Open new tab
|
||||||
|
close [index] Close tab (current if no index)
|
||||||
|
<index> Switch to tab by index
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser tab
|
||||||
|
agent-browser tab list
|
||||||
|
agent-browser tab new
|
||||||
|
agent-browser tab new https://example.com
|
||||||
|
agent-browser tab 2
|
||||||
|
agent-browser tab close
|
||||||
|
agent-browser tab close 1
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Window ===
|
||||||
|
"window" => r##"
|
||||||
|
agent-browser window - Manage browser windows
|
||||||
|
|
||||||
|
Usage: agent-browser window <operation>
|
||||||
|
|
||||||
|
Manage browser windows.
|
||||||
|
|
||||||
|
Operations:
|
||||||
|
new Open new browser window
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser window new
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Frame ===
|
||||||
|
"frame" => r##"
|
||||||
|
agent-browser frame - Switch frame context
|
||||||
|
|
||||||
|
Usage: agent-browser frame <selector|main>
|
||||||
|
|
||||||
|
Switch to an iframe or back to the main frame.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
<selector> CSS selector for iframe
|
||||||
|
main Switch back to main frame
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser frame "#embed-iframe"
|
||||||
|
agent-browser frame "iframe[name='content']"
|
||||||
|
agent-browser frame main
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Dialog ===
|
||||||
|
"dialog" => r##"
|
||||||
|
agent-browser dialog - Handle browser dialogs
|
||||||
|
|
||||||
|
Usage: agent-browser dialog <response> [text]
|
||||||
|
|
||||||
|
Respond to browser dialogs (alert, confirm, prompt).
|
||||||
|
|
||||||
|
Operations:
|
||||||
|
accept [text] Accept dialog, optionally with prompt text
|
||||||
|
dismiss Dismiss/cancel dialog
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser dialog accept
|
||||||
|
agent-browser dialog accept "my input"
|
||||||
|
agent-browser dialog dismiss
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Trace ===
|
||||||
|
"trace" => r##"
|
||||||
|
agent-browser trace - Record execution trace
|
||||||
|
|
||||||
|
Usage: agent-browser trace <operation> [path]
|
||||||
|
|
||||||
|
Record a trace for debugging with Playwright Trace Viewer.
|
||||||
|
|
||||||
|
Operations:
|
||||||
|
start [path] Start recording trace
|
||||||
|
stop [path] Stop recording and save trace
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser trace start
|
||||||
|
agent-browser trace start ./my-trace
|
||||||
|
agent-browser trace stop
|
||||||
|
agent-browser trace stop ./debug-trace.zip
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Console/Errors ===
|
||||||
|
"console" => r##"
|
||||||
|
agent-browser console - View console logs
|
||||||
|
|
||||||
|
Usage: agent-browser console [--clear]
|
||||||
|
|
||||||
|
View browser console output (log, warn, error, info).
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--clear Clear console log buffer
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser console
|
||||||
|
agent-browser console --clear
|
||||||
|
"##,
|
||||||
|
"errors" => r##"
|
||||||
|
agent-browser errors - View page errors
|
||||||
|
|
||||||
|
Usage: agent-browser errors [--clear]
|
||||||
|
|
||||||
|
View JavaScript errors and uncaught exceptions.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--clear Clear error buffer
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser errors
|
||||||
|
agent-browser errors --clear
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Highlight ===
|
||||||
|
"highlight" => r##"
|
||||||
|
agent-browser highlight - Highlight an element
|
||||||
|
|
||||||
|
Usage: agent-browser highlight <selector>
|
||||||
|
|
||||||
|
Visually highlights an element on the page for debugging.
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser highlight "#target-element"
|
||||||
|
agent-browser highlight @e5
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === State ===
|
||||||
|
"state" => r##"
|
||||||
|
agent-browser state - Save/load browser state
|
||||||
|
|
||||||
|
Usage: agent-browser state <operation> <path>
|
||||||
|
|
||||||
|
Save or restore browser state (cookies, localStorage, sessionStorage).
|
||||||
|
|
||||||
|
Operations:
|
||||||
|
save <path> Save current state to file
|
||||||
|
load <path> Load state from file
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser state save ./auth-state.json
|
||||||
|
agent-browser state load ./auth-state.json
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Session ===
|
||||||
|
"session" => r##"
|
||||||
|
agent-browser session - Manage sessions
|
||||||
|
|
||||||
|
Usage: agent-browser session [operation]
|
||||||
|
|
||||||
|
Manage isolated browser sessions. Each session has its own browser
|
||||||
|
instance with separate cookies, storage, and state.
|
||||||
|
|
||||||
|
Operations:
|
||||||
|
(none) Show current session name
|
||||||
|
list List all active sessions
|
||||||
|
|
||||||
|
Environment:
|
||||||
|
AGENT_BROWSER_SESSION Default session name
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
--json Output as JSON
|
||||||
|
--session <name> Use specific session
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser session
|
||||||
|
agent-browser session list
|
||||||
|
agent-browser --session test open example.com
|
||||||
|
"##,
|
||||||
|
|
||||||
|
// === Install ===
|
||||||
|
"install" => r##"
|
||||||
|
agent-browser install - Install browser binaries
|
||||||
|
|
||||||
|
Usage: agent-browser install [--with-deps]
|
||||||
|
|
||||||
|
Downloads and installs browser binaries required for automation.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-d, --with-deps Also install system dependencies (Linux only)
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
agent-browser install
|
||||||
|
agent-browser install --with-deps
|
||||||
|
"##,
|
||||||
|
|
||||||
|
_ => return false,
|
||||||
|
};
|
||||||
|
println!("{}", help.trim());
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
pub fn print_help() {
|
pub fn print_help() {
|
||||||
println!(
|
println!(
|
||||||
r#"
|
r#"
|
||||||
|
|||||||
Reference in New Issue
Block a user