PHPackages                             paksuco/dusk-time-travel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. paksuco/dusk-time-travel

ActiveLibrary[Testing &amp; Quality](/categories/testing)

paksuco/dusk-time-travel
========================

A dusk browser extension package for time traveling

1.2.0(1mo ago)35064MITPHPCI passing

Since Dec 20Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/paksuco/dusk-time-travel)[ Packagist](https://packagist.org/packages/paksuco/dusk-time-travel)[ Docs](https://github.com/paksuco/dusk-time-travel)[ GitHub Sponsors](https://github.com/sponsors/tpaksu)[ RSS](/packages/paksuco-dusk-time-travel/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (7)Dependencies (18)Versions (9)Used By (0)

[![](.github/dusk-time-travel.png)](.github/dusk-time-travel.png)

A dusk browser extension package for time traveling
---------------------------------------------------

[](#a-dusk-browser-extension-package-for-time-traveling)

[![Latest Version on Packagist](https://camo.githubusercontent.com/dbaa9c06b9faec07feaebc5672b673f750a45c7f0ae151de9dcacc31ea960aa2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70616b7375636f2f6475736b2d74696d652d74726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/paksuco/dusk-time-travel)[![Total Downloads](https://camo.githubusercontent.com/552848bd3b721416a8261a9acff4f721372bcd0d542f690df61eb3909c651692/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70616b7375636f2f6475736b2d74696d652d74726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/paksuco/dusk-time-travel)

This package feeds the hunger for Dusk test cases having time modified requests. All PR's are welcome.

Supported versions:

- Laravel Dusk 6 → 8
- Laravel Framework 7 → 13
- PHP 7.4 → 8.5

Beyond this the package may continue to work, but is untested. Please raise an issue if you run into problems, so it can be fixed.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require --dev paksuco/dusk-time-travel ^1.0.0
```

There is a crucial step to do after installing the package to let the browser have time travel methods, you need to extend your browser class from `Paksuco/DuskTimeTravel/Browser` class instead of the stock `Laravel/Dusk/Browser`. This class acts like a middle man between your test cases and the Laravel Dusk browser.

To do this, add this code to your `DuskTestCase.php` file:

```
    use \Paksuco\DuskTimeTravel\Browser as TimeTravelBrowser;

    class DuskTestCase extends BaseTestCase {

        protected function newBrowser($driver)
        {
            return new TimeTravelBrowser($driver);
        }

    }
```

Usage
-----

[](#usage)

Since you've changed your browser class, you've gained access to two new Dusk browser methods:

- `travelTo($time)` - travel through time, using a `Illuminate/Support/Carbon` instance as the time input.
- `travelBack()` - return to the current time.

The traveled time is delivered via a cookie, which has two consequences:

1. The browser must already be on a page of your app when you call `travelTo()` or `travelBack()`, so `visit()` something first or you'll get an `invalid cookie domain` error.
2. The time change (both server-side and browser-side JavaScript) only applies from the **next** page load; the current page is unaffected.

For example:

```
$this->browse(function ($browser) {

    $browser->visit('/')
        // (1) Visit home, (2) Travel to tomorrow
        ->visit("home")
        ->travelTo(Carbon::tomorrow())
        // The home page will show today's date (we have NOT reloaded the page)
        ->assertSee(Carbon::today()->format('Y-m-d'));
});
```

```
$this->browse(function ($browser) {

    $browser->visit('/')
        // (1) Travel to tomorrow, (2) Visit home
        ->travelTo(Carbon::tomorrow())
        ->visit("home")
        // The home page will show tomorrow's date (we have reloaded the page)
        ->assertSee(Carbon::tomorrow()-format('Y-m-d'));
});
```

Both of them will use tomorrows date as the next request (AJAX or Redirect, doesn't matter).

Other usage examples:

```
$this->browse(function ($browser) {

    // Do something in yesterdays date and expect to see that it occurred on that date
    $browser->visit('/')
        ->travelTo(Carbon::yesterday())->visit($itemDetailsPage)
        ->doStuffInYesterdaysDate()
        ->travelBack()->visit($itemDetailsPage)
        ->assertSee(Carbon::yesterday());
});
```

```
$this->browse(function ($browser) {

    // Log in sometime in the distant future (long after session expiry)
    $user = User::factory()->create(['name' => 'Bob']);
    $browser->visit('/')
        ->travelTo(Carbon::parse('2040-01-01 12:00:00')
        ->actingAs($user)->visit('/dashboard')
        ->assertSee("Welcome Bob, it is the year 2040!");
});
```

After you've recreated the instance, or manually reset with `travelBack()`, the server will revert to the normal date.

Browser-side (JavaScript) time travel
-------------------------------------

[](#browser-side-javascript-time-travel)

In addition to faking server-side time, `travelTo()` also fakes time for JavaScript running in the browser. `new Date()`, `Date.now()` and plain `Date()` calls in page scripts will return the traveled time. This works by registering a small `Date` shim through the Chrome DevTools Protocol (`Page.addScriptToEvaluateOnNewDocument`), so it:

- takes effect on the **next page load** — consistent with when the server-side time changes,
- survives navigations, and runs **before** any page script on every new document,
- is removed again by `travelBack()`, also taking effect on the next page load.

Note that each page load starts exactly at the traveled instant and then ticks forward naturally (time is shifted, not frozen — freezing would break polling and animation code).

Since the server re-freezes to the traveled time at the start of each request, browser and server agree at page-load time and the browser then drifts forward by the age of the page.

To fake only server-side time, pass `false` as the second argument:

```
// All PHP versions:
$browser->visit('/')->travelTo(Carbon::tomorrow(), false);

// Or if you'd like to use named parameters (PHP 8.0+):
$browser->visit('/')->travelTo(Carbon::tomorrow(), javascript: false);
```

Limitations:

- Requires Chrome/Chromium (the standard Dusk setup). On other drivers, or if the DevTools command is unavailable, browser-side faking silently degrades and server-side faking continues to work as before.
- Only the zero-argument functions are shifted. Explicit constructions like `new Date(2020, 0, 1)`, `Date.parse()` and `Date.UTC()` behave natively (as you'd expect).
- `performance.now()` and Web Workers are not faked.

Registering the `ModifyDuskBrowserTime` middleware
--------------------------------------------------

[](#registering-the-modifyduskbrowsertime-middleware)

By default, the package registers its middleware globally, so every request your application's HTTP kernel handles is covered — `web`, `api`, any custom middleware group, and even routes that don't belong to any group at all.

The middleware is inert unless the browser has actually traveled through time (with `travelTo()`), so this is safe even if your application has no `api` route group, or doesn't use one at all.

If you'd like more control, publish the config file:

```
php artisan vendor:publish --tag=dusk-time-travel-config
```

This creates `config/dusk-time-travel.php`:

```
return [
    'middleware' => true,
];
```

The `middleware` option accepts:

- `true` (default) — register globally, as described above.
- `false` — don't register the middleware anywhere automatically. Use this if you'd rather wire it up yourself.
- an array of middleware group names, e.g. `['web']` — register only on those groups instead of globally. Group names that you define but don't actually exist will be silently skipped.

**Note on Laravel 7.x:** Defining an array of middleware group names is only supported on Laravel 8 onwards. If an array is defined in the config file on Laravel 7, it will instead be silently handled as if you'd set it to boolean true instead and the middleware will be registered globally.

Testing
-------

[](#testing)

A test case is included in this respository, but since it's a Dusk extension the tests are run on a Laravel instance having Dusk installed. You can test the plugin the same way the `.github/workflows/run-tests.yml` workflow does.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Taha Paksu](https://github.com/tpaksu) (initial developer)
- [Shane Smith](https://github.com/shane-smith) (current maintainer)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance91

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 85.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~337 days

Recently: every ~55 days

Total

7

Last Release

44d ago

Major Versions

0.0.4 → 1.0.02026-07-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/baa85957b85812994a17cbfd9b1e63272c309c551aa94c78e7393efb9f967040?d=identicon)[tpaksu](/maintainers/tpaksu)

---

Top Contributors

[![tpaksu](https://avatars.githubusercontent.com/u/3295?v=4)](https://github.com/tpaksu "tpaksu (53 commits)")[![shane-smith](https://avatars.githubusercontent.com/u/943942?v=4)](https://github.com/shane-smith "shane-smith (8 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (1 commits)")

---

Tags

browserdusklaravellaravel-dusklaravel-dusk-cilaravel-packagetestingtime-travelpaksucodusk-time-travel

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/paksuco-dusk-time-travel/health.svg)

```
[![Health](https://phpackages.com/badges/paksuco-dusk-time-travel/health.svg)](https://phpackages.com/packages/paksuco-dusk-time-travel)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

79227.1M231](/packages/laravel-mcp)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[illuminate/routing

The Illuminate Routing package.

1239.4M3.5k](/packages/illuminate-routing)[intervention/image-laravel

Laravel Integration of Intervention Image

1589.8M226](/packages/intervention-image-laravel)[spatie/laravel-export

Create a static site bundle from a Laravel app

679153.2k7](/packages/spatie-laravel-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
