Skip to content

fix: propagate recording session to screencast stream#1045

Open
shtefcs wants to merge 1 commit intovercel-labs:mainfrom
shtefcs:fix/recording-screencast-session
Open

fix: propagate recording session to screencast stream#1045
shtefcs wants to merge 1 commit intovercel-labs:mainfrom
shtefcs:fix/recording-screencast-session

Conversation

@shtefcs
Copy link
Copy Markdown
Contributor

@shtefcs shtefcs commented Mar 27, 2026

Problem

After record start, the live preview (screencast) stays on the old pre-recording context while CLI commands execute on the new recording context. This causes:

  1. Live preview stuck — shows the old page, not the recording context
  2. Extensions appear broken — content scripts inject into the recording context but the screencast shows the old context where nothing happens

Root Cause

handle_recording_start creates a new BrowserContext via Target.createBrowserContext, adds a new page, and switches active_page_index to it. All subsequent CLI commands (snapshot, eval, click) use mgr.active_session_id() which returns the new recording session.

However, the StreamServer's cdp_session_id (used for Page.startScreencast) is never updated. update_stream_client() is called by 13+ other commands that switch contexts (open, close, connect, tab switch, etc.) but was missing from both handle_recording_start and handle_recording_stop.

Fix

Add state.update_stream_client().await in both handle_recording_start (after set_recording) and handle_recording_stop (after set_recording). This propagates the active session to the screencast stream, matching the pattern used everywhere else.

Same class of bug as #1019

PR #1019 fixed downloads not working in the recording context by re-applying Browser.setDownloadBehavior to the new context. This PR fixes the screencast stream not following the recording context by calling update_stream_client().

Testing

Verified that without this fix:

  • record start → live preview stays on old context
  • CLI commands execute on new recording context
  • Extensions (loaded via --load-extension) appear to not work because the screencast shows the wrong context

With this fix:

  • Live preview follows the recording context
  • Extensions visible in the screencast
  • record stop syncs the screencast back to the current page

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 27, 2026

@shtefcs is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@shtefcs shtefcs force-pushed the fix/recording-screencast-session branch from da5070c to 08c8227 Compare March 27, 2026 07:33
@@ -0,0 +1,9 @@
The recording function currently:
Copy link
Copy Markdown
Contributor

@vercel vercel bot Mar 27, 2026

Choose a reason for hiding this comment

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

A development scratch note file (cli/src/native/actions.rs.patch) was accidentally committed to the repository.

Fix on Vercel

`record start` previously created a new BrowserContext via
`Target.createBrowserContext`. This creates an Off-The-Record (incognito)
profile where extensions loaded via `--load-extension` are NOT available
— extensions require explicit user opt-in for incognito, and CDP-created
contexts have no such opt-ins.

This breaks CAPTCHA solvers (NopeCHA), ad blockers, and any other
extension that relies on content script injection during recording.

Confirmed by:
- Chromium source: `DevToolsBrowserContextManager::CreateBrowserContext`
  calls `GetOffTheRecordProfile()` which creates an OTR profile
- Puppeteer issue #3442: extensions blocked in createIncognitoBrowserContext
- Playwright issue #5328: extensions unavailable in browser.newContext()

Fix: replace `Target.createBrowserContext` + `Target.createTarget` with
`browserContextId` with just `Target.createTarget` (no browserContextId).
This creates a new tab in the DEFAULT browser context where extensions
work normally.

The recording still gets its own CDP session via `Target.attachToTarget`,
so there are no command conflicts — CDP supports multiple concurrent
in-flight commands via ID-based multiplexing.

Also removed `Browser.setDownloadBehavior` re-application since the new
tab shares the default context where downloads are already configured.
@shtefcs shtefcs force-pushed the fix/recording-screencast-session branch from 08c8227 to 094d7c7 Compare March 27, 2026 09:22
@ctate
Copy link
Copy Markdown
Collaborator

ctate commented Mar 29, 2026

Thanks for the fix @shtefcs! One thing: please remove cli/src/native/actions.rs.patch — looks like a scratch file that shouldn't be committed.

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.

2 participants