Clock

Playwright\Clock\ClockInterface

Controls time in a browser context. Use it to install fake timers or to set and advance time deterministically. Browser contexts expose the clock associated with their own page state.

Methods

fastForward()

void

Jumps the clock forward. Runs timers that become due, but fires each callback at most once. Accepts milliseconds or a duration string such as '01:00:00'.

function fastForward(int|string $ticks): void

install()

void

Installs the fake clock. Replaces time-related functions in this browser context with controlled implementations. The optional time becomes the initial value used by the fake clock.

function install(array $options = []): void

pauseAt()

void

Advances time and pauses it. Runs timers that become due, but fires each callback at most once. The time can be a timestamp, a duration string, or a DateTimeInterface.

function pauseAt(int|string|\DateTimeInterface $time): void

resume()

void

Resumes clock progression. Time starts flowing from its current value after a previous pause. Timers then run according to their normal schedule.

function resume(): void

runFor()

void

Runs the clock for a duration. Executes time-related callbacks that become due during the elapsed period. Accepts milliseconds or a duration string such as '01:00:00'.

function runFor(int|string $ticks): void

setFixedTime()

void

Fixes the reported date. Makes Date.now() and new Date() return the supplied fake time. Timers continue running while date reads remain fixed.

function setFixedTime(int|string|\DateTimeInterface $time): void

setSystemTime()

void

Sets the system time. Changes the fake clock's current time without running due timers. Use it when time must move without executing scheduled callbacks.

function setSystemTime(int|string|\DateTimeInterface $time): void