# Memlab Capture Heap Snapshots

Capture JavaScript heap snapshots (.heapsnapshot files) for memory analysis from Chrome...

- Repository: https://github.com/meta/memlab (5081 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-10-31
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add meta/memlab --skill memlab-capture-heap-snapshots -g -a claude-code -y`
Codex: `npx skills add meta/memlab --skill memlab-capture-heap-snapshots -g -a codex -y`
Cursor: `npx skills add meta/memlab --skill memlab-capture-heap-snapshots -g -a cursor -y`
Gemini CLI: `npx skills add meta/memlab --skill memlab-capture-heap-snapshots -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add meta/memlab`

## Description

Capture JavaScript heap snapshots (.heapsnapshot files) for memory analysis from Chrome or Edge, Puppeteer, Playwright, Node.js, Electron or React Native (Hermes), including a series of snapshots that shows what grows over repeated interactions. Use when the user needs a heap snapshot, a heap dump of a Node.js process or one taken near out-of-memory, wants to measure memory growth or a suspected leak, or asks how to take snapshots in a test so memlab can analyze them.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Capture JavaScript heap snapshots

A heap snapshot is a full dump of a JavaScript heap: every object, the
references between them, and their sizes. memlab, Chrome DevTools and the
memlab MCP server all read the same `.heapsnapshot` format.

## Decide what to capture first

- **"What is using memory?"** One snapshot, taken when memory is high.
- **"Is something leaking?"** Several snapshots from the **same** page or
  process: no reload and no restart in between, with the suspect interaction
  repeated between captures. A single snapshot can't show growth.
- Take snapshots from a build that matches the problem. Development builds
  (React development mode, hot reload, source-map tooling) hold extra memory a
  production build doesn't.

## Browser (Chrome, Edge)

**By hand**: DevTools → **Memory** → **Heap snapshot** → **Take snapshot**,
then right-click the snapshot → **Save...**. DevTools runs garbage collection
before each snapshot. Use a profile without extensions (or a guest window):
extensions add their own objects to the page's heap.

**From an agent, with the memlab MCP server**: start the browser with
`--remote-debugging-port=9222 --user-data-dir=/tmp/chrome-memlab`, then call
`memlab_capture` with `out_dir` and a `label`. Chrome 136 and later ignore
`--remote-debugging-port` on the default profile, so the separate
`--user-data-dir` is required; a fresh profile also has no extensions. It also captures the page's dedicated workers, which a page snapshot
never includes. `list_targets: true` lists the pages it can attach to, and
`url_filter` picks one. A saved capture can later be referred to as
`checkpoint:<label>` wherever a snapshot path is accepted.

**From Puppeteer or Playwright test code** (Chromium only): use a CDP session.
See [references/capture-code.md](references/capture-code.md) for a
copy-paste helper that runs garbage collection and streams the snapshot to a
file.

## Node.js

The rest: https://github.com/meta/memlab/blob/HEAD/plugins/memlab/skills/memlab-capture-heap-snapshots/SKILL.md
