javascriptnode.jspuppeteerpuppeteer-cluster

Puppeteer cluster example throwing Error: Unable to get browser page


I'm using this example in the puppeteer-cluster docs

I am running this on node v10.15.3 I have attempted passing the headless property and slowMo to puppeteer options.

I would expect the code to log out and create a Screenshot of the page however, what happens is several chrome instances boot up which do not load any of the pages then the console hangs and errors with:

(node:30826) UnhandledPromiseRejectionWarning: Error: Unable to get browser page
    at Worker.<anonymous> (/Users/Starlord/Code/oppose/node_modules/puppeteer-cluster/dist/Worker.js:43:31)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/Starlord/Code/oppose/node_modules/puppeteer-cluster/dist/Worker.js:4:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:30826) 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(). (rejection id: 21)
(node:30826) [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.
(node:30826) UnhandledPromiseRejectionWarning: Error: Unable to get browser page
    at Worker.<anonymous> (/Users/Starlord/Code/oppose/node_modules/puppeteer-cluster/dist/Worker.js:43:31)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/Starlord/Code/oppose/node_modules/puppeteer-cluster/dist/Worker.js:4:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:30826) 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(). (rejection id: 22)
^Cinternal/process/per_thread.js:198
      throw errnoException(err, 'kill');
      ^

Error: kill ESRCH
    at process.kill (internal/process/per_thread.js:198:13)
    at process.killChrome (/Users/Starlord/Code/oppose/node_modules/puppeteer/lib/Launcher.js:110:17)
    at process.emit (events.js:189:13)

Solution

  • This error happens when the library is unable to create a new browser page. The error is thrown here after several tries of opening a new context/page/browser (depending on your settings).

    Debugging log

    To get more information on what causes the error, you can check the debugging log. This starts the application in debugging mode and will log more information. To enter debugging mode you need to start the application with the environment variable DEBUG='puppeteer-cluster:*':

    # Linux
    DEBUG='puppeteer-cluster:*' node application.js
    # Windows Powershell
    $env:DEBUG='puppeteer-cluster:*';node application.js
    

    Problem

    In your case the debug logs shows (copied from your comment above):

    puppeteer-cluster: Worker Error getting browser page (try: 9), message: this.browser.createIncognitoBrowserContext is not a function +660ms

    This means, there is no createIncognitoBrowserContext that the library can use to create a new context. As you already confirmed, this is the case, because you are using an old puppeteer installation. To use the setting { concurrency: Cluster.CONCURRENCY_CONTEXT }, you have to be using at least version 1.5.0 as that was when contexts were introduced.

    Fix

    To fix the problem, update your puppeteer installation:

    npm install puppeteer@latest