# Chrome Control Enhanced Navigation for LLMs

This document explains the enhanced navigation capabilities implemented in the Chrome Control MCP server, specifically designed for LLMs (Large Language Models) to efficiently interact with web browsers.

## Enhanced Navigation Overview

The enhanced navigation feature allows LLMs to specify exactly what data they want to receive from a page during navigation, reducing token usage and providing more targeted information. This enables more efficient browsing workflows with fewer back-and-forth interactions.

### Key Features

1. **Customizable Response Format**: Specify what data to include in the navigation response
2. **Element Filtering**: Query specific DOM elements by selector and filter by attributes
3. **Screenshot Integration**: Include screenshots in navigation responses
4. **Input Field Detection**: Automatically detect and return details about input fields
5. **Link Extraction**: Get a list of all links on a page in a single request

## Using Enhanced Navigation

When calling the `chrome_navigate` tool, you can now include a `responseFormat` parameter to customize what data is returned:

```json
{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "tools.call",
  "params": {
    "name": "chrome_navigate",
    "arguments": {
      "url": "https://example.com",
      "browserId": "browser-uuid-here",
      "responseFormat": {
        "screenshot": true,
        "fullPage": false,
        "pageText": false,
        "pageTitle": true,
        "elements": {
          "selector": "input[type='text']",
          "attributes": ["placeholder", "name", "id"],
          "includeText": true,
          "includeHTML": false
        },
        "links": true,
        "inputs": true
      }
    }
  }
}
```

### Response Format Options

 < /dev/null |  Option | Type | Description |
|--------|------|-------------|
| `screenshot` | boolean | Include a screenshot in the response |
| `fullPage` | boolean | Take a full-page screenshot instead of viewport only |
| `pageText` | boolean | Include all page text in the response |
| `pageTitle` | boolean | Include page title in the response (default: true) |
| `elements` | object | Element data to include in response |
| `elements.selector` | string | CSS selector to find elements |
| `elements.attributes` | string[] | Element attributes to include in response |
| `elements.includeText` | boolean | Include element text content |
| `elements.includeHTML` | boolean | Include element HTML content |
| `links` | boolean | Include all links on the page |
| `inputs` | boolean | Include all input fields on the page |

## LLM Interaction Flow Example

Here's an example of how an LLM can use enhanced navigation to complete a task with fewer interactions:

### Traditional Approach (Multiple Calls)

1. LLM: Navigate to example.com
2. LLM: Take a screenshot
3. LLM: Find all input fields
4. LLM: Extract text from specific elements
5. LLM: Fill a form field
6. LLM: Click submit

### Enhanced Approach (Fewer Calls)

1. LLM: Navigate to example.com with responseFormat that includes screenshot, inputs, and elements
2. LLM: Fill a form field and submit (the LLM already has all the information needed)

## Example Implementation

The `duckduckgo-puppies.js` example demonstrates how to:

1. Navigate to DuckDuckGo with custom response format
2. Extract input field information from the response
3. Fill in the search box and perform a search
4. Take a screenshot of results with custom element selection

Run the example with:

```bash
npm run example:puppies
```

## Benefits for LLM Integration

- **Reduced Token Usage**: Only receive data that's actually needed
- **Fewer Round Trips**: Complete complex tasks with fewer back-and-forth interactions
- **Customized Information Extraction**: Target specific information rather than processing the entire page
- **Optimized Screenshot Workflow**: Include screenshots directly in responses rather than as separate calls
- **Improved User Experience**: Faster, more responsive LLM interactions with browsers

## Implementation Details

The enhanced navigation implementation extends the existing navigation functionality with customizable response formats. It's designed to be backward compatible with existing code, while providing new features for LLM-optimized browser control.

The feature uses page evaluation and DOM manipulation to extract specific elements and attributes based on the requested response format, assembling a tailored response that minimizes token usage for LLM processing.
