Expand description
Clock mocking for controlling time in browser pages.
The Clock API allows you to control time-related functions in JavaScript,
including Date, setTimeout, setInterval, requestAnimationFrame, and performance.now().
§Example
ⓘ
use std::time::Duration;
// Install clock mocking
page.clock().install().await?;
// Set a fixed time
page.clock().set_fixed_time("2024-01-01T00:00:00Z").await?;
// Check that Date.now() returns the fixed time
use viewpoint_js::js;
let time: f64 = page.evaluate(js!{ Date.now() }).await?;
// Advance time by 5 seconds, firing any scheduled timers
page.clock().run_for(Duration::from_secs(5)).await?;Structs§
- Clock
- Clock controller for mocking time in a browser page.
Enums§
- Time
Value - A time value that can be either a timestamp or an ISO string.