<USER_REQUEST> Implement a dual-path browser control system: a primary WebSocket relay path (CDP-free, bidirectional extension-daemon bridge) and a fallback standalone CDP bridge CLI, with built-in clipboard interception in the extension.
Working directory: /Users/a13973/dev/buddypia/browser-agent-guide Integrity mode: benchmark
Upgrade the extension and daemon communication:
- Make the daemon's WebSocket server (
daemon/src/ws.js) bidirectional, allowing it to push action commands (verbs + args) to connected extension clients. - In the extension Service Worker (
background/service-worker.js), handle action requests from the daemon WebSocket, target the active tab (matching URL or tab metadata), execute actions via content scriptRUN_ACTIONS, and send results back via WebSocket.
Implement a standalone fallback CLI tool that:
- Connects to local Chrome CDP (default port 9333/9222).
- Direct-WebSocket connects to a targeted tab matching given URL/title substrings, executing actions without terminal prompt locks.
Permanently hook navigator.clipboard.writeText in the extension content script to intercept copied text (like token environment variables) during automated actions, logging it to signalLog to guarantee recovery even when blocked by browser User Activation rules.
Develop tests in the test suite to verify:
- Action execution and result recovery via the WebSocket relay path.
- Action execution and result recovery via the fallback CDP bridge CLI.
- Active tabs can be controlled via WebSocket push (primary path) without open CDP ports.
- Active tabs can be controlled via direct CDP WebSocket attach (fallback CLI) when debugging port is open.
- Both paths return action results and successfully recover intercepted copy commands.
- Extension works normally (checked with
npm run check). </USER_REQUEST>