question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:21

github_iconTop GitHub Comments

10reactions
manadan999commented, Jul 14, 2021

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'
    ]
  });
6reactions
Joebayldcommented, Jan 30, 2021

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found