Puppeteer: Protocol error (Target.setDiscoverTargets): Target closed
Last verified
ProtocolError: Protocol error (Target.setDiscoverTargets): Target closedWhat it means
Puppeteer talks to Chrome over the Chrome DevTools Protocol. During puppeteer.launch() or puppeteer.connect(), one of the first commands it sends is Target.setDiscoverTargets. If the browser connection closes before the reply arrives, every pending command is rejected with Target closed, and the method name in parentheses tells you which command was waiting.
When the method is Target.setDiscoverTargets, the browser died almost immediately after starting. That makes this a launch-environment problem in disguise: the same root causes as Failed to launch the browser process, but the process lived just long enough to open the connection. Containers with tiny /dev/shm, missing libraries, sandbox restrictions and out-of-memory kills are the usual culprits. With other method names, for example Runtime.callFunctionOn, the page or browser closed mid-script.
What is not wrong: your scraping logic. No page has loaded yet.
What it looks like
const browser = await puppeteer.launch({
dumpio: true, // pipe Chrome's stdout/stderr to the console
args: ['--disable-dev-shm-usage'],
});
# docker run with more shared memory
docker run --shm-size=1gb my-scraperWhy it happens
- Chrome crashed on start because /dev/shm is too small in Docker (64 MB by default).
- Missing shared libraries or sandbox restrictions kill the process right after it opens the pipe.
- The container or serverless function ran out of memory.
- browser.close() or process exit happened while launch or connect was still in progress.
- Connecting to a remote browser whose WebSocket endpoint closed or belonged to an expired session.
How to fix it
- Launch with dumpio: true to print Chrome's own stderr and see why it exited.
- In Docker, add --shm-size=1gb (or --ipc=host), or pass args: ['--disable-dev-shm-usage'].
- Apply the fixes for missing libraries and sandboxing from the Failed to launch the browser process entry.
- Increase memory for the container or function, and close pages you no longer need.
- For remote browsers, fetch a fresh browserWSEndpoint immediately before calling connect.
How to stop it recurring
Size containers for Chrome: at least 1 GB of shared memory or --disable-dev-shm-usage, and enough RAM for the number of concurrent pages. Keep a launch smoke test in CI. When the method in parentheses is not a Target command, look for code that closes the browser too early.
Official documentation: pptr.dev/troubleshooting. See all Puppeteer error messages.
Related errors
- Failed to launch the browser processError: Failed to launch the browser process: Code: 127 stderr:…
- Session closed. Most likely the page has been closed.Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely…
- Could not find Chrome (ver. X). This can occur if either...Error: Could not find Chrome (ver. 142.0.7444.59). This can occur if either…
Definitions
- PuppeteerPuppeteer is Google's open-source Node.js library for controlling Chrome and Firefox. It drives Chrome over th
- Chrome DevTools Protocol (CDP)The Chrome DevTools Protocol (CDP) is the JSON-over-WebSocket interface Chrome exposes for inspecting and cont
- CSS SelectorA CSS selector is a pattern used to identify and target specific HTML elements on a web page, widely used in b
- Headless ChromeHeadless Chrome is Google Chrome running without a visible window. It renders pages and runs JavaScript like n
- IframeAn iframe (inline frame) is an HTML element that embeds a separate web page within a parent page, creating an
- Web ElementA web element is any individual component rendered on a web page — buttons, links, input fields, images, text
Quick answers
What does "Protocol error (Target.setDiscoverTargets): Target closed" mean in Puppeteer?
Puppeteer talks to Chrome over the Chrome DevTools Protocol. During puppeteer.launch() or puppeteer.connect() , one of the first commands it sends is Target.setDiscoverTargets . If the browser connection closes before the reply arrives, every pending command is rejected with Target closed , and the method name in parentheses tells you which command was waiting.
How do I fix "Protocol error (Target.setDiscoverTargets): Target closed"?
1. Launch with dumpio: true to print Chrome's own stderr and see why it exited. 2. In Docker, add --shm-size=1gb (or --ipc=host), or pass args: ['--disable-dev-shm-usage']. 3. Apply the fixes for missing libraries and sandboxing from the Failed to launch the browser process entry. 4. Increase memory for the container or function, and close pages you no longer need. 5. For remote browsers, fetch a fresh browserWSEndpoint immediately before calling connect.
Run browser automation you can watch and take over
Autonoly runs each job in a real cloud Chromium browser driven by Playwright. Timeouts and detached elements still happen; the difference is that you can watch the run live, see the step that failed, and take control of the browser to finish it.
Also see Live browser control.