Mutation observer

In session replay, the mutation observer is the mechanism that watches the page's DOM for changes such as added nodes, removed nodes, and attribute or text edits, so each change can be recorded as an event. It is built on the browser's native MutationObserver API and is the reason replay captures changes without polling.

How it works

The recorder registers an observer on the document with options covering child lists, attributes, and character data. The browser queues mutation records and delivers them in a microtask after the DOM changes occur. The callback still runs on the main thread, so expensive serialization can delay the next frame. rrweb translates each batch into serialized mutation events that reference node ids from the snapshot. Batching matters for fidelity: a burst of mutations arrives together, and rrweb must resolve ordering such as a node being added and moved within one batch. The DOM Standard defines delivery, while rrweb's replay design notes show why batch ordering matters later.

Where you encounter it

Every DOM change in a replay passed through this path. The concept page is here; the underlying browser API has its own entry at MutationObserver API, and rrweb's observer documentation explains how batching feeds incremental snapshots.