Self-Hosted Session Replay for Laravel Apps | Mohamed Said       [Skip to content](#main)  [ ![](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png) Mohamed SaidLaravel Backend Engineer ](https://msaied.com) - [Home](https://msaied.com)
- [Projects](https://msaied.com/projects)
- [Articles](https://msaied.com/articles)
- [Certificates](https://msaied.com/certificates)
- [About](https://msaied.com#about)

           [  Contact](https://msaied.com#contact) Menu 

Menu
----

Close 

 - [HomeStart here](https://msaied.com)
- [ProjectsCase studies](https://msaied.com/projects)
- [ArticlesEngineering notes](https://msaied.com/articles)
- [CertificatesCredentials](https://msaied.com/certificates)
- [AboutHow I work](https://msaied.com#about)
- [ContactGet in touch](https://msaied.com#contact)

  [Start a conversation](https://msaied.com#contact) [WhatsApp](https://wa.me/201094619204) [Email](mailto:hello@msaied.com) 

 1. [Home](https://msaied.com)
2. /
3. [Articles](https://msaied.com/articles)
4. /
5. [Laravel](https://msaied.com/articles?category=laravel)
6. /
7. Session Replay for Laravel: Self-Hosted Browser Recordings with rrweb

   [Laravel](https://msaied.com/articles?category=laravel) [Composer Pacakge](https://msaied.com/articles?category=composer-pacakge) 

 Session Replay for Laravel: Self-Hosted Browser Recordings with rrweb
======================================================================

 packstub/session-replay lets you record, store, and replay browser sessions entirely within your own Laravel app — no third-party SaaS required. One Blade directive, privacy-first defaults, and a Filament v5 plugin included.

 ![](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp) [Mohamed Said](https://msaied.com#person) Published 12 Nov 2026 · Updated 18 Nov 2026 · 4 min read

ShareCopy linkCopied

 ![Session Replay for Laravel: Self-Hosted Browser Recordings with rrweb](https://cdn.msaied.com/828/5a9000a45d8f968025633b783bec83e9.png) 

  On this page +1. [Self-Hosted Session Replay for Laravel](#self-hosted-session-replay-for-laravel)
2. [Installation](#installation)
3. [Controlling Access](#controlling-access)
4. [How Recording Works](#how-recording-works)
5. [Timeline Markers](#timeline-markers)
6. [Error-Only Recording Mode](#error-only-recording-mode)
7. [Linking Log Entries to Replays](#linking-log-entries-to-replays)
8. [Filament v5 Plugin](#filament-v5-plugin)
9. [Key Takeaways](#key-takeaways)

 Self-Hosted Session Replay for Laravel
--------------------------------------

[packstub/session-replay](https://github.com/packstub/session-replay), built by Ion Căliman, brings browser session recording directly into your Laravel application. Instead of sending user data to a third-party SaaS tool, recordings are captured with **rrweb**, stored as gzip chunks on any Laravel disk, and indexed in your own database. You watch them through a built-in viewer at `/session-replay` — all behind a gate you control.

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

The package requires **PHP 8.3** and **Laravel 12 or 13**.

```bash
composer require packstub/session-replay
php artisan session-replay:install

```

Add the directive to your layout before the closing `` tag:

```blade
@sessionReplay

```

No front-end build step is needed. The directive injects a small config object and a deferred script that handles everything.

### Controlling Access

Define the `viewSessionReplay` gate in the published `SessionReplayServiceProvider`. Outside `local`, nobody can view recordings until this gate is set:

```php
Gate::define('viewSessionReplay', function ($user, ?ReplaySession $session = null): bool {
    return $user->is_admin;
});

```

Schedule the prune command to clean up recordings older than 30 days:

```php
Schedule::command('session-replay:prune')->daily();

```

How Recording Works
-------------------

When a page renders, the server signs the current user, tenant, and any custom properties into a token using your app key. The recorder sends that token with each gzipped upload, so the ingest endpoint requires no session, cookie, or CSRF token. Recordings continue across page loads until the tab goes idle.

**Privacy defaults out of the box:**

- Every input field is masked
- Guests are not recorded
- No IP address is stored
- Livewire `wire:snapshot` state is stripped before upload

Timeline Markers
----------------

The recorder annotates the playback timeline so you can jump straight to the moment something went wrong:

- Uncaught JavaScript errors and `console.error()` calls
- Failed Livewire, `fetch`, or XHR requests (HTTP 500+)
- Server-side exceptions reported by Laravel
- Page loads, `wire:navigate` swaps, Inertia and Vue Router navigations
- LCP, INP, and CLS web vitals
- Rage clicks (3+ clicks on the same spot within 700 ms)

You can also add custom markers or trigger an upload from a "report a problem" button:

```javascript
SessionReplay.mark('Checkout started', { cart: 3 });
SessionReplay.send('Wrong total on the invoice');

```

Error-Only Recording Mode
-------------------------

To minimise data collection, switch to `on_error` mode. The recorder keeps the last 60 seconds in browser memory and uploads nothing until a JavaScript error or failed request fires:

```php
// config/session-replay.php
'mode' => 'on_error',
'on_error' => [
    'buffer_seconds' => 60,
    'triggers' => ['error', 'request'],
    'ask' => false,
],

```

Set `ask` to `true` to prompt the user for consent before any data is sent.

Linking Log Entries to Replays
------------------------------

A global middleware adds the recording ID and viewer URL to **Laravel's Context**, which Laravel automatically includes in every log entry for that request:

```php
[2026-09-18 10:57:12] production.ERROR: Undefined array key "total"
{"exception":"…"} {"session_replay":"0b1c6a0e-…","session_replay_url":"https://app.test/session-replay/0b1c6a0e-…"}

```

Error trackers that read Context — Flare, Sentry, Nightwatch — receive the same keys automatically. A `session_replay_moment` key opens the replay three seconds before the failing request.

Filament v5 Plugin
------------------

The companion `packstub/filament-session-replay` package adds a filterable recordings resource, the player, and a user relation manager to any Filament v5 panel.

Key Takeaways
-------------

- **Zero third-party data transfer** — recordings stay on your own infrastructure
- **One Blade directive** to enable recording, no build tooling required
- **Error-only mode** limits uploads to sessions where something actually failed
- **Laravel Context integration** creates a direct link from log entries to the exact replay moment
- **Gate-protected viewer** ensures only authorised users can access recordings
- **Filament v5 plugin** available for teams already using Filament panels

---

*Source: [Session Replay for Laravel: Self-Hosted Browser Recordings — Laravel News](https://laravel-news.com/laravel-session-replay)*

- [session-replay](https://msaied.com/articles?search=session-replay)
- [laravel-package](https://msaied.com/articles?search=laravel-package)
- [rrweb](https://msaied.com/articles?search=rrweb)
- [self-hosted](https://msaied.com/articles?search=self-hosted)
- [filament](https://msaied.com/articles?search=filament)
- [debugging](https://msaied.com/articles?search=debugging)

 Frequently asked questions 
---------------------------

  Does packstub/session-replay send recording data to any external service?No. All recordings are stored as gzip chunks on a Laravel disk you configure and indexed in your own database. No data leaves your infrastructure.

   What is error-only recording mode and when should I use it?In `on\_error` mode the recorder keeps the last 60 seconds of events in browser memory and only uploads them when a JavaScript error or failed HTTP request occurs. Use it when you want to minimise data collection and only capture sessions where something actually went wrong.

   How do I restrict who can view session recordings?Define the `viewSessionReplay` gate in the published `SessionReplayServiceProvider`. The gate guards the recording list, the player, and every file served through it. Outside the `local` environment, no recordings are accessible until the gate is defined.

   ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)About the author
----------------

[Mohamed Said](https://msaied.com#person)Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

[About](https://msaied.com#about) [GitHub ↗](https://github.com/EG-Mohamed) [LinkedIn ↗](https://www.linkedin.com/in/msaiedm/) [WhatsApp ↗](https://wa.me/201094619204) [Email Address ↗](mailto:hello@msaied.com) [My CV ↗](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)  

   [Previous articleLaravel AI SDK 1.4: Agents Now Recover From Tool Failures](https://msaied.com/articles/laravel-ai-sdk-14-agents-now-recover-from-tool-failures) [Next articleFilament v4.16.4 Released: Bulk Selection Fix, Lazy Loading &amp; Authorization Improvements](https://msaied.com/articles/filament-v4164-released-bulk-selection-fix-lazy-loading-authorization-improvements)  

   On this page
-------------

1. [Self-Hosted Session Replay for Laravel](#self-hosted-session-replay-for-laravel)
2. [Installation](#installation)
3. [Controlling Access](#controlling-access)
4. [How Recording Works](#how-recording-works)
5. [Timeline Markers](#timeline-markers)
6. [Error-Only Recording Mode](#error-only-recording-mode)
7. [Linking Log Entries to Replays](#linking-log-entries-to-replays)
8. [Filament v5 Plugin](#filament-v5-plugin)
9. [Key Takeaways](#key-takeaways)

 ###  Have a technical challenge?

 Tell me what you’re building. I reply within two working days.

[Start a conversation](https://msaied.com#contact) 

   Related articles
-----------------

 [ ![](https://cdn.msaied.com/826/01M7K1GYR3B8JV1TBK6JRYVW1Q.png) Laravel · 8 min read### Why I Built AutReply: One Inbox and an AI Assistant for WhatsApp, Instagram and Messenger

16 Nov 2026 ](https://msaied.com/articles/why-i-built-autreply-one-inbox-and-an-ai-assistant-for-whatsapp-instagram-and-messenger) [ ![](https://cdn.msaied.com/827/1a3be4bd86589b895c32108fa01c7983.png) Filament · 3 min read### Filament v4.16.4 Released: Bulk Selection Fix, Lazy Loading &amp; Authorization Improvements

15 Nov 2026 ](https://msaied.com/articles/filament-v4164-released-bulk-selection-fix-lazy-loading-authorization-improvements) [ ![](https://cdn.msaied.com/824/9cedece04b58444cb565a8bec2be1737.png) Laravel · 4 min read### Laravel AI SDK 1.4: Agents Now Recover From Tool Failures

12 Nov 2026 ](https://msaied.com/articles/laravel-ai-sdk-14-agents-now-recover-from-tool-failures) 

  Have a technical challenge?
----------------------------

Tell me what you’re building. I reply within two working days.

 [Discuss your project ↗](https://msaied.com#contact) 

  © 2026 Mohamed Said · Built with Laravel, meant to last.Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

 - [Home](https://msaied.com)
- [Articles](https://msaied.com/articles)
- [Certificates](https://msaied.com/certificates)
- [GitHub](https://github.com/EG-Mohamed)
- [LinkedIn](https://www.linkedin.com/in/msaiedm/)
- [WhatsApp](https://wa.me/201094619204)
- [Email Address](mailto:hello@msaied.com)
- [My CV](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
- [Sitemap](https://msaied.com/sitemap.xml)
