pub struct Clock { /* private fields */ }Expand description
Playwright Clock — provides fake timer control for deterministic tests.
All methods send RPC calls on the owning BrowserContext channel.
Implementations§
Source§impl Clock
impl Clock
Sourcepub fn new(channel: Channel) -> Self
pub fn new(channel: Channel) -> Self
Creates a new Clock backed by the given BrowserContext channel.
Sourcepub async fn install(&self, options: Option<ClockInstallOptions>) -> Result<()>
pub async fn install(&self, options: Option<ClockInstallOptions>) -> Result<()>
Installs fake timers, replacing the browser’s built-in clock APIs
(Date, setTimeout, setInterval, etc.) with controlled equivalents.
§Arguments
options- Optional configuration; settimeto fix the starting epoch timestamp in milliseconds.
§Errors
Returns error if:
- Context has been closed
- Communication with browser process fails
See: https://playwright.dev/docs/api/class-clock#clock-install
Sourcepub async fn fast_forward(&self, ticks: u64) -> Result<()>
pub async fn fast_forward(&self, ticks: u64) -> Result<()>
Advances the fake clock by the given number of milliseconds, firing any timers that fall within that range.
§Arguments
ticks- Number of milliseconds to advance the clock.
§Errors
Returns error if:
- Clock is not installed
- Context has been closed
- Communication with browser process fails
See: https://playwright.dev/docs/api/class-clock#clock-fast-forward
Sourcepub async fn pause_at(&self, time: u64) -> Result<()>
pub async fn pause_at(&self, time: u64) -> Result<()>
Pauses the fake clock at the given epoch timestamp (milliseconds).
No timers fire and time does not advance until Clock::resume is called.
§Arguments
time- Epoch timestamp in milliseconds to pause at.
§Errors
Returns error if:
- Clock is not installed
- Context has been closed
- Communication with browser process fails
See: https://playwright.dev/docs/api/class-clock#clock-pause-at
Sourcepub async fn resume(&self) -> Result<()>
pub async fn resume(&self) -> Result<()>
Resumes the fake clock after it was paused via Clock::pause_at.
§Errors
Returns error if:
- Context has been closed
- Communication with browser process fails
See: https://playwright.dev/docs/api/class-clock#clock-resume
Sourcepub async fn set_fixed_time(&self, time: u64) -> Result<()>
pub async fn set_fixed_time(&self, time: u64) -> Result<()>
Freezes Date.now() and related APIs at the given epoch timestamp
(milliseconds), without affecting timer scheduling.
§Arguments
time- Epoch timestamp in milliseconds.
§Errors
Returns error if:
- Context has been closed
- Communication with browser process fails
See: https://playwright.dev/docs/api/class-clock#clock-set-fixed-time
Sourcepub async fn set_system_time(&self, time: u64) -> Result<()>
pub async fn set_system_time(&self, time: u64) -> Result<()>
Updates the system time reported by Date and related APIs without
freezing the clock or affecting timer scheduling.
§Arguments
time- Epoch timestamp in milliseconds.
§Errors
Returns error if:
- Context has been closed
- Communication with browser process fails
See: https://playwright.dev/docs/api/class-clock#clock-set-system-time