Expand description
Clock — Playwright-style fake timers for a page.
CDP has no native fake-timer primitive, so this is implemented by injecting a
compact fake-timer controller script into the page’s main world and then
driving it with real Runtime.evaluate calls. The controller overrides
Date (so new Date() and Date.now() read from an adjustable base time),
performance.now, and the timer functions (setTimeout, clearTimeout,
setInterval, clearInterval, requestAnimationFrame).
The shape mirrors Playwright’s page.clock():
Clock::set_fixed_timepins time so it never advances;Clock::installengages the fakes (call before the code under test runs);Clock::advance/Clock::tickmove the virtual clock forward, firing any due timers in between.
§Scope
install() injects the controller on the current execution context only.
It is not automatically re-injected on cross-origin navigations; call
install() again after such a navigation. The injected controller lives on
the page’s main world, so timers scheduled in isolated worlds (e.g. content
scripts) are not faked.
Structs§
- Clock
- A fake-timer handle for a
Page. - Clock
Install Options - Options for
Clock::install.