# @amplitude/rrweb-snapshot

> rrweb's component to take a snapshot of DOM, aka DOM serializer

Latest version **2.1.2** (published 2026-06-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @amplitude/rrweb-snapshot
pnpm add @amplitude/rrweb-snapshot
yarn add @amplitude/rrweb-snapshot
bun add @amplitude/rrweb-snapshot
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2026-06-30 |
| First published | 2023-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Amplitude Inc |
| Maintainers | curtisbliu, kelson.warner, sdk.dev, eric_amplitude, daniel-graham-amplitude, jjwang123 |
| Keywords | rrweb, snapshot, DOM |

## Links

- npm: https://www.npmjs.com/package/@amplitude/rrweb-snapshot
- Repository: https://github.com/amplitude/rrweb
- Homepage: https://github.com/amplitude/rrweb/tree/master/packages/rrweb-snapshot#readme
- Issues: https://github.com/amplitude/rrweb/issues
- npm.io page: https://npm.io/package/@amplitude/rrweb-snapshot

## Dependencies (1)

- [postcss](https://npm.io/package/postcss.md) ^8.4.38

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.1.2 (latest) — 2026-06-30
- 2.0.0-alpha.12 (alpha) — 2023-10-24
- 2.1.0 — 2026-05-11
- 2.0.0-alpha.40 — 2026-05-04
- 2.0.0-alpha.39 — 2026-03-31
- 2.0.0-alpha.38 — 2026-03-30
- 2.0.0-alpha.37 — 2026-03-27
- 2.0.0-alpha.36 — 2026-03-18
- 2.0.0-alpha.35 — 2026-01-06
- 2.0.0-alpha.34 — 2025-12-15
- 2.0.0-alpha.33 — 2025-10-07
- 2.0.0-alpha.32 — 2025-07-09
- 2.0.0-alpha.31 — 2025-07-07
- 2.0.0-alpha.30 — 2025-06-12
- 2.0.0-alpha.29 — 2025-03-24
- … 16 more at https://npm.io/package/@amplitude/rrweb-snapshot/versions

## README

# rrweb-snapshot

[![Build Status](https://travis-ci.org/rrweb-io/rrweb.svg?branch=master)](https://travis-ci.org/rrweb-io/rrweb) [![Join the chat at slack](https://img.shields.io/badge/slack-@rrweb-teal.svg?logo=slack)](https://join.slack.com/t/rrweb/shared_invite/zt-siwoc6hx-uWay3s2wyG8t5GpZVb8rWg)

Snapshot the DOM into a stateful and serializable data structure.
Also, provide the ability to rebuild the DOM via snapshot.

## API

This module export following methods:

### snapshot

`snapshot` will traverse the DOM and return a stateful and serializable data structure which can represent the current DOM **view**.

There are several things will be done during snapshot:

1. Inline some DOM states into HTML attributes, e.g, HTMLInputElement's value.
2. Turn script tags into `noscript` tags to avoid scripts being executed.
3. Try to inline stylesheets to make sure local stylesheets can be used.
4. Make relative paths in href, src, CSS to be absolute paths.
5. Give an id to each Node, and return the id node map when snapshot finished.

#### rebuild

`rebuild` will build the DOM according to the taken snapshot.

There are several things will be done during rebuild:

1. Add data-rrid attribute if the Node is an Element.
2. Create some extra DOM node like text node to place inline CSS and some states.
3. Add data-extra-child-index attribute if Node has some extra child DOM.

#### serializeNodeWithId

`serializeNodeWithId` can serialize a node into snapshot format with id.

#### buildNodeWithSN

`buildNodeWithSN` will build DOM from serialized node and store serialized information in the `mirror.getMeta(node)`.

---
_Source: https://npm.io/package/@amplitude/rrweb-snapshot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
