# Chrome Remote Daemon (cremote) A command line utility for automating browser interactions using Chrome's remote debugging protocol. The tool uses a daemon-client architecture to maintain persistent connections to the browser. ## Architecture The tool consists of two main components: 1. **Daemon (`cremotedaemon`)**: A long-running process that connects to Chrome and manages browser state 2. **Client (`cremote`)**: A command-line client that sends commands to the daemon This architecture provides several benefits: - Persistent browser connection across multiple commands - Reliable tab management - No need to reconnect for each command - Better performance ## MCP Server Cremote includes a Model Context Protocol (MCP) server that provides a structured API for LLMs and AI agents. Instead of using CLI commands, the MCP server offers: - **State Management**: Automatic tracking of tabs, history, and iframe context - **Intelligent Abstractions**: High-level tools that combine multiple operations - **Better Error Handling**: Rich error context for debugging - **Automatic Screenshots**: Built-in screenshot capture for documentation See the [MCP Server Documentation](mcp/README.md) for setup and usage instructions. ## Prerequisites - Go 1.16 or higher - A running instance of Chromium/Chrome with remote debugging enabled ### Starting Chromium with Remote Debugging Before using this tool, you **must** start Chromium with remote debugging enabled on port 9222: ```bash chromium --remote-debugging-port=9222 --user-data-dir=/tmp/chromium-debug ``` or for Chrome: ```bash google-chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug ``` **Important**: The `--user-data-dir` flag is required to prevent conflicts with existing browser instances. ## Usage ### Starting the Daemon First, start the daemon: ```bash cremotedaemon ``` By default, the daemon listens on port 8989. You can specify a different port: ```bash cremotedaemon --port=9090 ``` ### Using the Client Once the daemon is running, you can use the client to send commands: ``` cremote [options] ``` ### Commands - `version`: Show version information for CLI and daemon - `open-tab`: Open a new tab and return its ID - `load-url`: Load a URL in a tab - `fill-form`: Fill a form field with a value (also handles checkboxes, radio buttons, and dropdown selections) - `upload-file`: Upload a file to a file input - `submit-form`: Submit a form - `get-source`: Get the source code of a page - `get-element`: Get the HTML of an element - `click-element`: Click on an element - `close-tab`: Close a tab - `wait-navigation`: Wait for a navigation event - `eval-js`: Execute JavaScript code in a tab - `switch-iframe`: Switch to iframe context for subsequent commands - `switch-main`: Switch back to main page context - `list-tabs`: List all open tabs - `status`: Check if the daemon is running ### Current Tab Feature The tool tracks the current tab, so you can omit the `--tab` flag to use the most recently used tab. This makes interactive use more convenient. For example, after opening a tab: ```bash # Open a tab TAB_ID=$(cremote open-tab) # Load a URL in the current tab (no need to specify --tab) cremote load-url --url="https://example.com" # Click an element in the current tab cremote click-element --selector="a.button" ``` You can still specify a tab ID explicitly if you need to work with multiple tabs. Run `cremote -h` for more information on a specific command. ### Examples #### Check Daemon Status ```bash cremote status ``` #### Open a new tab ```bash cremote open-tab [--timeout=5] ``` This will return a tab ID that you can use in subsequent commands. The `--timeout` parameter specifies how many seconds to wait for the tab to open (default: 5 seconds). #### Load a URL in a tab ```bash cremote load-url --tab="" --url="https://example.com" [--timeout=5] ``` The `--timeout` parameter specifies how many seconds to wait for the URL to load (default: 5 seconds). #### Fill a form field ```bash cremote fill-form --tab="" --selector="#username" --value="user123" [--timeout=5] ``` The `--timeout` parameter specifies how many seconds to wait for the fill operation to complete (default: 5 seconds). #### Check/uncheck a checkbox or select a radio button The same `fill-form` command can be used to check/uncheck checkboxes or select radio buttons: ```bash # Check a checkbox cremote fill-form --tab="" --selector="#agree" --value="true" # Uncheck a checkbox cremote fill-form --tab="" --selector="#agree" --value="false" # Select a radio button cremote fill-form --tab="" --selector="#option2" --value="true" ``` Accepted values for checking a checkbox or selecting a radio button: `true`, `1`, `yes`, `on`, `checked`. Any other value will uncheck the checkbox or deselect the radio button. #### Select dropdown options The `fill-form` command can also be used to select options in dropdown elements: ```bash # Select by option text (visible text) cremote fill-form --tab="" --selector="#country" --value="United States" # Select by option value (value attribute) cremote fill-form --tab="" --selector="#state" --value="CA" ``` The command automatically detects dropdown elements and tries both option text and option value matching. This works with both `