`Protocol error (Target.setDiscoverTargets): Target closed` when `puppeteer.launch` fails with `pipe: true`
See original GitHub issueSimilar to #4374, it appears that puppeteer.launch fails with a different error messaging depending on the pipe option. The error messaging for pipe: true is confusing.
Steps to reproduce
Happy Path - Attempt Launch Puppeteer `pipe: false` in Docker, missing runtime dependencies:
$ docker run --rm -it node:erbium-slim sh -c 'yarn add puppeteer; node -e "const puppeteer = require(\"puppeteer\"); puppeteer.launch({pipe: false})"'
yarn add v1.22.4
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 51 new dependencies.
info Direct dependencies
ββ puppeteer@5.2.1
info All dependencies
ββ @types/node@14.0.24
ββ @types/yauzl@2.9.1
ββ agent-base@5.1.1
ββ balanced-match@1.0.0
ββ base64-js@1.3.1
ββ bl@4.0.2
ββ brace-expansion@1.1.11
ββ buffer-crc32@0.2.13
ββ buffer@5.6.0
ββ chownr@1.1.4
ββ concat-map@0.0.1
ββ debug@4.1.1
ββ devtools-protocol@0.0.781568
ββ end-of-stream@1.4.4
ββ extract-zip@2.0.1
ββ fd-slicer@1.1.0
ββ find-up@4.1.0
ββ fs-constants@1.0.0
ββ fs.realpath@1.0.0
ββ get-stream@5.1.0
ββ glob@7.1.6
ββ https-proxy-agent@4.0.0
ββ ieee754@1.1.13
ββ inflight@1.0.6
ββ locate-path@5.0.0
ββ mime@2.4.6
ββ minimatch@3.0.4
ββ mkdirp-classic@0.5.3
ββ ms@2.1.2
ββ once@1.4.0
ββ p-limit@2.3.0
ββ p-locate@4.1.0
ββ p-try@2.2.0
ββ path-exists@4.0.0
ββ path-is-absolute@1.0.1
ββ pend@1.2.0
ββ pkg-dir@4.2.0
ββ progress@2.0.3
ββ proxy-from-env@1.1.0
ββ puppeteer@5.2.1
ββ readable-stream@3.6.0
ββ rimraf@3.0.2
ββ safe-buffer@5.2.1
ββ string_decoder@1.3.0
ββ tar-fs@2.1.0
ββ tar-stream@2.1.3
ββ through@2.3.8
ββ unbzip2-stream@1.4.3
ββ util-deprecate@1.0.2
ββ ws@7.3.1
ββ yauzl@2.10.0
Done in 90.98s.
(node:40) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
/node_modules/puppeteer/.local-chromium/linux-782078/chrome-linux/chrome: error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
at onClose (/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
at Interface.<anonymous> (/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:183:68)
at Interface.emit (events.js:327:22)
at Interface.close (readline.js:416:8)
at Socket.onend (readline.js:194:10)
at Socket.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1221:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:40) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:40) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Sad Path - Same as above, except with `pipe: true`
docker run --rm -it node:erbium-slim sh -c 'yarn add puppeteer; node -e "const puppeteer = require(\"puppeteer\"); puppeteer.launch({pipe: true})"'
yarn add v1.22.4
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 51 new dependencies.
info Direct dependencies
ββ puppeteer@5.2.1
info All dependencies
ββ @types/node@14.0.24
ββ @types/yauzl@2.9.1
ββ agent-base@5.1.1
ββ balanced-match@1.0.0
ββ base64-js@1.3.1
ββ bl@4.0.2
ββ brace-expansion@1.1.11
ββ buffer-crc32@0.2.13
ββ buffer@5.6.0
ββ chownr@1.1.4
ββ concat-map@0.0.1
ββ debug@4.1.1
ββ devtools-protocol@0.0.781568
ββ end-of-stream@1.4.4
ββ extract-zip@2.0.1
ββ fd-slicer@1.1.0
ββ find-up@4.1.0
ββ fs-constants@1.0.0
ββ fs.realpath@1.0.0
ββ get-stream@5.1.0
ββ glob@7.1.6
ββ https-proxy-agent@4.0.0
ββ ieee754@1.1.13
ββ inflight@1.0.6
ββ locate-path@5.0.0
ββ mime@2.4.6
ββ minimatch@3.0.4
ββ mkdirp-classic@0.5.3
ββ ms@2.1.2
ββ once@1.4.0
ββ p-limit@2.3.0
ββ p-locate@4.1.0
ββ p-try@2.2.0
ββ path-exists@4.0.0
ββ path-is-absolute@1.0.1
ββ pend@1.2.0
ββ pkg-dir@4.2.0
ββ progress@2.0.3
ββ proxy-from-env@1.1.0
ββ puppeteer@5.2.1
ββ readable-stream@3.6.0
ββ rimraf@3.0.2
ββ safe-buffer@5.2.1
ββ string_decoder@1.3.0
ββ tar-fs@2.1.0
ββ tar-stream@2.1.3
ββ through@2.3.8
ββ unbzip2-stream@1.4.3
ββ util-deprecate@1.0.2
ββ ws@7.3.1
ββ yauzl@2.10.0
Done in 40.60s.
(node:41) UnhandledPromiseRejectionWarning: Error: Protocol error (Target.setDiscoverTargets): Target closed.
at /node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:71:63
at new Promise (<anonymous>)
at Connection.send (/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:70:16)
at Function.create (/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:95:26)
at ChromeLauncher.launch (/node_modules/puppeteer/lib/cjs/puppeteer/node/Launcher.js:106:56)
(node:41) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:41) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Tell us about your environment:
- Puppeteer version:
5.2.1 - Platform / OS version: Docker
node:erbium-slim - URLs (if applicable):
- Node.js version:
v12.18.2
What steps will reproduce the problem?
Please see above.
- Launch puppeteer in Docker environment with
pipe: trueand a missing OS runtime dependency
What is the expected result?
I was expecting to see a clean stacktrace including this debug message:
Error: Failed to launch the browser process!
/node_modules/puppeteer/.local-chromium/linux-782078/chrome-linux/chrome: error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
What happens instead?
Instead, I received a confusing stacktrace referencing the protocol, which I am not intended to interact with directly:
Error: Protocol error (Target.setDiscoverTargets): Target closed.
at /node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:71:63
at new Promise (<anonymous>)
at Connection.send (/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:70:16)
at Function.create (/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:95:26)
at ChromeLauncher.launch (/node_modules/puppeteer/lib/cjs/puppeteer/node/Launcher.js:106:56)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:21
Top Results From Across the Web
Puppeteer - Protocol error (Page.navigate): Target closed
The Target closed exception is thrown when you are trying to run a function, but the target (tab) was already closed.
Read more >(Puppeteer) Protocol error (Target.setDiscoverTargets)
The command Target.createTarget() results in an unexpected about:blank page to be returned. I'll run some more jobs to get a better overview of...
Read more >Troubleshooting - Puppeteer
If you get an error that looks like this when trying to launch Chromium: (node:15505) UnhandledPromiseRejectionWarning: Error: Failed to launch the browserΒ ...
Read more >Puppeteer documentation - DevDocs
Puppeteer Documentation. Overview. Puppeteer is a Node library which provides a high-level API to control Chromium or Chrome over the DevTools Protocol. TheΒ ......
Read more >node-puppeteer autopkgtest log - Snippets - Debian Salsa
UPower was not provided by any .service files puppeteer:protocol:SEND β» {"method":"Target.setDiscoverTargets","params":{"discover":true}Β ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I had the same issue. I fixed it by using the following to launch.
I have the same issue with the following arguments:
The strange thing is that I only have the issue when running inside a docker container on Apple Silicon. Any ideas?