Skip to content

feat(browser): unify page capture across daemon and CDP#834

Open
Astro-Han wants to merge 5 commits intojackwener:mainfrom
Astro-Han:fix/unified-capture-i810
Open

feat(browser): unify page capture across daemon and CDP#834
Astro-Han wants to merge 5 commits intojackwener:mainfrom
Astro-Han:fix/unified-capture-i810

Conversation

@Astro-Han
Copy link
Copy Markdown
Contributor

@Astro-Han Astro-Han commented Apr 6, 2026

Description

Implement the unified page capture work for issue #810 across daemon-backed and direct CDP pages.

This wires structured capture into execution and diagnostics, preserves daemon capture intent across navigation reattach, restores stale-extension compatibility paths, and adds regression coverage for the new lifecycle and fallback behavior.

Related issue:

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Documentation (if adding/modifying an adapter)

  • Added doc page under docs/adapters/ (if new adapter)
  • Updated docs/adapters/index.md table (if new adapter)
  • Updated sidebar in docs/.vitepress/config.mts (if new adapter)
  • Updated README.md / README.zh-CN.md when command discoverability changed
  • Used positional args for the command's primary subject unless a named flag is clearly better
  • Normalized expected adapter failures to CliError subclasses instead of raw Error

Screenshots / Output

npm test
Test Files  46 passed (46)
Tests 578 passed | 1 skipped (579)

npx tsc --noEmit
passed

cd extension && npm run build
vite build completed successfully

Copy link
Copy Markdown
Contributor Author

@Astro-Han Astro-Han left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context

This PR implements T3-1 (unified IPage capture interface) and T3-4 (real consoleMessages collection) from the #810 roadmap, following:

  • #829 (T2-1): diagnostic reads intercepted payloads (merged)
  • #831 (T2-2): explore contentType URL inference (open)

What this does for diagnostic and auto-fix

The goal of #810 is making opencli fix work better. When a command fails, the fix loop needs to know what happened in the browser. Before this PR, that data was poor:

  • Network requests came from the Performance API (URL and timing only, no headers or response body). The real CDP capture existed but was split across daemon and CDP paths, and got wiped on every navigation.
  • consoleMessages() returned [] in daemon mode. Uncaught exceptions and failed API calls were invisible.

Now, diagnostic reads from readNetworkCapture() first (full request/response with headers and body preview), falling back to the Performance API only when capture data is empty. consoleMessages('error') returns real warn + error entries from CDP Runtime events in both modes. Capture is command-scoped: starts before runCommand, stops in finally, and survives mid-command navigation via the captureIntents persistence mechanism.

In practice, opencli fix now sees the actual 401/403/500 responses, CORS errors, and console stack traces instead of guessing from a DOM snapshot.

Review notes

I fixed five items in v2 after self-review:

  1. Preferred-tab drift guard for owned sessions (resolveTab now validates window ID)
  2. Doctor version check relaxed to major.minor (exact match was too noisy)
  3. Console non-drain semantics documented (readConsoleCapture is intentionally a rolling buffer, unlike readNetworkCapture which drains)
  4. ensureAttached early-return dependency comment (armCapture handles Runtime.enable, so the generic call is skipped)
  5. Workspace tab cache atomic writes (temp file + rename)

Capture methods stay optional on IPage (with a CaptureCapablePage utility type) to preserve backward compatibility for external implementers.

Follow-ups

This PR is the infrastructure layer. Still ahead from #810:

  • Migrate explore and operate to use readNetworkCapture as primary data source
  • T3-2 (adapter-repair loop) and T3-3 (adapter generation preset) need design discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant