Last month I wrote a thing on why concurrent Puppeteer scraping is slow in Node.js. In it, I found a way to get a 3.3x local speedup (50 concurrent tabs) by isolating every tab inside its own browser context (browser.createBrowserContext() in Puppeteer or browser.newContext() in Playwright) to bypass Chromium's shared HttpCache lock. This works great on your beefy 32 GB workstation but do it on a 512 MB Docker worker or Kubernetes pod and it'll blow up in your face with exit code 137, or a cryptic Target closed / Target page, context or browser has been closed error.
Now, why do Playwright and Puppeteer run out of memory in Docker and Kubernetes, and how do we actually fix it? Let's break things down a little bit -- pairing some local container tuning with Scraping Browser, Web Unlocker, and residential proxies from Bright Data so high-concurrency workers don't chew through container RAM limits like candy -- or worse, get IP-banned.
If you paste a Docker Target closed stack trace into your AI assistant right now, it's going to give you the exact same three fixes people have been repeating since 2018. And in 2026, none of them actually work anymore:
- Pass
--disable-dev-shm-usageor increase--shm-sizebecause Docker's default 64 MB/dev/shmpartition must be filling up and crashing Chromium. - Call
await page.close()andawait context.close()inside afinallyblock so Chromium frees memory after every page. - Switch from Puppeteer to Playwright (or vice versa) because one supposedly manages headless browser memory better than the other.
TL;DR: It's a big fat nope to all three because modern Chromium puts shared memory in regular container RAM, not /dev/shm. Containers actually crash because new browser contexts hammer available RAM, Linux kills tab processes (with Target closed), and missing --init causes zombie processes. Solution: Reuse a context pool with --init locally, or move the browser off your container entirely.
How to Profile Playwright and Puppeteer OOM Crashes in Docker and Kubernetes Using Linux cgroup v2
First things first: you can't actually call process.memoryUsage() inside the Node process because in a headless browser, monitoring Node.js heapUsed or rss is useless — Node is just a lightweight JSON-RPC controller sending DevTools protocol messages, while Chromium spawns many separate OS child processes that consume 80% to 90% of the container's memory limit.
So if Node can't see its own browser memory, how do we actually see what's going on when Linux starts killing things?
Now, Linux kernel internals aren't really my day-to-day thing, so I had to dig into this a little bit. Turns out everything we need lives in the Linux cgroup v2 memory interface and the /proc filesystem — so I set up the worker to poll these every 50 ms and after every batch checkpoint:
- Linux cgroup v2 Memory Counters (
/sys/fs/cgroup/memory.current,memory.peak, andmemory.stat): Measures the true container-wide memory footprint across Node.js and all Chromium child processes, broken down intoanon(heap/stack),shmem(shared memory and anonymousmemfdregions), andfile(page cache). - Kernel OOM Kill Events (
/sys/fs/cgroup/memory.events): Tracksoomandoom_killcounters inside the container cgroup, combined withdocker inspect --format "{{.State.OOMKilled}}"from the host. - Shared Memory Filesystem (
statfsSync("/dev/shm")and/proc/<pid>/fd): Tracks actual block usage on Docker's 64 MB/dev/shmtmpfs mount alongside unlinked shared memory file descriptors. - Process Table Scanner (
/proc/<pid>/status): Counts livechromium/headless_shellsubprocesses, sums their individualVmRSS, and counts<defunct>zombie processes (State: Z (zombie)).
We need a telemetry sampler here that the worker will run inside the container:
import { readdirSync, readFileSync, statfsSync } from "node:fs";
const readIntSafe = (path: string): number => {
try {
return Number(readFileSync(path, "utf8").trim()) || 0;
} catch {
return 0;
}
};
const readKeyedFileSafe = (path: string): Record<string, number> => {
const out: Record<string, number> = {};
try {
for (const line of readFileSync(path, "utf8").split(/\r?\n/)) {
const [k, v] = line.trim().split(/\s+/);
if (k && v !== undefined && Number.isFinite(Number(v))) out[k] = Number(v);
}
} catch {}
return out;
};
export const sampleContainerTelemetry = () => {
const memCurrent = readIntSafe("/sys/fs/cgroup/memory.current");
const memPeak = readIntSafe("/sys/fs/cgroup/memory.peak");
const memStat = readKeyedFileSafe("/sys/fs/cgroup/memory.stat");
const memEvents = readKeyedFileSafe("/sys/fs/cgroup/memory.events");
const st = statfsSync("/dev/shm");
const devShmUsedBytes = (st.blocks - st.bfree) * st.bsize;
let chromeProcessCount = 0;
let chromeRssSumBytes = 0;
let zombieProcessCount = 0;
for (const pid of readdirSync("/proc")) {
if (!/^\d+$/.test(pid)) continue;
try {
const status = readFileSync(`/proc/${pid}/status`, "utf8");
if (/^State:\s+Z/m.test(status)) zombieProcessCount += 1;
if (/^Name:\s+(chrom|headless_shell)/m.test(status)) {
chromeProcessCount += 1;
const rssKb = Number(/^VmRSS:\s+(\d+)/m.exec(status)?.[1] ?? 0);
chromeRssSumBytes += rssKb * 1024;
}
} catch {}
}
return {
cgroupMemoryCurrentBytes: memCurrent,
cgroupMemoryPeakBytes: Math.max(memPeak, memCurrent),
cgroupShmemBytes: memStat["shmem"] ?? 0,
cgroupOomKillEvents: memEvents["oom_kill"] ?? 0,
devShmUsedBytes,
chromeProcessCount,
chromeRssSumBytes,
zombieProcessCount,
nodeRssBytes: process.memoryUsage().rss,
};
};
One thing I didn't really foresee when I started running these tests, by the way, was Linux swap. Every single scenario here MUST run in a fresh container with --memory-swap set to --memory — otherwise host swap kicks in and pretty much hides the exact OOM crashes we're trying to measure.
Playwright vs. Puppeteer Memory Usage and OOM Benchmark in Docker and Kubernetes
Both Playwright and Puppeteer run fine in a small container when tabs share one browser context, and both crash almost immediately when every page gets its own isolated context. And if you forget --init, timed-out browsers leave a huge pile of zombie processes behind.
| Scenario & Engine Mode | Docker Limits (--memory / --shm-size / --init) | Pages Completed | Kernel OOMKilled (oom_kill Events) | Peak Container cgroup RAM | Peak cgroup shmem (/memfd) | /dev/shm Mount Used | Peak Zombie PIDs | Throughput (pages/s) |
|---|---|---|---|---|---|---|---|---|
1. Puppeteer Shared Context (page.close()) | 512 MB / 64 MB / init=true | 150 / 150 | False (0) | 422.6 MB | 11.5 MB | 0.0 MB | 1 | 24.16/s |
2. Playwright Shared Context (page.close()) | 512 MB / 64 MB / init=true | 150 / 150 | False (0) | 421.9 MB | 29.8 MB | 0.0 MB | 1 | 22.95/s |
3. Puppeteer Isolated createBrowserContext() (1 GB) | 1 GB / 64 MB / init=true | 150 / 150 | False (0) | 656.3 MB | 12.1 MB | 0.0 MB | 5 | 17.52/s |
4. Playwright Isolated browser.newContext() (1 GB) | 1 GB / 64 MB / init=true | 150 / 150 | False (0) | 634.6 MB | 40.5 MB | 0.0 MB | 5 | 18.06/s |
| 5. Puppeteer Isolated Contexts in 512 MB | 512 MB / 64 MB / init=true | 5 / 150 | True (5 kills) | 512.0 MB | 5.2 MB | 0.0 MB | 5 | Crashed |
| 6. Playwright Isolated Contexts in 512 MB | 512 MB / 64 MB / init=true | 5 / 150 | True (5 kills) | 512.0 MB | 25.4 MB | 0.0 MB | 5 | Crashed |
7. Puppeteer 1080p Canvas (No --disable-dev-shm-usage) | 2 GB / 64 MB / init=true | 30 / 30 | False (0) | 901.4 MB | 275.3 MB | 0.0 MB | 1 | 4.18/s |
8. Puppeteer 1080p Canvas (--disable-dev-shm-usage) | 2 GB / 64 MB / init=true | 30 / 30 | False (0) | 916.0 MB | 279.1 MB | 0.0 MB | 1 | 4.06/s |
9. Playwright 1080p Canvas (--disable-dev-shm-usage) | 2 GB / 64 MB / init=true | 30 / 30 | False (0) | 1,157.4 MB | 231.2 MB | 0.0 MB | 3 | 3.55/s |
10. Playwright 1080p Canvas (No --disable-dev-shm-usage) | 2 GB / 64 MB / init=true | 30 / 30 | False (0) | 1,151.9 MB | 236.4 MB | 0.0 MB | 3 | 3.56/s |
11. Puppeteer Leaked Pages (Missing page.close()) | 512 MB / 256 MB / init=true | 12 / 120 | True (3 kills) | 512.0 MB | 15.9 MB | 0.0 MB | 1 | Crashed |
12. Playwright Leaked Pages (Missing page.close()) | 512 MB / 256 MB / init=true | 8 / 120 | True (2 kills) | 512.0 MB | 71.4 MB | 0.0 MB | 2 | Crashed |
13. Browser Timeout Kills WITHOUT Docker --init | 1 GB / 256 MB / init=false | 20 / 20 | False (0) | 278.1 MB | 5.2 MB | 0.0 MB | 220 zombies | 1.35/s |
14. Browser Timeout Kills WITH Docker --init | 1 GB / 256 MB / init=true | 20 / 20 | False (0) | 274.4 MB | 5.2 MB | 0.0 MB | 0 zombies | 1.37/s |
So yeah, that's a lot of numbers to take in, but at the end of the day, you only really need to pay attention to four things.
Let's start with why the most famous Docker flag in web scraping no longer does what developers think it does.
Why --disable-dev-shm-usage and /dev/shm No Longer Fix Playwright or Puppeteer OOM Crashes in Docker and Kubernetes
Modern Linux Chromium doesn't write to /dev/shm, even when rendering heavy 1080p pages without the --disable-dev-shm-usage flag. Instead, it allocates shared memory directly in your container's regular RAM.
Every single tutorial, blog post, and LLM still telling you to add --disable-dev-shm-usage to fix Docker crashes is operating on outdated info. Here's what happens now (as of November, 2026):
-
Both Puppeteer and Playwright already pass
--disable-dev-shm-usageby default: If you inspectpuppeteer.defaultArgs()in Puppeteer or the default Chromium launch args in Playwright, both libraries actually inject--disable-dev-shm-usageautomatically on every launch unless you go out of your way to remove it withignoreDefaultArgs: ["--disable-dev-shm-usage"]. Debian and Ubuntu's/usr/bin/chromiumwrapper script also injects it automatically. -
Chromium migrated Linux shared memory IPC to
memfd_create(): Even when we bypassed Debian's wrapper script by throwingexecutablePathstraight at the raw/usr/lib/chromium/chromiumELF binary and passedignoreDefaultArgs: ["--disable-dev-shm-usage"](Go back to the table above -- this is scenarios 7 and 10),statfsSync("/dev/shm")still recorded 0 bytes used.
For your edification, if you want to see how to strip default Chromium flags on launch, check out the official docs for Puppeteer ignoreDefaultArgs and Playwright browserType.launch({ ignoreDefaultArgs }).
Inspecting /proc/<pid>/fd inside the running container reveals why:
lrwx------ 1 root root 64 Nov 12 10:05 18 -> /memfd:shared-memory-region (deleted)
lr-x------ 1 root root 64 Nov 12 10:05 22 -> /memfd:shared-memory-region (deleted)
lr-x------ 1 root root 64 Nov 12 10:05 31 -> /memfd:shared-memory-region (deleted)
Modern Linux kernels and Chromium allocate shared memory between the browser, GPU, and renderer processes using memfd_create() (/memfd:shared-memory-region) or unlinked /tmp/.org.chromium.Chromium.* files.
And this is kind of wild to think about, because for years, that 64 MB /dev/shm limit was the one Docker problem everyone knew by heart. Now that Chromium puts shared memory straight into regular container RAM instead, every big page or screenshot eats directly into your container's --memory limit.
During our 6-tab screenshot test, shared memory goes from ~5 MB to 275 MB, pushing total container RAM past 900 MB in Puppeteer and about ~1200 MB in Playwright. So it didn't crash because /dev/shm filled up — it basically just crashed because total container RAM passed 1 GB and the Linux kernel killed 8 browser processes.
Why Playwright and Puppeteer Throw Target Closed in Docker and Kubernetes When Linux Runs Out of Memory (OOM)
When your Docker container runs out of RAM, Linux rarely kills your Node.js app. Instead, it actually starts killing Chromium tab process in the background, which breaks the connection and throws Target closed or Page crashed in Node.js while your container is just fine and dandy.
I know I've spent days debugging ProtocolError: Target closed or Target page, context or browser has been closed errors myself. My first thought is always that it's some kind of race condition in my TypeScript async/await code — which, I think it was last year I wasted a whole afternoon chasing something like that.
Turns out, no -- look at what actually happened inside /sys/fs/cgroup/memory.events during Scenarios 11 and 12 when we leaked unclosed pages inside a 512 MB container:
| Checkpoint (512 MB Limit) | Puppeteer Cgroup RAM | Puppeteer Chrome Processes | Puppeteer Kernel oom_kill Count | Playwright Cgroup RAM | Playwright Chrome Processes | Playwright Kernel oom_kill Count |
|---|---|---|---|---|---|---|
| Baseline (Browser Idle) | 231.3 MB | 11 | 0 | 171.7 MB | 8 | 0 |
| After 10 Leaked Pages | 509.6 MB | 21 | 2 kills | 507.2 MB | 18 | 2 kills |
At Target closed Exception | 512.0 MB | 20 | 3 kills | 512.0 MB | 18 | 2 kills |
| Node.js Process Status | Alive (exit code 0) | — | — | Alive (exit code 0) | — | — |
Whoa. Look at the last row. Even though the container went to the max 512.0 MB and the kernel executed oom_kill 2-3 times, the Node.js process didn't actually crash?!
This is because of the secret rules of engagement between Chromium and the Linux OOM killer: Chromium marks its tab processes as more expendable than the main browser or Node.js. Linux always kills the active tab first when memory runs out.
From Node.js's perspective, the tab simply vanished mid-command — and so obviously you get Target closed or timing out on Runtime.callFunctionOn.
So if you're only looking at whether the Docker container restarted, you're going to miss these OOM kills every single time — unless you're the nerdy type and obsessively inspect /sys/fs/cgroup/memory.events, I suppose 😄.
Why Isolated BrowserContexts (createBrowserContext and newContext) Cause Playwright and Puppeteer OOM Crashes in Docker and Kubernetes
Opening and closing normal tabs with page.close() is fairly safe — memory use will go up at first, but it will flatten out eventually. What actually crashes small Docker containers is creating a fresh incognito-style browser context for every single page.
This will become much easier to visualize if we compare the cgroup memory curve across 150 pages (let's say at concurrency = 5) between a shared BrowserContext vs. per-page isolated BrowserContexts:
| Pages Completed (Concurrency = 5) | Puppeteer Shared Context (512 MB Limit) | Playwright Shared Context (512 MB Limit) | Puppeteer Isolated Contexts (1 GB Limit) | Playwright Isolated Contexts (1 GB Limit) | Isolated Contexts in 512 MB Limit |
|---|---|---|---|---|---|
| Page 0 (Browser Launch) | 281.4 MB | 211.7 MB | 268.2 MB | 212.5 MB | 268.2 MB |
| Page 25 | 391.4 MB | 414.2 MB | 436.1 MB | 425.7 MB | OOMKilled at Page 5 (512.0 MB) |
| Page 50 | 390.1 MB | 415.9 MB | 446.8 MB | 424.9 MB | — |
| Page 100 | 391.4 MB | 415.3 MB | 460.9 MB | 424.6 MB | — |
| Page 150 | 389.8 MB | 418.4 MB | 455.2 MB | 427.5 MB | — |
Transient Peak (memory.peak) | 422.6 MB | 421.9 MB | 656.3 MB | 634.6 MB | 512.0 MB (5 oom_kills) |
After browser.close() | 112.1 MB | 99.6 MB | 105.8 MB | 97.4 MB | — |
There's two parts to what we're seeing in this table:
- Closing normal tabs does not leak memory: In a shared browser context, RAM usage goes up because Chromium is filling up its normal network and font caches (all business as usual). But see how from Page 25 to Page 150 memory usage is almost constant (~390 MB in Puppeteer, ~418 MB in Playwright)...as long as you call
page.close()insidefinally. - Creating a new context per page spikes RAM before cleanup finishes: Remember in my previous concurrency benchmark, I used isolated browser contexts to get a 3.3x speedup. But the catch in Docker is that spinning up and destroying a brand-new cookiejar and cache on every page happens way faster than Chromium can clean them up, funnily enough, and all of a sudden that whole speedup gets thrown out the window — spiking memory to 656.3 MB in Puppeteer and 634.6 MB in Playwright and crashing 512 MB containers almost immediately.
How to Pool Isolated BrowserContexts in Playwright and Puppeteer Without Spiking Container RAM
Simply put, if you run local headless Chromium inside a 512 MB or 1 GB Docker container, do not call createBrowserContext() / newContext() and context.close() on every single URL. Instead, pre-allocate a fixed pool of K isolated contexts (matching your worker concurrency) and clear cookies/storage between jobs, or recycle each context every N pages:
import { chromium, type Browser, type BrowserContext } from "playwright";
export class BoundedContextPool {
private contexts: BrowserContext[] = [];
private uses: number[] = [];
constructor(
private readonly browser: Browser,
private readonly poolSize: number,
private readonly maxUsesPerContext = 50,
) {}
async init(): Promise<void> {
for (let i = 0; i < this.poolSize; i++) {
this.contexts.push(await this.browser.newContext());
this.uses.push(0);
}
}
async withIsolatedPage<T>(slot: number, fn: (url: string) => Promise<T>, url: string): Promise<T> {
if (this.uses[slot]! >= this.maxUsesPerContext) {
await this.contexts[slot]!.close();
this.contexts[slot] = await this.browser.newContext();
this.uses[slot] = 0;
}
const ctx = this.contexts[slot]!;
this.uses[slot]! += 1;
await ctx.clearCookies();
const page = await ctx.newPage();
try {
return await fn(url);
} finally {
await page.close();
}
}
}
Why You Should Never Run Playwright or Puppeteer as PID 1 Without Docker
Regardless of how it happens -- when a Chromium browser crashes or gets force-killed after a timeout in Docker, its helper processes are left behind as dead <defunct> "zombie" processes because Node.js doesn't know how to clean them up.
In production scrapers, there's always going to be target websites that hang -- that's just kind of a given, isn't it? So when your typical browser.close() freezes, your code has to force-kill the browser and start a fresh one.
Uh oh. This is where things go from a minor annoyance to an absolute mess — we ended up with 220 zombie processes across just 20 browser timeouts without --init (and zero with it):
- Killing the main browser ALSO orphans its 11 helper processes: Every Chromium instance spawns around 11 child processes for tabs, networking, and graphics (This is a little unintuitive -- read more about Chromium's multi-process architecture here if you'd like). When you force-kill the main browser, these 11 helpers lose their parent and get handed over to the main container process (PID 1).
- Linux persists dead processes in the table until PID 1 acknowledges them: When those 11 helpers finish "dying", Linux keeps their slots open as
<defunct>zombies until PID 1 officially clears them. - Also, Node.js ignores processes it didn't start itself: When you use
CMD ["node", "dist/worker.js"], you'll see that Node.js runs as PID 1. Because Node only cleans up the main browser process it spawned directly and flat out ignores the 11 grandchildren, those zombie entries pile up until the container hits its process limit and refuses to launch any more browsers — even with plenty of free RAM!
How to Fix Chromium Zombie Processes in Docker and Kubernetes with --init and tini
Passing --init to docker run (which injects tini as PID 1) or configuring tini in your Dockerfile / Kubernetes pod spec will properly clear out every reparented Chromium grandchild automatically, dropping our "zombie" count from 220 down to 0:
FROM node:22-bookworm-slim
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
ENV CHROMIUM_EXECUTABLE_PATH=/usr/lib/chromium/chromium
RUN apt-get update && apt-get install -y --no-install-recommends \
chromium \
tini \
fonts-liberation \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["node", "dist/worker.js"]
NOTE: This tini ("tiny init") is a tiny process wrapper that is always at PID 1, launching your Node.js app as its child, and garbage collecting Chromium helper processes so your container's process table won't fill up.
How to Scale Playwright and Puppeteer in Docker and Kubernetes Without OOM Crashes or IP Bans Using Bright Data
Adding tini and bumping your container RAM will stop the crashes, sure, but there's still a catch when you try to scale this up. The moment you run dozens of isolated browser contexts at once, you start paying for huge containers while every single tab still goes out through the same datacenter IP and gets blocked.
At the end of the day, local container tuning only gets you so far.
- The Container Memory Ceiling is still an issue. If you want 50 concurrent isolated tabs to bypass Chromium's
HttpCachelock, a single container will need several gigabytes of RAM just to contain the V8 renderer processes and shared mem buffers. - Per-Context IP rotation will become a problem. Because isolated BrowserContexts do not share cookies or cached tokens, if you start concurrent contexts from a single container IP it WILL trigger Cloudflare, DataDome, and rate-limit blocks unless each context routes through its own residential IP. Using something like Bright Data's Residential Proxies will help.
Option 1: Per-Context Bright Data Residential Proxy Rotation for Playwright and Puppeteer in Docker and Kubernetes
If you self-host Chromium inside a 1 GB+ container (with tini enabled), pass your Bright Data proxy zone credentials to either browser.newContext({ proxy }) (Playwright) or page.authenticate() (Puppeteer):
import { chromium, type Browser } from "playwright";
export const scrapeWithIsolatedProxyContext = async (
browser: Browser,
targetUrl: string,
sessionId: string,
): Promise<string> => {
const context = await browser.newContext({
proxy: {
server: "http://brd.superproxy.io:33335",
username: `brd-customer-${process.env.BRIGHT_DATA_CUSTOMER_ID}-zone-${process.env.BRIGHT_DATA_ZONE}-session-${sessionId}`,
password: process.env.BRIGHT_DATA_PASSWORD!,
},
});
const page = await context.newPage();
try {
await page.goto(targetUrl, { waitUntil: "domcontentloaded", timeout: 30_000 });
return await page.content();
} finally {
await page.close();
await context.close();
}
};
Option 2: Zero Local Chromium RAM usage with Bright Data Scraping Browser and Web Unlocker
I will say, one thing in the benchmark logs really stood out to me right at the end of every run. As soon as browser.close() finished, container memory immediately dropped from 400–1,150 MB all the way back down to about 100 MB — zero Chrome processes, exactly 0 MB of shmem, and no zombie processes.
And when you look at that, you kind of have to ask why we're paying for 2 GB or 4 GB containers just to babysit Chromium in the first place. If you take your browser out of the container, your Node worker will plateau at around 100 MB inside a cheap 256-512 MB container.
To do this, you have two options:
- Bright Data Scraping Browser (Drop-In Remote CDP for Playwright and Puppeteer): Replace
chromium.launch()/puppeteer.launch()withchromium.connectOverCDP()orpuppeteer.connect(). Your existing Playwright or Puppeteer interaction code will still run unchanged inside your lightweight Node.js container while Chromium execution,/memfdrendering, automatic CAPTCHA solving, and residential IP rotation all happen on Bright Data's remote browser cluster. No muss, no fuss. - Bright Data Web Unlocker (Replace Headless Browsers with Standard
fetch()): If your pipeline only has to open a tab, wait for JavaScript rendering, and callpage.content(), send a single HTTP POST request to Web Unlocker (https://api.brightdata.com/request) and let the proxy edge handle headless rendering and anti-bot unblocking with zero WebSocket or CDP state.
import { chromium } from "playwright";
import puppeteer from "puppeteer";
const SBR_WS_ENDPOINT =
`wss://brd-customer-${process.env.BRIGHT_DATA_CUSTOMER_ID}-zone-${process.env.BRIGHT_DATA_SBR_ZONE}:` +
`${process.env.BRIGHT_DATA_SBR_PASSWORD}@brd.superproxy.io:9222`;
// 1. Playwright: zero local Chromium processes or /memfd shmem inside Docker
export const connectPlaywrightScrapingBrowser = () =>
chromium.connectOverCDP(SBR_WS_ENDPOINT);
// 2. Puppeteer: scale isolated sessions without hitting 512 MB container OOM limits
export const connectPuppeteerScrapingBrowser = () =>
puppeteer.connect({ browserWSEndpoint: SBR_WS_ENDPOINT });
So yeah, that's pretty much where things are at. I'll leave you with a quick decision table as a cheatsheet.
Summary: How to Prevent Playwright and Puppeteer Out-of-Memory (OOM) Crashes in Docker and Kubernetes
If you want Playwright or Puppeteer to stay up in Docker, it's pretty safe to ignore the old /dev/shm advice. Pool your browser contexts so RAM doesn't spike, run tini so crashed tabs actually get cleaned up, or offload the browser when concurrency grows expensive:
| Container Scraping Setup | Minimum Safe Docker --memory (Concurrency = 5) | Peak Container cgroup RAM | Peak shmem / /dev/shm Used | Survives 512 MB Container? | Zombie Risk Without --init | Anti-Bot & IP Rotation |
|---|---|---|---|---|---|---|
| Puppeteer / Playwright Unclosed Page Leak | Crashes any fixed limit | 512.0 MB+ (+22–35 MB/page) | 15.9–71.4 MB / 0.0 MB | No (OOM at Page 8–12) | High on crash | None |
Isolated Context per Page (createBrowserContext / newContext) | 1 GB+ | 634.6–656.3 MB | 12.1–40.5 MB / 0.0 MB | No (OOM at Page 5) | 220 zombies / 20 timeouts | Requires per-context proxy (brd.superproxy.io) |
Shared Context or Bounded Context Pool + tini (--init) | 512 MB (HTML) / 2 GB (1080p Screenshots) | 421.9–422.6 MB (HTML) / 1,157 MB (Canvas) | 275.3 MB (memfd) / 0.0 MB | Yes (150/150 HTML pages) | 0 zombies (with tini) | Single proxy per context slot |
Playwright / Puppeteer + Bright Data Scraping Browser (connectOverCDP) | 256 MB – 512 MB | ~85–120 MB (Node.js only) | 0.0 MB / 0.0 MB | Yes (0 local Chrome PIDs) | 0 zombies | Built-in residential IP rotation, browser fingerprinting & CAPTCHA solving |
Node.js fetch() + Bright Data Web Unlocker | 128 MB – 256 MB | ~60–90 MB (Node.js only) | 0.0 MB / 0.0 MB | Yes (1,000+ concurrent) | 0 zombies | Edge JS rendering, WAF/CAPTCHA unblocking & residential proxies |
FAQ: Why Playwright and Puppeteer Run Out of Memory (OOM) in Docker and Kubernetes
Why does Playwright or Puppeteer crash with Target closed in Docker and Kubernetes when Node.js still has free heap memory?
Because Node.js process.memoryUsage().heapUsed only measures the Node controller (~30 MB heap, ~120 MB RSS), while Chromium's 11 to 23 child processes consume the rest of the container's cgroup memory limit. When total container RAM hits --memory, the Linux kernel OOM killer sacrifices a Chromium renderer subprocess (oom_kill in /sys/fs/cgroup/memory.events), which closes the DevTools session and throws Target closed in Node.js without killing the container itself.
Does --disable-dev-shm-usage or increasing --shm-size still fix Playwright and Puppeteer OOM crashes in Docker and Kubernetes?
Rarely on modern stacks. Both Puppeteer (v22+) and Playwright already include --disable-dev-shm-usage in their default launch arguments, Debian/Ubuntu's /etc/chromium.d/default-flags enables it automatically whenever /dev/shm is under 3.8 GB, and modern Linux Chromium allocates shared memory via anonymous /memfd:shared-memory-region descriptors (0.0 MB on /dev/shm). Because memfd buffers count toward container cgroup shmem RAM (reaching 275.3 MB during 1080p canvas screenshots), increasing --shm-size will not prevent a cgroup OOM kill — you must increase --memory or reduce concurrent screenshot viewports.
Does Playwright use less memory than Puppeteer in Docker and Kubernetes containers?
In steady-state HTML scraping, both use virtually identical container memory because both drive the same underlying Chromium engine: across 150 pages at concurrency 5 in a shared BrowserContext, Puppeteer peaked at 422.6 MB and Playwright peaked at 421.9 MB. On isolated BrowserContext churn, Playwright peaked slightly lower (634.6 MB vs. Puppeteer's 656.3 MB), while on concurrent 1080p full-page screenshots Playwright peaked higher (1,157.4 MB vs. Puppeteer's 916.0 MB) due to font-readiness and compositor buffering before capture.
Why do defunct zombie Chromium processes build up in Docker and Kubernetes when running Playwright or Puppeteer?
When Node.js runs as PID 1 in a container (CMD ["node", "worker.js"]) and a Chromium browser process crashes or is killed with SIGKILL after a timeout, its 11 child processes (renderer, zygote, utility, gpu-process) reparent to PID 1. Because Node.js does not call waitpid() on reparented grandchildren, every crashed browser leaves ~11 <defunct> zombies in /proc (220 zombies across 20 timeouts in our test). Run Docker with --init or add tini as your ENTRYPOINT to reap orphaned Chromium processes automatically.
Further Reading
Discover more articles on similar topics across our network

Comments
Loading comments…