Skip to content
Source
Sign inSign up
pingdotgg/t3code

Add background preview capture and picture-in-picture support #4397

Mergedjuliusmarmingemerged 32 commits intomain fromrefs/pull/4397/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Summary

  • Add background preview frame capture for concurrent recording and picture-in-picture sessions.
  • Add desktop picture-in-picture windows with live preview frames and lifecycle cleanup.
  • Expose picture-in-picture IPC APIs and update preview state across desktop, web, and mobile clients.
  • Refine sidebar and home-screen behavior alongside preview automation updates.

Testing

  • Added and updated focused tests for preview manager capture sharing, picture-in-picture lifecycle, and desktop window configuration.
  • Not run: local test, lint, or type-check commands were not provided.

Note

High Risk Recording and frame delivery are reimplemented (capturePage vs screencast) with concurrent tabs and complex PiP/tab-lifecycle concurrency; auth cookie naming changes can invalidate dev sessions across parallel agents.

Overview Desktop preview moves recording and picture-in-picture off CDP Page.screencast onto a shared ~12 FPS capturePage loop with separate consumers (recording / picture-in-picture). Native PiP gets new IPC, a dedicated preload, always-on-top windows with backgroundThrottling: false, and tab state pictureInPicture. Tab close/register races are tightened with lifecycle locks and generation checks; global single-recording enforcement and PreviewRecordingAlreadyActiveError are removed.

Web client allows hidden and multi-tab recordings: MediaRecorder starts only after the first valid frame, dimensions come from capture (not UI layout), and stop targeting understands multiple active tab IDs. BrowserSurfaceSlot gains corner radius, layout versioning, and optional content fitting; hosted webviews recover from render-process crashes.

Server preview sessions expose serverEpoch and monotonic revision on list/events; dev session cookies are isolated per port + state-dir hash (wildcard dev included). MCP preview_open defaults to inline preview with open/show normalization; preview_recording_stop tab routing follows the stopped tab’s response.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 00462f44046ecb04c9e833ae59ffacac24e8b310. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add background preview capture and picture-in-picture support

  • Introduces a draggable, resizable floating mini-player (ThreadPreviewMiniPlayer.tsx) that shows a live preview tab within the chat view, scoped per thread.
  • Adds native picture-in-picture support via a new always-on-top BrowserWindow in the desktop preview manager (Manager.ts), with IPC methods to open/close PiP per tab.
  • Replaces DevTools screencast-based recording with a capturePage frame capture loop, supporting multiple concurrent recordings for hidden tabs without requiring visibility.
  • Adds serverEpoch and monotonic revision fields to all preview events and list results so clients can discard stale or out-of-order server messages.
  • Serializes per-tab desktop lifecycle operations and stops any active recording before closing a tab.
  • Risk: DesktopPreviewTabState, PreviewListResult, and all PreviewEvent contracts now require pictureInPicture, serverEpoch, and revision fields — existing decoders will fail without updating.
Macroscope summarized 00462f4.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: a8a26b55-7631-4337-b970-d0f6275eaf15

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `t3code/background-preview-automation`

      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. apps/desktop/src/preview/Manager.ts line 2098Resolvedby juliusmarminge
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR adds substantial new functionality including picture-in-picture support, background preview capture, and a mini-player component. These are new features introducing new user-facing behavior, new native window integrations, and changes to recording architecture and session cookie handling that warrant human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. apps/desktop/src/preview/Manager.ts line 2175OutdatedResolvedby juliusmarminge
    6. apps/desktop/src/preview/Manager.ts line 2095OutdatedResolvedby juliusmarminge
      apps/desktop/src/preview/Manager.ts line 2090OutdatedResolvedby juliusmarminge
    7. apps/desktop/src/preview/Manager.ts line 2458Resolvedby juliusmarminge
    8. apps/desktop/src/preview/Manager.ts line 1427OutdatedResolvedby juliusmarminge
      apps/desktop/src/preview/Manager.ts line 2004OutdatedResolvedby juliusmarminge
      apps/web/src/browser/browserRecording.ts line 207Resolvedby juliusmarminge
    9. apps/web/src/browser/browserRecording.ts line 143OutdatedResolvedby juliusmarminge
    10. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High

      https://github.com/pingdotgg/t3code/blob/65dbe947f0c7498892a531bc5d59ca909bfdf73c/apps/web/src/browser/browserRecording.ts#L535

      When stopBrowserRecording is called during pending startup and its stopScreencast call fails, finalizeBrowserRecording throws the startup-wait timeout, but the catch handler in stopBrowserRecording overwrites recording.lifecycle with discardBrowserRecording as the cleanup continuation and falls through without preserving the slot reservation. clearActiveRecording is then invoked by discardBrowserRecording, which deletes the map entry. A new recording for the same tab can start before the old startup resolves, and the old continuation then calls bridge.recording.stopScreencast(tabId), stopping the replacement recording because the bridge operation is keyed only by tabId. The same slot-reservation protection the startup-timeout path uses for the non-discard branch must also guard the late-cleanup path so a replacement session is not stopped.

      ✅ Resolved in 7b046af10868e60c2ec34cdd8b57710bcb832ad5

    11. apps/web/src/browser/browserRecording.ts line 256Resolvedby juliusmarminge
    12. apps/desktop/src/preview/Manager.ts line 2124Resolvedby juliusmarminge
      apps/desktop/src/preview/Manager.ts line 2188Resolvedby juliusmarminge
      apps/desktop/src/preview/Manager.ts line 3233Resolvedby juliusmarminge
      apps/server/src/preview/Manager.ts line 392Resolvedby juliusmarminge
    13. apps/desktop/src/preview/Manager.ts line 1420OutdatedResolvedby juliusmarminge
    14. apps/desktop/src/preview/Manager.ts line 549Resolvedby juliusmarminge
    15. apps/web/src/browser/browserRecording.ts line 482Resolvedby juliusmarminge
      apps/web/src/browser/BrowserSurfaceSlot.tsx line 72OutdatedResolvedby juliusmarminge
      apps/desktop/src/preview/Manager.ts line 1549Resolvedby juliusmarminge
      apps/web/src/browser/HostedBrowserWebview.tsx line 252OutdatedResolvedby juliusmarminge
    16. apps/web/src/browser/BrowserSurfaceSlot.tsx line 58OutdatedResolvedby juliusmarminge
      apps/web/src/browser/browserRecording.ts line 367Resolvedby juliusmarminge
    17. apps/desktop/src/preview/Manager.ts line 2092Resolvedby juliusmarminge
    18. apps/web/src/browser/HostedBrowserWebview.tsx line 205Resolvedby juliusmarminge
      apps/web/src/browser/HostedBrowserWebview.tsx line 180Resolvedby juliusmarminge
    19. Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

      Fix All in Cursor Bugbot Autofix is [ON](https://www.cursor.com/dashboard/bugbot), but a cloud agent failed to start. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit bfc1e68defca12dfa034ad7e7fcbf0da371bb0ac. Configure [here](https://www.cursor.com/dashboard/bugbot).
    20. juliusmarminge merged thisf4c3943

    21. juliusmarminge closed this

Sign in to join this conversation.