Skip to content
Puppeteer · error message

Puppeteer: Protocol error (Target.setDiscoverTargets): Target closed

ConfigurationProtocol, session & connection

Last verified

The exact message
ProtocolError: Protocol error (Target.setDiscoverTargets): Target closed

What 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-scraper

Why 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

  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.

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

Definitions

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.