| 287 | } |
| 288 | |
| 289 | export async function driveWarmupTicks( |
| 290 | options: WarmupTickOptions, |
| 291 | state: WarmupTickState, |
| 292 | ): Promise<void> { |
| 293 | const sleep = options.sleep ?? realSleep; |
| 294 | while (true) { |
| 295 | if (options.lockWarmupTicks) { |
| 296 | // Locked mode exits on the iteration count, ignoring `state.running` — |
| 297 | // the caller flips `running=false` after page-readiness but we keep |
| 298 | // ticking until LOCKED_WARMUP_TICKS so the count is host-independent. |
| 299 | if (state.ticks >= LOCKED_WARMUP_TICKS) return; |
| 300 | } else { |
| 301 | // Unlocked mode is wall-clock-bounded. |
| 302 | if (!state.running) return; |
| 303 | } |
| 304 | try { |
| 305 | await options.tick(state.ticks * options.intervalMs, options.intervalMs); |
| 306 | state.ticks += 1; |
| 307 | } catch { |
| 308 | // Page not ready yet; keep spinning. |
| 309 | } |
| 310 | await sleep(options.intervalMs); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | export function resolveCaptureSessionOptions( |
| 315 | options: CaptureOptions, |