chrome-devtools-mcp icon indicating copy to clipboard operation
chrome-devtools-mcp copied to clipboard

screencast output duration is ~2.6x longer than real elapsed time (timeline stretched / slow-motion playback)

Open nebrass opened this issue 5 months ago • 5 comments

Summary

screencast_start / screencast_stop produces a .webm whose playback duration is ~2.5–2.6× longer than the real elapsed recording time. The captured frames are correct, but they're muxed so the timeline is stretched — the video plays back in slow motion. This makes the output unusable for any timing-sensitive purpose (e.g. trimming clips to a fixed length, or any 1:1 "what happened on screen, when" record) without a manual re-timing/re-encode pass.

Repro

Minimal page that renders its own live elapsed-time clock via requestAnimationFrame, so the ground-truth recording duration is visible inside the video:

<!doctype html><html><head><meta charset="utf-8">
<style>html,body{margin:0;height:100%;background:#0b1020;color:#fff;font-family:monospace;display:flex;align-items:center;justify-content:center}
#t{font-size:160px;font-variant-numeric:tabular-nums}#s{position:fixed;top:24px;left:24px;font-size:28px;color:#7df}</style></head>
<body><div id="s">elapsed (page clock):</div><div id="t">0.00</div>
<script>const t0=performance.now(),el=document.getElementById('t');
function f(){el.textContent=((performance.now()-t0)/1000).toFixed(2);requestAnimationFrame(f)}requestAnimationFrame(f);</script>
</body></html>

Serve it locally, then via the MCP:

  1. new_page → the page URL
  2. screencast_start (filePath: repro.webm)
  3. wait ~10 seconds of wall-clock (nothing else)
  4. screencast_stop

Expected

The output video's playback duration ≈ the real recording window (~9–10 s), and the on-screen page clock advances at 1× (real time) during playback.

Actual

  • On-screen page clock in the final frame: 8.91 (i.e. ~8.9 s of real time actually elapsed and was captured)
  • Resulting video playback duration: 23.12 s — confirmed two ways:
    • last video packet pts_time = 23.120000
    • ffmpeg -i repro.webm -c copy remuxed.mp4 → format.duration = 23.120000
  • Stream: vp9, 1920×1080, r_frame_rate 25/1, 578 frames. 578 / 25fps = 23.12 s, but only ~8.9 s of content exists → the timeline is stretched ~2.6×, so the clock visibly counts 0 → 8.9 over 23 s of playback (slow motion).

I also saw the same effect on a real interaction recording (≈15 s of actual UI activity → an 83 s / 2078-frame webm) and on a simple video-playback recording (~13 s window → 27.2 s output), so it's consistent and reproducible, not a one-off.

Likely cause (hypothesis)

CDP Page.startScreencast emits frames on visual change with their own timestamps; it looks like the assembler writes them at a fixed nominal 25 fps (constant frame rate) rather than honoring each frame's capture timestamp, so a stream that was effectively captured faster than 25 fps gets stretched to fit 25 fps on the timeline. Honoring per-frame timestamps (VFR) or computing the real duration from first/last frame timestamps would fix it.

Environment

  • chrome-devtools-mcp: 1.2.0
  • Node: v24.16.0
  • OS: Linux 6.18 (WSL2)
  • MCP launched with --experimentalScreencast + --experimentalFfmpegPath /usr/bin/ffmpeg
  • Output format: .webm

Impact

For agent-driven video/demo capture (driving a UI and recording it), the clips can't be used directly — every clip needs ffprobe + a re-time pass to restore real-time playback, which defeats the convenience of the tool. Frame-accurate/real-time duration would make these recordings drop-in usable.

nebrass avatar Jun 12 '26 17:06 nebrass

Update: minimal repro + the bug is isolated to the MCP wrapper (Puppeteer and Playwright record the same page at ~1×).

Public reproduction repo: https://github.com/nebrass/sample-screencast-code

I built a page that renders its own requestAnimationFrame clock (so the ground-truth elapsed time is visible inside the recording) and recorded it three ways on the same Chrome:

Recorder Real elapsed (page clock) Video playback Stretch
Puppeteer page.screencast() (what this MCP wraps) 12.49 s 13.88 s · 347 frames 1.11× ✅
Playwright recordVideo() (different code path) 12.02 s 13.40 s · 335 frames 1.11× ✅
chrome-devtools-mcp screencast 15.38 s 32.40 s · 810 frames 2.11× ❌

Two independent, unrelated recorders are correct on the same page; only chrome-devtools-mcp's screencast stretches ~2×. So this isn't an upstream Puppeteer/CDP problem — it's in this server's screencast frame-handling/muxing.

Mechanism (hypothesis): for ~15 s of real time the MCP muxed 810 frames (~53 fps of captured frames) into a 25 fps container → 810 / 25 = 32.4 s. Puppeteer/Playwright captured ~28 fps and muxed at 25 fps → ~1×. The MCP appears to keep ~2× too many screencast frames and write them at a fixed nominal frame rate instead of honoring each frame's capture timestamp (constant-frame-rate-at-the-wrong-rate rather than timestamp-aware / VFR muxing).

Repro (one command each):

npm install
CHROME=/path/to/chrome RECORD_SECONDS=12 npm run repro              # Puppeteer  -> ~1.0x
CHROME=/path/to/chrome RECORD_SECONDS=12 npm run repro:playwright   # Playwright -> ~1.0x

The MCP path (the bug) + verify.mjs are documented in the repo README, and all three recordings are committed under evidence/.

Workaround until fixed — the stretch is ≈ a constant factor and the real recording window is known, so it can be re-timed:

FACTOR=$(python3 -c "print(REAL_ELAPSED / VIDEO_DURATION)")
ffmpeg -i mcp.webm -vf "setpts=${FACTOR}*PTS,fps=30" -r 30 -pix_fmt yuv420p out.mp4

Env: chrome-devtools-mcp 1.2.0 · Node 24.16 · Chrome-for-Testing 149 · ffmpeg 4.4 · WSL2.

nebrass avatar Jun 12 '26 18:06 nebrass

Effacer tout les code

chloedidia2000-hub avatar Jun 12 '26 22:06 chloedidia2000-hub

Root-caused upstream — it's a bug in Puppeteer's ScreenRecorder, not in chrome-devtools-mcp's own code.

screencast_start is a thin wrapper over page.screencast(), and the timeline stretch happens entirely inside Puppeteer's ffmpeg muxing. (My earlier "Puppeteer records at ~1×" was with puppeteer-core 23; the bug is in 25.x's ScreenRecorder, which is what this server bundles.) Two bugs combine:

  1. -framerate is placed after -i (an input option in output position), so ffmpeg ignores it and the image2pipe demuxer falls back to 25fps, while frames are duplicated for a 30fps timeline → a constant 30/25 = 1.2× stretch.
  2. Per-interval rounding in the frame duplication (round(fps · Δt)) makes the written frame count track the capture rate instead of fps. So stretch ≈ capture_fps / 25 — which is why the factor varies (≈1.0–1.2× on low-capture machines, 2.1–2.6× at the ~53–65fps this server captures over WSL).

Filed and fixed upstream (with a unit test + cross-environment measurements):

  • Issue: puppeteer/puppeteer#15111
  • PR: puppeteer/puppeteer#15112

No chrome-devtools-mcp code change is needed — this resolves automatically once the puppeteer-core dependency is bumped past the merge. Might be worth keeping this open as a tracking issue until that bump lands.

nebrass avatar Jun 13 '26 15:06 nebrass

The puppeteer fix has been merged, let's test this again when the puppeteer bump is merged as well

nroscino avatar Jun 18 '26 12:06 nroscino

The bump in Puppeteer version happened - https://github.com/ChromeDevTools/chrome-devtools-mcp/pull/2246 It will be in the next release which you can track here - https://github.com/ChromeDevTools/chrome-devtools-mcp/pull/2228

Lightning00Blade avatar Jun 22 '26 17:06 Lightning00Blade