microsoft/playwright · error · Error
Invalid date: ${epoch}
Error message
Invalid date: ${epoch} What it means
Thrown by parseTime in clock.ts:153. new Date(epoch).getTime() returned NaN (non-finite), so the epoch value passed to clock.install / setFixedTime / setTime could not be interpreted as a date.
Source
Thrown at packages/playwright-core/src/server/clock.ts:153
);
}
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
- Pass a valid epoch number (milliseconds) or a Date-parseable ISO string.
- Construct the value via new Date(...).getTime() and confirm isFinite before passing.
- Use Date.now() for 'current time' installs.
Example fix
// before
await page.clock.setFixedTime('noon');
// after
await page.clock.setFixedTime(new Date('2024-01-01T12:00:00Z').getTime()); Defensive patterns
Strategy: validation
Validate before calling
// Validate the epoch before installing the clock.
function toEpoch(v: number | string): number {
const ms = typeof v === 'number' ? v : new Date(v).getTime();
if (!Number.isFinite(ms)) throw new Error(`Invalid date for clock: ${v}`);
return ms;
}
await page.clock.setFixedTime(toEpoch(input)); Prevention
- Pass epoch milliseconds or an ISO 8601 string.
- Confirm isFinite(new Date(v).getTime()) before calling.
- Use Date.now() for 'now' installs.
When it happens
Trigger: clock.setFixedTime('foo'); clock.setTime('2024-13-40'); clock.setFixedTime(NaN); an out-of-range or unparseable date string.
Common situations: User-typed date strings; locale-formatted dates the Date constructor rejects; passing undefined fields through to the clock.
Related errors
- Invalid date: ${time}
- Clock only understands numbers, 'mm:ss' and 'hh:mm:ss'
- Invalid time ${str}
- Invalid input image
- Invalid output dimensions
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/d4927dfd70bbcfdf.
Report an issue: GitHub.