world

Laravel Session Replay Brings Self-Hosted DOM Recording via rrweb

Packstub's open-source Laravel package records DOM sessions via rrweb, buffers 60 seconds in memory, and saves gzipped replays only when errors occur.

Laravel Session Replay Brings Self-Hosted DOM Recording via rrweb

Debugging production bugs often stalls on a familiar bottleneck: the stack trace shows where the server failed, but not what the user actually clicked, typed, or saw in the browser seconds earlier. A new open-source package from Packstub, Session Replay for Laravel, created by Ion Căliman and featured on Laravel News, brings self-hosted browser session recording directly into Laravel 12 and 13 applications running on PHP 8.3.

How the Self-Hosted Recorder Works

Unlike third-party SaaS analytics suites that stream user interactions to external clouds, packstub/session-replay stores recordings as gzip-compressed chunks on any configured Laravel filesystem disk while indexing metadata in your own database. Integration requires no front-end build step: developers drop a single @sessionReplay Blade directive before the closing body tag of a layout. That directive outputs a lightweight configuration object and a deferred script powered by rrweb, an established open-source library for capturing DOM snapshots and incremental mutations.

Each browser tab maintains one continuous recording across page loads until the tab goes idle, uploading compressed batches every few seconds. To avoid coupling the ingestion endpoint to browser cookies, sessions, or CSRF tokens, the server signs the authenticated user, tenant, and optional custom properties into a token using the application key when the page renders. Because the token is signed rather than encrypted, developers must keep sensitive secrets out of those custom properties.

Error-Only Buffering and Timeline Markers

Recording every single session can quickly inflate storage bills and noise. To address that, the package supports an on_error mode in config/session-replay.php. In this mode, the browser holds a rolling 60-second buffer (buffer_seconds => 60) strictly in memory and uploads nothing until a configured trigger—such as a JavaScript error or failed request—fires. Once triggered, the recorder flushes the preceding minute and continues capturing the remainder of the tab's session. Teams with stricter consent workflows can also enable ask => true to prompt the user before uploading.

The built-in player at /session-replay overlays structured timeline markers so engineers can jump straight to failure points instead of scrubbing through idle footage. Supported markers include:

  • Uncaught JavaScript exceptions and console.error() calls.
  • Failed Livewire requests and same-origin fetch or XHR responses returning HTTP 500 or higher.
  • Server-side Laravel exceptions, complete with exception class, HTTP method, path, and report ID.
  • Navigation events across full page loads, wire:navigate swaps, Inertia, and Vue Router.
  • Core Web Vitals (LCP, INP, CLS) and rage clicks (three or more clicks on the same spot within 700 ms).

Teams can also emit custom milestones from JavaScript via SessionReplay.mark() or wire a user-facing bug report button to SessionReplay.send(), attaching a report marker directly to the uploaded timeline.

Deep Integration with Laravel Context and Access Gates

Where the package stands out for backend engineers is its bidirectional link to server observability. A global middleware automatically injects session_replay, session_replay_url, and session_replay_moment keys into Laravel Context during recorded requests. Every log line written for that request inherits those identifiers, and error trackers that read Context—including Flare, Sentry, and Nightwatch—receive direct links that open the replay three seconds before the failing request hit the server. In the opposite direction, SessionReplay::logUrlUsing() adds an Open in logs button next to server error markers inside the player, linking out to tools such as Log Viewer.

Security and privacy defaults are opinionated out of the box. Every form input is masked by default, guest visitors are skipped, IP addresses are not stored, and Livewire's wire:snapshot state is stripped prior to upload. Outside the local environment, nobody can access the recording list, player, or underlying chunk files until a viewSessionReplay Gate is explicitly defined in SessionReplayServiceProvider. Scheduling session-replay:prune daily cleans up recordings automatically after 30 days.

Why It Matters for Laravel Teams

For SaaS products handling regulated or sensitive workflows—healthcare, finance, or internal enterprise tooling—sending full DOM streams to third-party replay vendors often triggers lengthy compliance reviews. Keeping rrweb recordings inside existing Laravel disks, behind native authorization gates, and coupled directly to Laravel Context removes both vendor lock-in and external data exposure. Teams already building admin dashboards on Filament v5 also get a companion package, packstub/filament-session-replay, which embeds a filterable recordings resource, player, and user relation manager directly into the panel.

// sources

// WebZona Studio products

Need a product or service that does not exist yet?

Pitch your idea in our "50 Hours" program — every month we build one community idea free for everyone. Or explore our released products.

// comments (0)

// no comments yet.