feat: add browser session recording via CDP screencast (start/stop API)#20
Conversation
There was a problem hiding this comment.
4 issues found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="examples/record.py">
<violation number="1" location="examples/record.py:21">
P2: Module executes `asyncio.run(main())` at import time; missing `__main__` guard causes import-time side effects.</violation>
</file>
<file name="cdp_use/recorder.py">
<violation number="1" location="cdp_use/recorder.py:50">
P1: Queue task completion is not exception-safe; an error in frame processing can prevent `task_done()` and cause `stop()` to hang on `queue.join()`.</violation>
</file>
<file name="cdp_use/client.py">
<violation number="1" location="cdp_use/client.py:412">
P2: `start_recording()` lacks an active-recording guard, allowing multiple recorder starts on one client and conflicting screencast/event-handler state.</violation>
<violation number="2" location="cdp_use/client.py:412">
P2: `start_recording()` launches a background `Recorder` task that is not tracked or stopped by `CDPClient.stop()`, causing lifecycle leaks when callers forget explicit `recorder.stop()`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
|
Hey @Adarsh-Raj-Jaiswal — following up on the feedback we left on the three threads. We went ahead and implemented the fixes on a branch on our fork if you'd like to cherry-pick them. What's in the commits:
To cherry-pick: git remote add crayment https://github.com/crayment/cdp-use.git
git fetch crayment
git cherry-pick 1b19503 b00e1b3Happy to iterate if anything looks off. |
- Wrap worker frame processing in try/finally so task_done() is always called even if base64 decode, file write, or screencastFrameAck raises, preventing queue.join() from hanging indefinitely in stop() - Add _recorder field to CDPClient to track active recording; guard start_recording() against double-start (EventRegistry uses a plain dict so a second call would silently overwrite the first on_frame handler, leaking the first recorder's worker task) - Stop active recorder in CDPClient.stop() before closing the WebSocket, so screencastFrameAck calls in the recorder can still complete cleanly; without this, recorder.stop() called after CDPClient.stop() raises RuntimeError from send_raw() on a closed connection
…arsh-Raj-Jaiswal/cdp-use into feat/cdp-screencast-recording
|
Thanks a lot for the detailed review and for putting together the fixes + tests — really appreciate it. I’ve cherry-picked the commits into my branch and pushed the updates. Let me know if anything else needs refinement. |
|
Hi @crayment , Just checking if everything looks good now happy to make any further changes if needed. |
|
Looks great @Adarsh-Raj-Jaiswal — the commits landed cleanly and the code matches exactly. From our side this is good to go! 🎉 |
|
Hey @reformedot — wanted to give this a gentle nudge! PR #20 from @Adarsh-Raj-Jaiswal adds the session recording feature via CDP screencast that was requested in issue #19. We reviewed it as third-party contributors, addressed the bot feedback, and added tests — everything looks good from our side. Would love to see this land! 🙏 |
|
Thanks again @crayment for the help getting this merged 🙏 Once this lands, I’m planning to proceed with the browser-use CLI integration on top of the current frame-based recording (start/stop commands), and then iterate toward video encoding support from there. Let me know if that direction aligns with your expectations. |
#19
Summary
Adds initial support for recording browser sessions using Chrome DevTools Protocol (CDP) screencast.
This implements a minimal start/stop recording API that captures frames via
Page.startScreencastand saves them as JPEG images.Features
CDPClient.start_recording(output_dir)APIPage.startScreencast/Page.screencastFrameExample