|
| 1 | +# Implementation Plan: Chrome DevTools CLI & MCP Optimizations |
| 2 | + |
| 3 | +This plan implements optimizations for the `take_snapshot` tool to improve agent efficiency by reducing the volume of DOM data transmitted. It ensures full compatibility with both the Model Context Protocol (MCP) and the `chrome-devtools` CLI. |
| 4 | + |
| 5 | +## Progress Overview |
| 6 | + |
| 7 | +- [x] **Step 0: Save Plan to Project** |
| 8 | + - [x] Save this plan to `/Users/hablich/src/internal/chrome-devtools-mcp/snapshot_improvement_plan.md` |
| 9 | +- [x] **Step 0: Save Plan to Project** |
| 10 | +- [x] **PR 1: Native Semantic Filtering** (`feat/semantic-filtering`) |
| 11 | + - [x] Create branch and apply filtering changes |
| 12 | + - [x] Include `post-build.ts` fix (on `main`) |
| 13 | + - [x] Verify tests and CLI |
| 14 | + - [x] Commit |
| 15 | +- [x] **PR 2: Built-in "Interactive Only" Mode** (`feat/interactive-mode`) |
| 16 | + - [x] Create branch and apply interactive mode changes |
| 17 | + - [x] Include `post-build.ts` fix |
| 18 | + - [x] Verify tests and CLI |
| 19 | + - [x] Commit |
| 20 | +- [x] **PR 3: Session-Based Snapshot Diffs** (`feat/snapshot-diffs`) |
| 21 | + - [x] Create branch and apply diffing + UID stability changes |
| 22 | + - [x] Include `post-build.ts` fix |
| 23 | + - [x] Verify tests and CLI |
| 24 | + - [x] Commit |
| 25 | +- [x] **Verification** |
| 26 | + - [x] Check if each branch works independently from each other. |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## PR 1: Native Semantic Filtering |
| 31 | + |
| 32 | +**Objective**: Enable agents to request only specific types of elements from the accessibility tree. |
| 33 | + |
| 34 | +- **Flags**: `role`, `name`, `text` |
| 35 | +- **Tasks**: |
| 36 | + - [ ] Update `SnapshotParams` in `src/tools/ToolDefinition.ts`. |
| 37 | + - [ ] Update `take_snapshot` tool schema in `src/tools/snapshot.ts`. |
| 38 | + - [ ] Implement `filterTree` in `McpContext.ts` to prune nodes that do not match and do not have matching descendants. |
| 39 | + - [ ] Update `createTextSnapshot` to use `filterTree`. |
| 40 | + - [ ] Add tests to `tests/McpContext.test.ts` verifying `role`, `name`, and `text` filters. |
| 41 | + |
| 42 | +## PR 2: Built-in "Interactive Only" Mode |
| 43 | + |
| 44 | +**Objective**: Strip non-actionable content from snapshots. |
| 45 | + |
| 46 | +- **Flag**: `interactive` |
| 47 | +- **Tasks**: |
| 48 | + - [ ] Define "interactive" roles: `button`, `link`, `menuitem`, `checkbox`, `radio`, `textbox`, `searchbox`, `combobox`. |
| 49 | + - [ ] Implement `isInteractive` check in `McpContext.ts`. |
| 50 | + - [ ] Use `DOMDebugger.getEventListeners` to include nodes with event listeners. |
| 51 | + - [ ] Update `createTextSnapshot` to use this logic when `interactive: true`. |
| 52 | + - [ ] Add tests to `tests/tools/snapshot.test.ts` with complex HTML to verify pruning of static text. |
| 53 | + |
| 54 | +## PR 3: Session-Based Snapshot Diffs |
| 55 | + |
| 56 | +**Objective**: Send only changes since the last observation. |
| 57 | + |
| 58 | +- **Flag**: `diff` |
| 59 | +- **Tasks**: |
| 60 | + - [ ] Update `McpPage` to store `lastSnapshot` and reset on `framenavigated` / `load`. |
| 61 | + - [ ] Implement semantic diffing by `uid`. |
| 62 | + - [ ] Update `SnapshotFormatter` to render diffs with `[+]`, `[-]`, `[*]`. |
| 63 | + - [ ] Add tests to `tests/McpContext.test.ts` for multiple snapshot calls, ensuring only deltas are returned and navigation resets the cache. |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## Verification & Testing Strategy |
| 68 | + |
| 69 | +- **Infrastructure**: Use `withMcpContext` in existing test files. |
| 70 | +- **MCP Verification**: Run the server and call `take_snapshot` with new parameters. |
| 71 | +- **CLI Verification**: |
| 72 | + - Run `npm run cli:generate` after each PR. |
| 73 | + - Run `chrome-devtools take_snapshot --help` to check for new flags. |
| 74 | + - Execute commands like `chrome-devtools take_snapshot --role button` and verify output. |
| 75 | +- **Daemon Verification**: Ensure that `diff` mode works correctly when calling the CLI multiple times (state should be preserved in the running daemon). |
0 commit comments