|
| 1 | +// Browser command parser for CLI |
| 2 | +// |
| 3 | +// Defines the browser automation subcommand and its options. |
| 4 | + |
| 5 | +use clap::{Arg, ArgAction, Command}; |
| 6 | + |
| 7 | +pub fn browser_command() -> Command { |
| 8 | + Command::new("browser") |
| 9 | + .about("Browser automation using Playwright (headless browser control)") |
| 10 | + .long_about( |
| 11 | + "Browser automation commands for web scraping, testing, and interaction.\n\ |
| 12 | + \n\ |
| 13 | + Powered by Playwright with MCP integration for secure, isolated execution.\n\ |
| 14 | + \n\ |
| 15 | + Examples:\n\ |
| 16 | + osvm browser install Install/verify Playwright\n\ |
| 17 | + osvm browser status Show automation status\n\ |
| 18 | + osvm browser tools List available tools\n\ |
| 19 | + osvm browser navigate --url https://example.com Navigate to URL\n\ |
| 20 | + osvm browser screenshot --filename page.png Take screenshot\n\ |
| 21 | + osvm browser click --selector \"#submit-button\" Click element\n\ |
| 22 | + osvm browser type --selector \"#search\" --text \"query\" Type text\n\ |
| 23 | + osvm browser snapshot Get page snapshot\n\ |
| 24 | + osvm browser evaluate --script \"document.title\" Run JavaScript\n\ |
| 25 | + osvm browser wait-for --selector \".loading\" Wait for element\n\ |
| 26 | + \n\ |
| 27 | + Security:\n\ |
| 28 | + • Runs in sandboxed environment\n\ |
| 29 | + • Configurable timeouts\n\ |
| 30 | + • Screenshot verification\n\ |
| 31 | + • DOM access controls\n" |
| 32 | + ) |
| 33 | + .subcommand_required(false) |
| 34 | + .arg_required_else_help(true) |
| 35 | + .subcommand( |
| 36 | + Command::new("install") |
| 37 | + .about("Install or verify Playwright installation") |
| 38 | + .long_about( |
| 39 | + "Checks if Playwright is installed and available.\n\ |
| 40 | + In MCP environment, Playwright should be pre-installed." |
| 41 | + ) |
| 42 | + ) |
| 43 | + .subcommand( |
| 44 | + Command::new("status") |
| 45 | + .about("Show browser automation status and configuration") |
| 46 | + ) |
| 47 | + .subcommand( |
| 48 | + Command::new("tools") |
| 49 | + .about("List all available browser automation tools") |
| 50 | + .long_about( |
| 51 | + "Display all browser tools with their descriptions and input schemas.\n\ |
| 52 | + Use --debug for detailed schema information." |
| 53 | + ) |
| 54 | + ) |
| 55 | + .subcommand( |
| 56 | + Command::new("navigate") |
| 57 | + .about("Navigate to a URL") |
| 58 | + .arg( |
| 59 | + Arg::new("url") |
| 60 | + .long("url") |
| 61 | + .short('u') |
| 62 | + .value_name("URL") |
| 63 | + .required(true) |
| 64 | + .help("URL to navigate to") |
| 65 | + ) |
| 66 | + ) |
| 67 | + .subcommand( |
| 68 | + Command::new("screenshot") |
| 69 | + .about("Take a screenshot of the current page") |
| 70 | + .arg( |
| 71 | + Arg::new("filename") |
| 72 | + .long("filename") |
| 73 | + .short('f') |
| 74 | + .value_name("PATH") |
| 75 | + .help("Optional filename for the screenshot (default: timestamped)") |
| 76 | + ) |
| 77 | + ) |
| 78 | + .subcommand( |
| 79 | + Command::new("click") |
| 80 | + .about("Click an element on the page") |
| 81 | + .arg( |
| 82 | + Arg::new("selector") |
| 83 | + .long("selector") |
| 84 | + .short('s') |
| 85 | + .value_name("SELECTOR") |
| 86 | + .required(true) |
| 87 | + .help("CSS selector for the element to click") |
| 88 | + ) |
| 89 | + ) |
| 90 | + .subcommand( |
| 91 | + Command::new("type") |
| 92 | + .about("Type text into an element") |
| 93 | + .arg( |
| 94 | + Arg::new("selector") |
| 95 | + .long("selector") |
| 96 | + .short('s') |
| 97 | + .value_name("SELECTOR") |
| 98 | + .required(true) |
| 99 | + .help("CSS selector for the element") |
| 100 | + ) |
| 101 | + .arg( |
| 102 | + Arg::new("text") |
| 103 | + .long("text") |
| 104 | + .short('t') |
| 105 | + .value_name("TEXT") |
| 106 | + .required(true) |
| 107 | + .help("Text to type into the element") |
| 108 | + ) |
| 109 | + ) |
| 110 | + .subcommand( |
| 111 | + Command::new("snapshot") |
| 112 | + .about("Capture accessibility snapshot of the current page") |
| 113 | + .long_about( |
| 114 | + "Captures the page structure in a machine-readable format.\n\ |
| 115 | + Useful for understanding page layout and element hierarchy." |
| 116 | + ) |
| 117 | + ) |
| 118 | + .subcommand( |
| 119 | + Command::new("evaluate") |
| 120 | + .about("Evaluate JavaScript on the page") |
| 121 | + .arg( |
| 122 | + Arg::new("script") |
| 123 | + .long("script") |
| 124 | + .short('s') |
| 125 | + .value_name("JAVASCRIPT") |
| 126 | + .required(true) |
| 127 | + .help("JavaScript code to evaluate") |
| 128 | + ) |
| 129 | + ) |
| 130 | + .subcommand( |
| 131 | + Command::new("wait-for") |
| 132 | + .about("Wait for an element to appear on the page") |
| 133 | + .arg( |
| 134 | + Arg::new("selector") |
| 135 | + .long("selector") |
| 136 | + .short('s') |
| 137 | + .value_name("SELECTOR") |
| 138 | + .required(true) |
| 139 | + .help("CSS selector to wait for") |
| 140 | + ) |
| 141 | + .arg( |
| 142 | + Arg::new("timeout") |
| 143 | + .long("timeout") |
| 144 | + .short('t') |
| 145 | + .value_name("MILLISECONDS") |
| 146 | + .help("Timeout in milliseconds (default: 30000)") |
| 147 | + ) |
| 148 | + ) |
| 149 | +} |
0 commit comments