2

I ran into the following problem.

Here's the error message:

 Error: Navigation failed because browser has disconnected!
    at /Users/me/myproject/node_modules/puppeteer/lib/cjs/puppeteer/common/LifecycleWatcher.js:51:147
    at /Users/me/myproject/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:47:62
    at Array.map (<anonymous>)
    at Object.emit (/Users/me/myproject/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:47:43)
    at CDPSession.emit (/Users/me/myproject/node_modules/puppeteer/lib/cjs/puppeteer/common/EventEmitter.js:72:22)
    at CDPSession._onClosed (/Users/me/myproject/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:247:14)
    at Connection._onMessage (/Users/me/myproject/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:94:25)
    at WebSocket.<anonymous> (/Users/me/myproject/node_modules/puppeteer/lib/cjs/puppeteer/common/WebSocketTransport.js:13:32)
    at WebSocket.onMessage (/Users/me/myproject/node_modules/ws/lib/event-target.js:125:16)
    at WebSocket.emit (events.js:315:20)

And here's the documentation I am reading:

timeout <number> Specify a timeout for all tasks. Defaults to 30000 (30 seconds).
[src](https://github.com/thomasdondorf/puppeteer-cluster#clusterlaunchoptions)

Each of my tasks were ~34 seconds, so most of the time it would fail (timeout after 30s) but occasionally it would succeed.

Other GitHub/Stack Overflow answers have also mentioned that a missing await in your code could also cause the same error message.

halfer
  • 19,824
  • 17
  • 99
  • 186
David McNamee
  • 403
  • 4
  • 10

1 Answers1

1

Here's my solution,

Before:

const cluster = await Cluster.launch({
    concurrency: Cluster.CONCURRENCY_PAGE,
    maxConcurrency: 2,
    puppeteerOptions: { headless: false }
  });

After:

const cluster = await Cluster.launch({
    concurrency: Cluster.CONCURRENCY_PAGE,
    maxConcurrency: 2,
    timeout: 150 * 1000, // 2.5 min timeout per task
    puppeteerOptions: { headless: false }
  });

Just leaving it here for reference incase anyone else has this problem.

David McNamee
  • 403
  • 4
  • 10