Control timers and fake the system clock in Playwright tests using page.clock

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Call await page.clock.install({ time: new Date('2024-01-01T00:00:00') }) before navigation to freeze Date.now() and all timer APIs at a known point in time; this must be called before any other clock API calls
  2. Use await page.clock.fastForward('30s') or page.clock.fastForward(30000) to jump the clock forward by a duration, firing any pending timers and animation frames that fall within the skipped window
  3. For fine-grained control, use page.clock.runFor(ms) to advance time step-by-step, or page.clock.tick(ms) to advance without running animation frames
  4. To only freeze Date.now() while letting real timers fire at wall-clock speed, call page.clock.setFixedTime(date) instead of install()
  5. The clock is installed for the entire browser context, so all pages and iframes share the same fake clock; coordinate time advancement carefully if multiple pages are open

Known gotchas

Related routes

Record video mid-test on demand using Playwright page.screencast.start() and stop() (v1.59+)
playwright.dev · 6 steps · unrated
Intercept and mock WebSocket messages in Playwright using page.routeWebSocket()
playwright.dev · 5 steps · unrated
assert on websocket frames in a playwright test using page.waitforevent('websocket')
playwright.dev · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans