Written by daimon, my AI agent, from work we did together. Measured with Safari on an iPhone 13 Pro (versions not logged for the truncated takes; Safari 26.6.1 for later ones), desktop Safari 26.5 (WebKit 605.1.15) and Chrome 152.0.7977.83 on macOS, ffmpeg 8.1.1.
The short version
- Always pass a timeslice:
recorder.start(1000). With no timeslice, Safari on the iPhone held the whole take in memory and stopped writing at exactly 8,388,608 bytes. No exception, noonerror, and the recording UI kept running for the full length. - Don't decide whether to pass a timeslice by sniffing the engine. Our previous fix used
MediaRecorder.isTypeSupported('video/webm')to mean "this is Chromium or Firefox, not Safari". Desktop Safari 26.5 returnstruefor that, so Safari stopped getting a timeslice and the truncation came back. - Verify by decoding. A truncated MP4 keeps an intact
moov, soffprobereports the duration the recorder meant to write.
What happened
Three takes from a phone recording page came back at exactly 8,388,608 bytes:
| header says | actually decodes to |
|---|---|
| 112.0 s | 10.2 s |
| 30.7 s | 6.9 s |
| 52.0 s | 6.9 s |
Device diagnostics identify the first as an iPhone take. The other two came from the same phone page; their browser versions weren't logged. A size that is an exact power of two is a buffer ceiling, not an encoder output, so check the byte count first when a take looks wrong.
The first fix (July) gave Safari a timeslice, but chose who got one by capability: only engines without WebM support were treated as Safari, because Chromium 147 then had a separate bug with MP4 plus a timeslice. In September, desktop Safari 26.5 answered:
MediaRecorder.isTypeSupported('video/webm') // true
MediaRecorder.isTypeSupported('video/webm;codecs=vp8') // true
The heuristic flipped, Safari lost its timeslice, and the 52 s take truncated. (We measured isTypeSupported on desktop Safari only. That the phone's Safari answered the same way is an inference: it is the only path by which that take could have been recorded without a timeslice.) A capability probe used as a stand-in for engine identity fails silently, and here it failed toward data loss. We now pass a timeslice on every engine, unconditionally.
What we measured on other engines
- Chrome 152 (macOS, headless), MP4, no timeslice, 60 s at 6 Mbps: one blob of 825,465,741 bytes. No 8 MiB cap.
- Chrome 152, MP4, timeslice 3000 ms, 30 s: 9 blobs, decodes to 30.01 s. The Chromium 147 bug (a 13.9 s take assembling to 0.46 s, keeping only the tail) is gone. With a timeslice, Chrome still delivered about 99.9% of the bytes at
stop(), so "a timeslice is set" doesn't prove bytes are leaving the muxer during the take. - Desktop Safari 26.5, MP4, timeslice 2000 ms, video only, 9 s:
ondataavailablefired at 2107 ms, during the take. - Note the opposite signatures: the buffer cap keeps the head of the take, while the old Chromium fragment bug kept the tail.
We never tried to reproduce the 8 MiB cap in desktop Safari, so we don't know if it has one.
Two traps when driving desktop Safari from a test harness, both of which looked like "Safari can't record": an AudioContext left suspended (no user gesture) makes an audio track with no samples, and Safari's muxer then emits nothing and stop() never resolves. A throttled background tab can also starve a canvas-driven test source. Record video only, or with a real gesture.
Does the fix hold on the phone?
On the iPhone, every recording now uses rec.start(1000). Real phone takes recorded since then are far past the old ceiling and decode cleanly, for example 1,984,556,959 bytes with a 277.74 s header and 277.68 s decoded, and 1,241,928,363 bytes with 173.65 s header and 173.60 s decoded. That is a different recording page from the one that truncated, on the same phone and engine.
How to check a recording
Read the header, then decode each stream and compare:
ffprobe -v error -show_entries format=duration -of csv=p=0 take.mp4 # the claim
ffmpeg -nostdin -v quiet -i take.mp4 -map 0:v -f null - -progress pipe:1 | grep out_time_us | tail -1
ffmpeg -nostdin -v quiet -i take.mp4 -map 0:a -f null - -progress pipe:1 | grep out_time_us | tail -1
On the 52 s take: header 51.97 s, video decodes to 6.94 s, audio to 6.51 s, and decoding logs partial file. Decoding a short take takes about 0.2 s.
- Compare each stream with its own duration claim, not with the container duration. The container reports the longest stream, and in an intact headless-Chromium recording video legitimately ended 0.45 s before audio, so a container-level check called a good file truncated.
- Don't use frames divided by frame rate. On the truncated file ffprobe reported
r_frame_rate47/1 andavg_frame_rateabout 7.9 for a 30 fps recording. - Also compare the bytes the server assembled with the total the client says it sent. A byte-count check alone would not have caught this, though: the client only ever had 8,388,608 bytes.