thomasdondorf / puppeteer-cluster

Puppeteer Pool, run a cluster of instances in parallel
MIT License
3.2k stars 307 forks source link

UnhandledPromiseRejectionWarning: Error: Unable to get browser page #323

Open gyloh9210 opened 4 years ago

gyloh9210 commented 4 years ago

Hi i am unable to run my source code in ubuntu 20.04. Here is my source code.

const appRoot = require('app-root-path');
require('dotenv').config({ path: appRoot + "/.env"})
const { Cluster } = require("puppeteer-cluster"); `

(async() => {
    const cluster = await Cluster.launch({
        concurrency: Cluster.CONCURRENCY_BROWSER,
        maxConcurrency: 3,
        workerCreationDelay: 200,
        puppeteerOptions: {
            headless: true,
            executablePath: process.env.PUPPETEER_EXE,
            args: [
                '--no-sandbox',
                '--disable-setuid-sandbox',
                '--disable-dev-shm-usage',
                '--disable-accelerated-2d-canvas',
                '--no-first-run',
                '--no-zygote',
                '--single-process', // <- this one doesn't works in Windows
                '--disable-gpu'
            ]
        },
    });

    const extractTitle = async ({ page, data: url }) => {
        await page.goto(url);
        const pageTitle = await page.evaluate(() => document.title);
        console.log(`Page title is ${pageTitle}`);
    };

    cluster.queue("https://www.mudah.my/Sagu+gula+melaka-82605319.htm", extractTitle);

    await cluster.idle();
    await cluster.close();
})();

And I got these errors. (node:63559) UnhandledPromiseRejectionWarning: Error: Unable to get browser page at Worker.<anonymous> (/var/www/web-scrapper/node_modules/puppeteer-cluster/dist/Worker.js:44:31) at Generator.next (<anonymous>) at fulfilled (/var/www/web-scrapper/node_modules/puppeteer-cluster/dist/Worker.js:5:58) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:63559) 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:63559) [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.

Please help.

thorn0 commented 4 years ago

Sometimes I get a similar error, which I can't reproduce. It's caught via process.on('unhandledRejection', ...), but after it happens, the cluster seems to stop working (looks like cluster.execute returns promises that stay pending).

Unhandled Rejection at: Promise Promise {
<rejected> TimeoutError: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r768783 is guaranteed to work.
at Timeout.onTimeout ([...]\node_modules\puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:204:20)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
}
eliseumds commented 3 years ago

I see the same error when using --single-process on MacOS 10.15.7 (Catalina) on a MBP 16" (Intel). It's random.