Problem
The current CdpClient.send() sends a command and reads the next WebSocket message as the response. But CDP can send events (no id field) between command responses. If Chrome pushes an event before our response, we'll return the wrong data.
Fix
Implement response correlation:
- Parse the
id field from each received message
- If it matches our sent command ID → return as response
- If it's an event (no
id) → buffer/skip and read next message
- Add timeout for response waiting
Inspiration
vercel-labs/agent-browser handles this via Playwright's built-in CDP session management which correlates responses internally.
Files
src/cdp/client.zig (send method)
Problem
The current
CdpClient.send()sends a command and reads the next WebSocket message as the response. But CDP can send events (noidfield) between command responses. If Chrome pushes an event before our response, we'll return the wrong data.Fix
Implement response correlation:
idfield from each received messageid) → buffer/skip and read next messageInspiration
vercel-labs/agent-browserhandles this via Playwright's built-in CDP session management which correlates responses internally.Files
src/cdp/client.zig(sendmethod)