rrweb · Frontend · Observability · JavaScript

Session Replay with rrweb: Record and Replay Real User Sessions

How to record browser sessions with rrweb using DOM events instead of video, keep personal data private, shrink payloads and replay bugs.

Sander Yazıcıoğlu Published: 3 min read Türkçe oku

The fastest way to solve a bug report that says "I clicked the button and nothing happened" is to see what the user did. I used rrweb while building a web session listener at Testinium. This article explains how rrweb works, how to set it up, and what to watch out for in production.

rrweb doesn't record video

rrweb ("record and replay the web") never captures a video of the screen. Instead it:

  1. Takes a full DOM snapshot of the page when recording starts.
  2. Records DOM changes (via MutationObserver), mouse moves, scrolls, form input and viewport changes as events.
  3. The player rebuilds the snapshot and applies the events in timestamp order.

The result is far less data than video, pixel-perfect playback, and a DOM you can inspect during replay.

Setup: recording

npm install rrweb
import { record } from 'rrweb';

const events = [];

const stop = record({
  emit(event) {
    events.push(event);
  },
  maskAllInputs: true,
  blockClass: 'rr-block',
  sampling: { mousemove: 50, scroll: 150, input: 'last' }
});

// Ship events in batches
setInterval(() => {
  if (!events.length) return;
  const batch = events.splice(0, events.length);
  navigator.sendBeacon('/api/sessions', JSON.stringify(batch));
}, 10000);

Options that matter:

  • maskAllInputs masks form values with *. Keep it on by default for privacy.
  • blockClass means elements with this class are never recorded; an empty box shows up instead. Use it for payment forms and personal data.
  • sampling thins out mouse-move and scroll events, which cuts payload size dramatically.

Playback

import rrwebPlayer from 'rrweb-player';
import 'rrweb-player/dist/style.css';

new rrwebPlayer({
  target: document.getElementById('player'),
  props: { events, autoPlay: false, skipInactive: true }
});

skipInactive skips long idle stretches, which saves time when you are hunting a bug.

Privacy by design

Session replay is powerful, but set up carelessly it becomes a personal-data leak. Under GDPR and similar laws:

  • Mask by default, unmask on purpose. Masking all input and unmasking known-safe fields is safer than the reverse.
  • Think about text, not just inputs. Names, emails and addresses rendered on screen are recorded even if they aren't form fields. Mask those regions with maskTextSelector.
  • Tell users and limit retention. Mention it in your privacy policy and delete recordings automatically after a set period.
  • Sample. Record a percentage of sessions, or only sessions with errors, rather than all of them.

Keeping payloads small

Long sessions and dynamic pages produce many events. Techniques that work:

  • Compression: event arrays are highly repetitive JSON. Compressing with gzip, or rrweb's packFn option, before upload shrinks them a lot.
  • Periodic full snapshots: take a fresh snapshot every so often with checkoutEveryNms, so you can start replay mid-session without loading every event from the start.
  • Don't record noise: exclude constantly changing animated ads, clocks or charts with blockClass.

Pairing it with error tracking

Session replay really shines when combined with error tracking. Attaching the last 30–60 seconds of the session to each captured JavaScript error largely removes "can't reproduce". With rrweb plugins you can also put console logs and network requests on the same timeline.

When not to use it

  • On pages dense with sensitive data (banking transactions, for example), masking can cost more than the replay is worth.
  • canvas and WebGL content aren't recorded by default; it is possible, but payloads grow fast.
  • Third-party cross-origin iframe content can't be recorded.

Conclusion

rrweb is a light, flexible tool for understanding bugs and improving UX. With proper masking, sampling and compression you protect both privacy and performance. To keep the recorder from slowing your page down, apply the "defer non-critical JavaScript" technique from the Core Web Vitals article.

December 2, 2026 · 4 min read

Full-Stack Developer Roadmap 2026: From Junior to Senior

What to learn, and in which order, to become a full-stack developer in 2026: the technologies that matter, where AI tools fit, and the skills that make you senior.

CareerFull-stackRoadmapFrontend

All articles →