microsoft/playwright · error · Error

Invalid time ${str}

Error message

Invalid time ${str}

What it means

Thrown by parseLength in clock.ts:141 after the format check passed. Each colon-separated component is parsed with parseInt and rejected when >= 60, so a field that looks like a valid mm/ss but is out of range is rejected as an invalid time.

Source

Thrown at packages/playwright-core/src/server/clock.ts:141

    return 0;
  const str = value;

  const strings = str.split(':');
  const l = strings.length;
  let i = l;
  let ms = 0;
  let parsed;

  if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) {
    throw new Error(
        `Clock only understands numbers, 'mm:ss' and 'hh:mm:ss'`,
    );
  }

  while (i--) {
    parsed = parseInt(strings[i], 10);
    if (parsed >= 60)
      throw new Error(`Invalid time ${str}`);
    ms += parsed * Math.pow(60, l - i - 1);
  }

  return ms * 1000;
}

function parseTime(epoch: string | number | undefined): number {
  if (!epoch)
    return 0;
  const parsed = new Date(epoch);
  if (!isFinite(parsed.getTime()))
    throw new Error(`Invalid date: ${epoch}`);
  return typeof epoch === 'number' ? epoch : parsed.getTime();
}

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Keep each minute/second component below 60.
  2. Prefer passing total milliseconds as a number to avoid parsing ambiguity.
  3. Validate the components programmatically before calling the clock API.

Example fix

// before
await page.clock.advance('01:75');
// after
await page.clock.advance(135 * 1000);
Defensive patterns

Strategy: validation

Validate before calling

// Each mm/ss component must be < 60.
function assertClockLength(v: string) {
  const parts = v.split(':');
  if (parts.some(p => Number(p) >= 60))
    throw new Error(`Clock component out of range: ${v}`);
}
if (typeof input === 'string') assertClockLength(input);
await page.clock.advance(input);

Prevention

When it happens

Trigger: clock.advance('99:99'); clock.advance('12:75'); any 'mm:ss' / 'hh:mm:ss' where minutes or seconds are 60 or more.

Common situations: Off-by-one durations written as 'minutes:seconds' with seconds=60; copy-pasted countdown strings;mis-encoded times.

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/da38f37489c3b5db. Report an issue: GitHub.