{"title":"Measure Video Startup Time With Percentiles, Not a Mean","excerpt":"A player release can lower mean startup time while viewers on slow links wait almost twice as long. Start the clock at intent, stop it at the first presented frame, record milestones on one clock, run cold starts per device and network segment, and gate on p95 per segment.","canonicalUrl":"https://automationtester.in/blog/automation-tutorials/measure-video-startup-time-percentiles","category":{"name":"Automation Tutorials","slug":"automation-tutorials"},"tags":["video-streaming","playwright","performance-testing","hls","percentiles","chrome-devtools-protocol"],"author":{"name":"Shashank Rawlani","url":"https://shashank.rawlani.com","linkedin":"https://www.linkedin.com/in/shashankrawlani/"},"datePublished":"2026-11-23T13:30:00.000Z","dateModified":"2026-11-23T13:30:00.000Z","coverImage":{"url":"https://ik.imagekit.io/automationtester/automationtester-in/blog/covers/v3/measure-video-startup-time-percentiles.webp","alt":"Dark illustration: thirteen lanes of pills leave a green vertical line. Ten green lanes end together; three orange lanes with one long pill end far right. A dashed grey vertical falls in the gap between green and orange ringed markers."},"contentHtml":"<div class=\"callout callout-info\"><strong>Quick answer:</strong> Start the clock at the viewer's intent (the click handler's <code>performance.now()</code>) and stop it at the first <code>requestVideoFrameCallback</code> that fires while the video is not paused, using that callback's <code>presentationTime</code>. Record each step in between as a milestone on that clock, not as a duration. Run cold starts in a fresh browser context, at least 20 per device and network segment so the nearest-rank p95 is not the slowest run itself. Gate on p95 per segment, weight segments by audience share for the headline, and never gate on the mean: a release can lower it while the slowest tenth of viewers wait almost twice as long.</div>\n\n<p>A player release ships with a startup win on the dashboard. Mean time to first frame falls from 533 ms to 472 ms. The same release takes viewers on a constrained connection from 1.2 seconds to 2.1 seconds before they see a picture, and the mean hides it. Both releases come from the lab below, built so the regression is known in advance and the measurement has to find it.</p>\n\n<p>This is part 3 of an eight-part series on streaming and CTV quality. <a href=\"/blog/automation-tutorials/streaming-quality-model-beyond-video-starts\">Part 1</a> split a viewing session into separate contracts and named startup as one of them; <a href=\"/blog/automation-tutorials/validate-hls-dash-manifests-before-playback\">part 2</a> checked what manifests prove before a player opens them. This part measures the startup contract so that a regression in one segment survives the summary. Bitrate switching and the inside of a DRM licence exchange belong to later parts; here the licence request is one more milestone.</p>\n\n<div class=\"callout callout-warning\"><strong>Versions checked on 2026-11-18:</strong> Playwright 1.62.1 with its bundled Chromium 151.0.7922.34, hls.js 1.7.4, Node.js 26.12.1 and ffmpeg 9.0.1, on macOS arm64. All media is generated by ffmpeg's <code>testsrc2</code> and <code>sine</code> sources and served from <code>http://localhost</code>. The lab opens no external network connection. <code>Network.emulateNetworkConditions</code> is marked deprecated in the tip-of-tree DevTools Protocol as of that date; it still worked in this Chromium build.</div>\n\n<h2 id=\"vst-clock-boundaries\">Where the startup clock starts and stops</h2>\n\n<p><strong>The start is the intent, not the page load.</strong> Take <code>performance.now()</code> inside the handler for the click, remote-control key or autoplay decision that commits to playback. Starting at navigation folds page rendering into startup; starting at <code>hls.loadSource()</code> drops the entitlement or session call that often comes first. Use <code>performance.now()</code>, never <code>Date.now()</code>: the High Resolution Time specification defines a monotonic clock that is not subject to system clock adjustment, while <code>Date.now()</code> can move backwards between two reads.</p>\n\n<p><strong>The end is a presented frame, not an event that implies one.</strong> The HTML standard fires <code>playing</code> when <code>readyState</code> reaches <code>HAVE_FUTURE_DATA</code> while the element is not paused, and notes that the element may still not be potentially playing when it fires. <code>loadeddata</code> means the first frame <em>can</em> be rendered, and it can fire while the video is paused. Neither says a frame reached the screen. <code>video.requestVideoFrameCallback()</code> does: the callback runs when a frame is sent to the compositor, and its metadata carries <code>presentationTime</code>, when the frame was submitted for composition, and <code>expectedDisplayTime</code>, when the browser expects it to be visible. The specification is a WICG Draft Community Group Report, so check support on each target platform and fall back to <code>playing</code> where it is missing, labelled as a fallback in the data.</p>\n\n<pre class=\"language-javascript\"><code class=\"language-javascript\">play.addEventListener(\"click\", async () =&gt; {\n  const t0 = performance.now();              // intent: the click that commits to playback\n  const at = {};\n  const ms = (t) =&gt; Math.round(t - t0);\n  const done = () =&gt; at.playing !== undefined &amp;&amp; at.firstFrame !== undefined &amp;&amp; finish();\n  video.addEventListener(\"playing\", () =&gt; { at.playing = ms(performance.now()); done(); }, { once: true });\n\n  // One-shot: each registration fires for the next presented frame only.\n  const onFrame = (now, meta) =&gt; {\n    if (!video.paused) { at.firstFrame = ms(meta.presentationTime); return done(); }\n    video.requestVideoFrameCallback(onFrame);  // a paused first frame is not startup\n  };\n  video.requestVideoFrameCallback(onFrame);\n  // ... entitlement, loadSource, attachMedia, play()\n});</code></pre>\n\n<p>The callback re-registers until it sees a frame while playing. A player that renders the first frame paused, then waits for a licence before calling <code>play()</code>, would otherwise report a startup it had not finished.</p>\n\n<h2 id=\"vst-milestones\">Record milestones from one clock, not durations</h2>\n\n<p>A total tells you that startup got slower; milestones tell you which step did. Record entitlement, multivariant and media playlists, the licence response for encrypted streams, the first segment received and appended, and the first frame, each as milliseconds after intent on the same <code>performance.now()</code> timeline. Milestones beat durations because players overlap steps. If the app requests entitlement and the manifest at the same time, \"entitlement 250 ms + manifest 47 ms\" adds up to a number that never happened. \"Manifest received at 47 ms, entitlement at 252 ms, first frame at 287 ms\" shows the critical path directly: whichever milestone sits just before the frame is the one to work on.</p>\n\n<p>Resource Timing gives the network milestones without touching the player. Every fetch and XHR becomes a <code>PerformanceResourceTiming</code> entry whose <code>responseEnd</code> is on the same timeline as <code>performance.now()</code>. hls.js 1.7.4 loads segments with XHR, so its entries carry <code>initiatorType</code> <code>\"xmlhttprequest\"</code>. The player's own events add what the network cannot see: hls.js fires <code>FRAG_BUFFERED</code> when a fragment's data has been appended to the <code>SourceBuffer</code>.</p>\n\n<pre class=\"language-javascript\"><code class=\"language-javascript\">hls.once(Hls.Events.FRAG_BUFFERED, (_, d) =&gt; { at.appended = ms(performance.now()); at.segment = d.frag.relurl; });\n\nfunction finish() {\n  const rt = performance.getEntriesByType(\"resource\");\n  const end = (re) =&gt; { const e = rt.find((x) =&gt; re.test(x.name)); return e ? ms(e.responseEnd) : null; };\n  window.__startup = {\n    entitlement: end(/\\/api\\/entitlement$/),\n    manifest: end(/\\/master\\.m3u8$/),\n    mediaPlaylist: end(/\\/r\\d\\.m3u8$/),\n    firstSegment: end(/_000\\.m4s$/),\n    ...at,\n    initiator: rt.find((x) =&gt; /_000\\.m4s$/.test(x.name))?.initiatorType,\n  };\n}</code></pre>\n\n<p>The resource timing buffer is finite: the specification recommends an initial limit of at least 250 entries. Startup will not reach it, but a long session with short segments will, so call <code>performance.setResourceTimingBufferSize()</code> if you extend the harness past startup.</p>\n\n<h2 id=\"vst-cold-start-harness\">A cold-start harness with CDP throttling</h2>\n\n<p>Each sample needs an empty HTTP cache and no warm connections, or the distribution fills with starts no new viewer gets. A new Playwright browser context per sample gives that, and <code>Network.setCacheDisabled</code> makes it explicit. Playwright's <code>newCDPSession()</code> works only on Chromium-based browsers, so this harness is Chromium-only.</p>\n\n<pre class=\"language-javascript\"><code class=\"language-javascript\">const PROFILES = {\n  wifi:        { n: 30, latency: 40,  downloadThroughput: 5_000_000, uploadThroughput: 1_000_000 }, // ~40 Mbit/s\n  constrained: { n: 30, latency: 150, downloadThroughput: 375_000,   uploadThroughput: 125_000 },   // ~3 Mbit/s\n};\n\nasync function coldStart(release, cfg) {\n  const context = await browser.newContext();   // fresh cache and connections: a cold start\n  const page = await context.newPage();\n  const cdp = await context.newCDPSession(page);\n  await cdp.send(\"Network.enable\");\n  await cdp.send(\"Network.setCacheDisabled\", { cacheDisabled: true });\n  const { n: _, ...conditions } = cfg;\n  await cdp.send(\"Network.emulateNetworkConditions\", { offline: false, ...conditions });\n  await page.goto(`${base}?release=${release}`);\n  await page.click(\"#play\");\n  const s = await page.waitForFunction(() =&gt; window.__startup, null, { timeout: 30_000 })\n    .then((h) =&gt; h.jsonValue());\n  await context.close();\n  return s;\n}</code></pre>\n\n<p>Three details of <code>Network.emulateNetworkConditions</code> decide what a profile means. Throughput is in <strong>bytes</strong> per second, so 3 Mbit/s is 375,000, not 3,000,000. <code>latency</code> is defined as the <em>minimum</em> time from request sent to response headers received, which is a floor rather than an added delay: in the lab, an entitlement endpoint that takes 250 ms on the server answered at 252 to 259 ms under both 40 ms and 150 ms of emulated latency. And the protocol's <code>packetLoss</code> parameter applies to WebRTC only, so these profiles have no loss at all. The tip-of-tree protocol marks the command deprecated in favour of <code>emulateNetworkConditionsByRule</code> plus <code>overrideNetworkState</code>, so pin the browser version.</p>\n\n<p>Alternate releases inside the loop (A, B, A, B). Anything that drifts during the run, such as thermal throttling, then lands on both releases instead of looking like a difference between them.</p>\n\n<h2 id=\"vst-lab-releases\">Two releases built to disagree</h2>\n\n<p>The media is a two-rendition HLS ladder in fragmented MP4 with 2-second segments: 640×360 at 600 kbit/s and 1280×720 at 2,400 kbit/s. The <code>noise</code> filter stops the synthetic picture compressing to almost nothing; the first segments came out at 161,490 and 599,335 bytes.</p>\n\n<pre class=\"language-bash\"><code class=\"language-bash\">ffmpeg -hide_banner -loglevel error \\\n  -f lavfi -i \"testsrc2=size=1280x720:rate=30:duration=20\" \\\n  -f lavfi -i \"sine=frequency=440:sample_rate=48000:duration=20\" \\\n  -filter_complex \"[0:v]noise=alls=40:allf=t,split=2[a][b];[a]scale=640:360[v0];[b]copy[v1]\" \\\n  -map \"[v0]\" -map 1:a -map \"[v1]\" -map 1:a \\\n  -c:v libx264 -preset veryfast -profile:v main -g 60 -keyint_min 60 -sc_threshold 0 \\\n  -b:v:0 600k -maxrate:v:0 600k -bufsize:v:0 600k \\\n  -b:v:1 2400k -maxrate:v:1 2400k -bufsize:v:1 2400k \\\n  -c:a aac -b:a 96k -ac 2 \\\n  -f hls -hls_time 2 -hls_playlist_type vod -hls_segment_type fmp4 \\\n  -master_pl_name master.m3u8 -var_stream_map \"v:0,a:0 v:1,a:1\" \\\n  -hls_segment_filename \"media/r%v_%03d.m4s\" -hls_fmp4_init_filename \"init_%v.mp4\" \\\n  media/r%v.m3u8</code></pre>\n\n<p>A local Node server serves the files and an entitlement endpoint that answers after 250 ms. Release A waits for entitlement, then loads the stream, starting on the 360p rendition. Release B requests entitlement and the manifest in parallel, which helps everyone, and pins hls.js <code>startLevel</code> to the 720p rendition for a sharper first picture, which costs about 438 KB more before the first frame: cheap on a fast link, expensive on a slow one.</p>\n\n<h2 id=\"vst-report\">The report: a faster mean and a slower tail</h2>\n\n<p>The run did one discarded warm-up session and 120 measured cold starts, 30 per release per profile, in 4 minutes 31 seconds. The audience mix of 90% Wi-Fi and 10% constrained is an input, standing in for what field data would supply. This is the output as printed:</p>\n\n<pre class=\"language-text\"><code class=\"language-text\">warm-up session (discarded): firstFrame=567 ms\nwrote 120 cold starts to runs.json\ntime to first frame after intent (ms); audience mix {\"wifi\":0.9,\"constrained\":0.1}\nsegment       release    n    mean    p50    p90    p95\nwifi          A         30     458    459    464    464\nwifi          B         30     288    287    292    295\nconstrained   A         30    1209   1212   1220   1223\nconstrained   B         30    2128   2129   2139   2145\nall, weighted A         60     533    460    465   1212\nall, weighted B         60     472    288    298   2129\n\nmilestones, p50 / p95 (ms after intent)\nsegment       release    entitlement      manifest mediaPlaylist  firstSegment      appended    firstFrame       playing\nwifi          A            254 / 256     302 / 306     352 / 356     436 / 439     457 / 462     459 / 464     463 / 483\nwifi          B            252 / 253       47 / 48       92 / 96     260 / 265     279 / 286     287 / 295     296 / 317\nconstrained   A            256 / 259     416 / 422     577 / 585   1176 / 1185   1210 / 1218   1212 / 1223   1217 / 1225\nconstrained   B            256 / 258     160 / 163     320 / 326   2087 / 2095   2117 / 2133   2129 / 2145   2153 / 2166\n\n'playing' dispatched after the first frame was presented: 120/120 sessions, max gap 41 ms\nfirst segment initiatorType: xmlhttprequest</code></pre>\n\n<p>Read the weighted rows first. B's mean is 61 ms better, its p50 is 172 ms better, and even its p90 is better. Its p95 is 917 ms worse. A dashboard showing the mean, or the median, approves this release.</p>\n\n<p>The milestone table says why. On Wi-Fi, B's manifest arrives at 47 ms instead of 302 ms because it no longer waits for entitlement, and the larger first segment costs little. On the constrained profile the manifest also arrives earlier, but the first segment now lands at 2,087 ms instead of 1,176 ms. Entitlement moved off the critical path and the first segment moved onto it. That finding has an owner; a single total does not.</p>\n\n<p>Lab distributions are much tighter than field ones: emulated throughput is exact and the server is local, so the Wi-Fi p50 and p95 sit within 10 ms of each other. Real networks spread each segment far wider.</p>\n\n<h2 id=\"vst-weighting\">Weight segments by audience share, not by run count</h2>\n\n<p>The lab ran 30 starts on each profile because each segment needs enough samples on its own. Pooling those 60 runs as if they were the audience would claim half of all viewers are on a constrained link. The report instead gives each run a weight of its segment's audience share divided by that segment's run count, and computes a weighted nearest-rank percentile: sort by value, accumulate weights, return the first value whose cumulative weight reaches the target. The <a href=\"/blog/automation-tutorials/measure-ci-pipeline-reliability\">CI reliability article</a> covers the unweighted nearest-rank method and why to keep one method throughout.</p>\n\n<pre class=\"language-javascript\"><code class=\"language-javascript\">const pct = (xs, p) =&gt; {\n  const s = [...xs].sort((a, b) =&gt; a.v - b.v);\n  const total = s.reduce((t, x) =&gt; t + x.w, 0);\n  let cum = 0;\n  for (const x of s) if ((cum += x.w) &gt;= (p / 100) * total - 1e-9) return x.v;\n};\n\nconst mine = rows.filter((r) =&gt; r.release === release);\nconst xs = mine.map((r) =&gt; ({\n  v: r.firstFrame,\n  w: SHARE[r.profile] / mine.filter((m) =&gt; m.profile === r.profile).length,\n}));</code></pre>\n\n<p>Weighting also exposes a blind spot of any aggregate percentile: a segment can only put its own times into the aggregate p95 if it holds more than 5% of sessions. Here the constrained share is exactly 10%, so p95 lands inside it while p90 lands on the slowest Wi-Fi start, which is why p90 improved and p95 did not. At a 4% share, the aggregate p95 would have improved too. Gate per segment, and use the aggregate only for the headline.</p>\n\n<h2 id=\"vst-sample-size\">How many cold starts each segment needs</h2>\n\n<p>Nearest-rank p95 is the value at rank ⌈0.95 × n⌉. For any n up to 19 that rank is n itself, so the \"p95\" of 19 samples is the single slowest run, and a release gate built on it fails whenever one sample hiccups. At n = 20 it becomes the second slowest, and at n = 30 still the second slowest. For p99 the same arithmetic requires 100 samples before the figure stops being the maximum.</p>\n\n<p>Multiply that floor by the grid you care about. Three device classes on three network profiles at 30 cold starts each is 270 runs per release, or 540 to compare two releases. At the lab's rate of about 2.2 seconds per run, averaged over a fast and a slow profile, that is about 20 minutes on one machine, before any device that cannot run Playwright at all. Choose the grid from where real viewers are, not from every combination the emulator allows.</p>\n\n<h2 id=\"vst-misleading\">Four ways a startup number lies</h2>\n\n<h3 id=\"vst-warm-cache\">A warm cache counted as a cold start</h3>\n<p>Reusing a page or context between samples lets the second run read the manifest and segments from the HTTP cache. Check it in the data: Resource Timing's <code>transferSize</code> is 0 for a response served from the local cache and exactly 300 for one revalidated with the server, so any first-segment entry with a <code>transferSize</code> of 0 is not a cold start.</p>\n\n<h3 id=\"vst-playing-proxy\">Treating playing as the first frame</h3>\n<p>In all 120 lab sessions the <code>playing</code> handler ran after the first frame's <code>presentationTime</code>, by up to 41 ms. The specification has the browser queue a task to fire <code>playing</code>, so the handler's timestamp includes whatever else the main thread was doing. On a busy CTV main thread the gap can be larger. If you must fall back to <code>playing</code>, store which boundary each sample used and never mix the two in one percentile.</p>\n\n<h3 id=\"vst-opaque-cdn\">Zeros from a cross-origin CDN</h3>\n<p>Without a <code>Timing-Allow-Origin</code> header that passes the timing allow check, segment entries from a CDN on another origin are opaque: <code>requestStart</code> and <code>responseStart</code> read zero, while <code>responseEnd</code> survives. The milestone still works, but a dashboard computing time to first byte as <code>responseStart - startTime</code> reports a negative value for every segment, and the mean includes them. Filter on <code>responseStart &gt; 0</code> and count the rows you dropped.</p>\n\n<h3 id=\"vst-first-launch\">The first session in a fresh browser</h3>\n<p>The warm-up session in the lab took 567 ms to its first frame, against a Wi-Fi p95 of 464 ms for the same release afterwards. The first start in a new browser process pays one-off costs. Launch the browser once, discard one session, and keep a fresh context per sample.</p>\n\n<h2 id=\"vst-limits\">What a laptop lab cannot tell you about a CTV</h2>\n\n<p>The case that motivates most startup work is a low-end CTV on congested Wi-Fi, and this harness reaches only part of it. CDP's <code>Emulation.setCPUThrottlingRate</code> slows the CPU by a factor; it does not model a television's hardware decoder or media pipeline, so decode and append times from a laptop say little about the device. Emulated throughput is also smooth, with no jitter and no loss.</p>\n\n<p>Use the lab to compare two builds under identical, repeatable conditions before release. Take absolute numbers from field telemetry on the devices, with the same boundaries and milestone names, so a lab regression and a field regression read the same way.</p>\n\n<h2 id=\"vst-faq\">Questions about startup measurement</h2>\n\n<h3 id=\"vst-faq-autoplay\">Where does the clock start for autoplay, with no click?</h3>\n<p>At the app's decision to play: the line of code that commits to playback after the page or screen is ready. Record it with <code>performance.now()</code> as you would a click, and label autoplay sessions separately, because they often start before the page has settled.</p>\n\n<h3 id=\"vst-faq-failed-starts\">What happens to sessions that never reach a first frame?</h3>\n<p>Keep them out of the latency percentiles and report them as a separate startup failure rate. A release that turns slow starts into failed ones improves its p95 by losing its worst samples, so read the two numbers together.</p>\n\n<h3 id=\"vst-faq-p99\">Should the gate use p99 instead of p95?</h3>\n<p>Only where each segment collects at least 100 starts per release, which usually means field data. Below that, nearest-rank p99 is the maximum, and a gate on the maximum fails on noise.</p>\n\n<h2 id=\"vst-references\">Specifications and docs behind the startup numbers</h2>\n\n<ul>\n<li><a href=\"https://html.spec.whatwg.org/multipage/media.html\">WHATWG HTML Living Standard, media elements</a>. The conditions for <code>playing</code> and <code>loadeddata</code>, the <code>readyState</code> values, and the note that <code>playing</code> can fire before the element is potentially playing.</li>\n<li><a href=\"https://wicg.github.io/video-rvfc/\">HTMLVideoElement.requestVideoFrameCallback()</a>. The callback firing when a frame is sent to the compositor, one registration per callback, the meaning of <code>presentationTime</code> and <code>expectedDisplayTime</code>, and the document's Draft Community Group Report status.</li>\n<li><a href=\"https://www.w3.org/TR/resource-timing/\">W3C Resource Timing</a>. <code>responseEnd</code> and <code>initiatorType</code> values, the recommended 250-entry buffer and <code>setResourceTimingBufferSize()</code>, attributes zeroed for opaque cross-origin entries, and <code>transferSize</code> of 0 for local cache and 300 for revalidation.</li>\n<li><a href=\"https://www.w3.org/TR/hr-time-3/\">W3C High Resolution Time</a>. A monotonic clock not subject to system clock adjustment, coarsening to 100 microseconds (5 when cross-origin isolated) or coarser, and why <code>Date.now()</code> is unsuitable for durations.</li>\n<li><a href=\"https://github.com/ChromeDevTools/devtools-protocol/blob/65346a3b62255360c5e18477c3541c513da3d9ce/json/browser_protocol.json\">Chrome DevTools Protocol definition, browser_protocol.json</a>. <code>Network.emulateNetworkConditions</code> parameters in bytes per second, latency as a minimum to response headers, <code>packetLoss</code> limited to WebRTC, the deprecation in favour of <code>emulateNetworkConditionsByRule</code>, <code>Network.setCacheDisabled</code> and <code>Emulation.setCPUThrottlingRate</code>.</li>\n<li><a href=\"https://playwright.dev/docs/api/class-browsercontext\">Playwright BrowserContext API</a>. <code>newCDPSession()</code> and its restriction to Chromium-based browsers.</li>\n<li><a href=\"https://github.com/video-dev/hls.js/blob/v1.7.4/docs/API.md\">hls.js 1.7.4 API documentation</a>. <code>startLevel</code>, <code>FRAG_BUFFERED</code> firing after data is appended to the <code>SourceBuffer</code>, and loader stats that hls.js compares against <code>performance.now()</code>.</li>\n</ul>\n\n<h2 id=\"vst-apply\">Apply this now, before the next player release</h2>\n\n<ol>\n<li>Find where your player's startup clock starts today. If it is page load, <code>loadSource()</code> or <code>Date.now()</code>, move it to <code>performance.now()</code> in the intent handler.</li>\n<li>Add a <code>requestVideoFrameCallback</code> end boundary that ignores paused frames, and log which boundary each session used.</li>\n<li>Log milestones, not durations: entitlement, manifest, licence where it applies, first segment received, first append and first frame, all as milliseconds after intent.</li>\n<li>Pick the two or three device and network segments that hold most of your viewers and the one that holds your worst sessions. Run 30 cold starts per segment for the current release and keep the table as a baseline.</li>\n<li>Add a gate on p95 per segment, not on the aggregate mean, and record the audience shares you used to weight the headline number.</li>\n</ol>\n"}