Registry / testing / memlab

memlab

JSON →
library2.0.1jsnpmunverified

MemLab is an end-to-end testing and analysis framework for identifying JavaScript memory leaks and optimization opportunities. Version 2.0.1 is the latest stable release, actively maintained by Meta. It provides automated browser memory leak detection using Puppeteer, a heap snapshot analysis API for Node.js/Electron/Hermes, and CLI tools for memory debugging. Key differentiators: supports custom leak detectors, object-oriented heap traversing, and integrates with unit testing. MemLab goes beyond simple heap dump analysis by automatically comparing snapshots and filtering leaks with retainer traces.

npm install memlab
INSTALL
IMPORT
SIG · MEMLAB
M
memlab
testingjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

memlab
import memlab from 'memlab'
const memlab = require('memlab')
MemLab is ESM-only since v2; CJS require will fail.
IScenario
import { IScenario } from 'memlab'
import IScenario from 'memlab'
Type-only export; must use named import.
takeHeapSnapshot
import { takeHeapSnapshot } from 'memlab'
import takeHeapSnapshot from 'memlab'
Named export for heap snapshot API.

Demonstrates using MemLab's programmatic API to define a scenario and run browser memory leak detection.

import memlab from 'memlab'; import fs from 'fs'; // Define a scenario as an object with url, action, back functions const scenario = { url: () => 'https://example.com', async action(page) { await page.click('button#load-more'); }, async back(page) { await page.click('button#reset'); } }; async function runLeakDetection() { // Run leak detection with default options const result = await memlab.run(scenario); console.log(`Leaks found: ${result.leaks.length}`); for (const leak of result.leaks) { console.log(`Retained size: ${leak.retainedSize}`); } } runLeakDetection().catch(console.error);
memlab --version
Debug
Known issues
breakingMemLab v2 drops CommonJS support; only ESM imports work.
fix
Use import syntax instead of require().
affects: >=2.0.0
breakingThe CLI 'memlab run' command changed its argument from --browser to --runner in v2.
fix
Use '--runner puppeteer' instead of '--browser puppeteer'.
affects: >=2.0.0 <2.0.1
deprecatedFunction 'createBrowserlessScenario' is deprecated in v2. Use the object-based scenario format.
fix
Define scenario as {url, action, back} instead.
affects: >=2.0.0
gotchaHeap snapshot files can be very large (multiple GB). Ensure sufficient disk space.
fix
Monitor disk usage; consider using --max-snapshots option to limit files.
affects: >=1.0.0
gotchaMemLab runs Puppeteer in headless mode by default; some sites may require full browser.
fix
Set headless: false in Puppeteer launch options within scenario.
affects: >=1.0.0
gotchaRetainer traces may be unavailable if minified code is served; use source maps.
fix
Ensure the website serves non-minified code or source maps for readable traces.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: memlab.run is not a function
Using require() instead of import for ESM-only package.
fix
Replace const memlab = require('memlab') with import memlab from 'memlab'.
Error: Cannot find module 'puppeteer'
Puppeteer is an optional peer dependency not installed.
fix
Run npm install --save-dev puppeteer to install it.
Error: The 'back' action must be a function
Missing or invalid 'back' function in scenario object.
fix
Define an async 'back' function that returns to the pre-action state.
Error: EACCES: permission denied, mkdir '/tmp/memlab'
MemLab uses /tmp for snapshot storage; may lack permissions.
fix
Override work directory with memlab.setWorkDir('/custom/path') or run with sudo.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
puppeteeroptionalUsed for browser automation in leak detection scenarios
Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
2
Resources
memlab — npm install memlab · libregistry