Puppeteer "Protocol error ... Target closed" in CI
A "Protocol error ... Target closed" means the page or browser Puppeteer was driving went away mid-command, so the DevTools connection dropped. In CI this is usually a renderer crash from limited /dev/shm or an out-of-memory kill.
What this error means
A test throws "Protocol error (Runtime.callFunctionOn): Target closed" or "Protocol error (Page.navigate): Target closed", often intermittently, on a container runner.
Error: Protocol error (Runtime.callFunctionOn): Target closed.
at .../puppeteer/lib/cjs/puppeteer/common/Connection.js
ProtocolError: Protocol error (Page.navigate): Target closed.Common causes
The renderer crashed on small /dev/shm
The container default 64 MB /dev/shm starves Chromium, so the renderer process dies and the target closes.
The browser was killed by the OOM killer
A memory-heavy page or many parallel pages exhaust the runner memory, so the kernel kills the browser mid-operation.
How to fix it
Avoid the /dev/shm crash
- Launch with
--disable-dev-shm-usageso Chromium uses /tmp. - Or raise the container shared memory size.
- Re-run so the renderer no longer crashes under memory pressure.
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-dev-shm-usage'],
});Reduce memory pressure
Close pages you finish with and limit how many browser contexts run in parallel so the runner does not run out of memory.
const page = await browser.newPage();
try { /* ... */ } finally { await page.close(); }How to prevent it
- Use --disable-dev-shm-usage or a larger --shm-size in containers.
- Close pages and contexts promptly to bound memory.
- Cap parallel browser instances to the runner memory.