puppeteer: `Protocol error (Target.setDiscoverTargets): Target closed` when `puppeteer.launch` fails with `pipe: true`

Similar 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.

  1. Launch puppeteer in Docker environment with pipe: true and 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)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 15
  • Comments: 23

Most upvoted comments

I had the same issue. I fixed it by using the following to launch.

 const browser = await puppeteer.launch({
    headless: true,
    args: [
      '--no-sandbox',
      '--disable-setuid-sandbox',
      '--disable-dev-shm-usage',
      '--single-process'
    ]
  });

I have the same issue with the following arguments:

  const browser = await puppeteer.launch({
    headless: true,
    args: [
      '--no-sandbox',
    ]
  });

The strange thing is that I only have the issue when running inside a docker container on Apple Silicon. Any ideas?

I had the same issue. I fixed it by using the following to launch.

 const browser = await puppeteer.launch({
    headless: true,
    args: [
      '--no-sandbox',
      '--disable-setuid-sandbox',
      '--disable-dev-shm-usage',
      '--single-process'
    ]
  });

This worked perfectly in my Lambda Docker instance too. Thanks for the suggestion.

I had to install some more (more than explicitly required) libraries, and it worked afterwards. This list -maybe more than required- but worked https://gist.github.com/winuxue/cfef08e2f5fe9dfc16a1d67a4ad38a01#gistcomment-3832668

I have the same issue but on AWS Lambda (runtime: provided.al2) with Serverless.

I’m using:

EDIT: Well, I was able to fix my issue by switching to the runtime provided. I’m not a big fan but it’s working. 🤷‍♂️

Any update on this ??