Skills

Memlab Capture Heap Snapshots

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

Install

npx skills add meta/memlab --skill memlab-capture-heap-snapshots -g -a claude-code -y
Repository
meta/memlab5.1k
Category
Testing
Updated
4d ago
License
MIT
Context cost
Lightabout 1,234 tokens
Runs scripts
No, instructions only

What it does

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.

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 for a copy-paste helper that runs garbage collection and streams the snapshot to a file.

Node.js

Read the whole SKILL.md on GitHub

More in Testing