Capture the moment#
From the reporter, record:
- The time of the bug as an instant, in UTC:
2026-03-29T00:59:00Z, not "around 2 am" - The browser's time zone:
Intl.DateTimeFormat().resolvedOptions().timeZone - How long the page had been open, and whether the tab was in the background
The time zone matters as much as the instant. The same instant is a different calendar date and wall-clock time in different zones, and daylight saving transitions happen on different dates. Replay the time zone and locale covers capturing it.
Set the clock in Playwright#
Playwright's clock API replaces Date, timers and related functions in the page:
const context = await browser.newContext({ timezoneId: 'Europe/Berlin' });
const page = await context.newPage();
await page.clock.install({ time: new Date('2026-03-29T00:59:00Z') });
await page.goto('https://staging.example.test/schedule');
await page.clock.fastForward('01:00:00'); // one hour later, firing due timers
We ran that in Chromium on a test page. Before the jump, new Date().toString() showed 01:59:00 GMT+0100 (Central European Standard Time). One hour later it showed 03:59:00 GMT+0200 (Central European Summer Time): the wall clock moved two hours, because Berlin's clocks went forward at 01:00 UTC that night. A one-hour timer set before the jump had fired. Code that adds 60 minutes to a displayed time, or assumes every day has 24 hours, fails here.
page.clock.setFixedTime() stops time at one instant, for bugs that depend on the date but not on timers. Setting 2026-12-31T23:59:59Z with the context in Europe/Berlin made new Date().getFullYear() return 2027, since it was already the new year in Berlin.
Choose the method for the bug#
| The bug depends on | Use |
|---|---|
| The calendar date or time at page load | clock.setFixedTime() or clock.install({ time }) |
| A timer or a timeout, such as session expiry after 30 minutes | clock.install() then clock.fastForward() or clock.runFor() |
| An animation or polling loop | clock.install() then clock.runFor() in small steps |
| The server's clock, such as a token's expiry checked by the API | Not the browser clock: the server must be in that state too |
The last row is the limit. Faking the browser's clock does not change the server's, so a bug in how the page and server disagree about time needs both sides set, or a response replayed with the times the reporter's server sent. Replay recorded responses covers the second.
Moments worth testing#
- The last day of a month, and the 29th to 31st when code adds one month
- Daylight saving changes in both directions in the users' zones
- Midnight in the user's zone versus midnight UTC
- The year boundary, and week numbering around it
- Leap days
- Session or token expiry, and the minute after it
Worked example: a renewal date one month off#
This example is fictional. On January 31, a tester reports that the subscription page shows the next renewal as March 3. The developer looks the next day and sees March 1.
The developer fixes the clock with setFixedTime(new Date('2027-01-31T10:00:00Z')) and sees March 3 on every run. The page computed next month with date.setMonth(date.getMonth() + 1), which turns January 31 into "February 31", rolled over to March 3. The test with the fixed date became a regression test, and the fix clamped the day to the end of the target month.
Questions#
Does faking the clock affect performance.now()?
Playwright's clock also controls performance.now(). A page that measures elapsed time sees the faked time.
Can I fake the clock without Playwright?
Test frameworks such as Jest and Vitest have fake timers for unit tests. In DevTools, there is no clock override, but you can set the OS clock in a virtual machine.
The bug depends on the tab being in the background for an hour. Does fast-forwarding cover that?
It covers the timers. Background tabs also have their timers throttled by the browser, which the clock API does not simulate. If the bug depends on throttling, reproduce it in a real background tab and say so.
Return to reproducing what someone else saw for the other layers a replay needs.