agentchrome 1.62.0

A CLI tool for browser automation via the Chrome DevTools Protocol
Documentation
# Defect Report: console read always returns empty array

**Issue**: #103
**Date**: 2026-02-16
**Status**: Approved
**Author**: Claude (spec generation)
**Severity**: High
**Related Spec**: specs/feature-console-message-reading-with-filtering/

---

## Reproduction

### Steps to Reproduce

1. `agentchrome connect --launch --headless`
2. `agentchrome navigate https://www.google.com --wait-until load`
3. `agentchrome js exec "console.log('info msg'); console.error('err msg'); 42"` — the JS response includes `console: [{level: "log", text: "info msg"}]` inline
4. `agentchrome console read``[]`
5. Inject page-level script: `agentchrome js exec "var s = document.createElement('script'); s.textContent = 'console.log(\"page\")'; document.head.appendChild(s);"`
6. `agentchrome console read``[]`
7. `agentchrome console read --errors-only``[]`

### Environment

| Factor | Value |
|--------|-------|
| **OS / Platform** | macOS (Darwin 25.3.0) |
| **Version / Commit** | `c584d2d` (main) |
| **Browser / Runtime** | Chrome via CDP |
| **Configuration** | Default (headless or headed) |

### Frequency

Always — 100% reproducible on any page that has generated console messages.

---

## Expected vs Actual

| | Description |
|---|-------------|
| **Expected** | `console read` returns a JSON array of captured console messages with `id`, `level`, `text`, and `timestamp` fields. Filters (`--type`, `--errors-only`) work on the captured list. |
| **Actual** | `console read` returns `[]` every time. Console messages generated by `js exec` appear in the JS response's inline `console` field but not in `console read`. Page-level console output is also not captured. Only `console follow` (streaming) works. |

### Error Output

```
$ agentchrome console read
[]
```

No error — the command succeeds with exit code 0 but returns an empty array regardless of console activity.

---

## Acceptance Criteria

**IMPORTANT: Each criterion becomes a Gherkin BDD test scenario.**

### AC1: Console read returns captured messages

**Given** a page has generated console messages (e.g., via injected script)
**When** I run `agentchrome console read`
**Then** the output is a JSON array containing the messages
**And** each entry has `id`, `type`, `text`, and `timestamp` fields
**And** the exit code should be 0

### AC2: Errors-only filter works on captured messages

**Given** a page has generated log, warn, and error console messages
**When** I run `agentchrome console read --errors-only`
**Then** only error-level messages are returned
**And** the result is non-empty

### AC3: Console messages persist across commands

**Given** `console.log()` was called during a previous command (e.g., via `js exec`)
**When** I run `console read` in a subsequent invocation
**Then** the previously logged messages are available

**Note**: This AC requires that the fix strategy replays console activity so that messages generated before the current CLI invocation are capturable. Per the retrospective learning on CDP session isolation (`steering/retrospective.md`), each CLI invocation creates a fresh CDP session with no event history — the fix must account for this.

### AC4: Console follow streaming still works

**Given** Chrome is running with a page open
**When** I run `agentchrome console follow --timeout 2000` and console messages are generated
**Then** messages are streamed as JSON lines
**And** the existing follow behavior is unchanged

---

## Functional Requirements

| ID | Requirement | Priority |
|----|-------------|----------|
| FR1 | `console read` must return console messages from the current page — it must not rely solely on a 100ms event drain window after connecting | Must |
| FR2 | Console capture must work without requiring `console follow` to be running in a separate terminal | Must |
| FR3 | Filters (`--type`, `--errors-only`, `--limit`, `--page`) must work correctly on the captured message list | Must |
| FR4 | The fix must not break `console follow` streaming behavior | Must |

---

## Out of Scope

- Console message persistence across page navigations (unless `--include-preserved`)
- Console message body/argument capture beyond text
- Changes to `console follow` streaming behavior
- Changes to `js exec` inline console capture
- Long-running background daemon for persistent console monitoring

---

## Validation Checklist

- [x] Reproduction steps are repeatable and specific
- [x] Expected vs actual behavior is clearly stated
- [x] Severity is assessed
- [x] Acceptance criteria use Given/When/Then format
- [x] At least one regression scenario is included (AC4)
- [x] Fix scope is minimal — no feature work mixed in
- [x] Out of scope is defined