feat(browser): unify page capture across daemon and CDP#834
feat(browser): unify page capture across daemon and CDP#834Astro-Han wants to merge 5 commits intojackwener:mainfrom
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
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:
- Preferred-tab drift guard for owned sessions (resolveTab now validates window ID)
- Doctor version check relaxed to major.minor (exact match was too noisy)
- Console non-drain semantics documented (readConsoleCapture is intentionally a rolling buffer, unlike readNetworkCapture which drains)
ensureAttachedearly-return dependency comment (armCapture handles Runtime.enable, so the generic call is skipped)- 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
exploreandoperateto usereadNetworkCaptureas primary data source - T3-2 (adapter-repair loop) and T3-3 (adapter generation preset) need design discussion
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
Checklist
Documentation (if adding/modifying an adapter)
docs/adapters/(if new adapter)docs/adapters/index.mdtable (if new adapter)docs/.vitepress/config.mts(if new adapter)README.md/README.zh-CN.mdwhen command discoverability changedCliErrorsubclasses instead of rawErrorScreenshots / Output