0

I am running puppeteer with Chromium (v112) on a collection of websites. On some of the websites, i encounter the following error:

STDERR: Error: Navigation failed because browser has disconnected!
    at new LifecycleWatcher (/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.js:83:223)
    at Frame.goto (/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Frame.js:183:25)
    at CDPPage.goto (/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js:438:91)
    at /puppeteer/iframes.js:44:24

The iframe.js file with puppeteer options is:

const puppeteer = require('puppeteer');
const Xvfb = require('xvfb');
var args = process.argv; // node iframes.js site extn

(async () => {
    var xvfb = new Xvfb({
        silent: true,
        reuse: true,
        // xvfb_args: ["-screen", "0", '1280x720x24', "-ac"],
    });
    xvfb.start((err)=>{if (err) console.error(err)});

    const browser = await puppeteer.launch({ 
        headless: false,
        ignoreDefaultArgs: ["--disable-extensions","--enable-automation"],
        args: [
            "--disable-gpu",
            "--disable-dev-shm-usage",
            "--no-sandbox",
            "--disable-setuid-sandbox",
            "--no-first-run",
            "--no-zygote",
            "--single-process",
            '--disable-web-security',
            '--disable-features=IsolateOrigins,site-per-process',
            '--disable-web-security',
            '--disable-features=IsolateOrigins,site-per-process',
            // `--load-extension=/home/ritik/work/pes/extensions/privacy_extn/${args[3]}`,
            '--display='+xvfb._display
            // '--single-process',
            '--window-size=960,1080',
            '--disable-features=AudioServiceOutOfProcess'
        ],
        // executablePath: '/usr/bin/google-chrome' 
        executablePath: '/snap/bin/chromium' 
    });
    const page = await browser.newPage();
    await page.setViewport({ width: 960, height: 1080 });
    await page.waitForTimeout(2000);
    var sites = args[2].split(',');
    for (let index=0; index<sites.length; index++){
        let site = sites[index];
        try{
            await page.goto(site, { waitUntil: 'networkidle2', timeout: 60000 });
            await page.waitForTimeout(2000);
        } catch (error){
            console.error(error);
            console.log(site);
            // continue;
            break;
        }
    }

    await browser.close();
    xvfb.stop();
})();

The only relevant discussion I could find was this link but it doesn't resolve the error. Some of the sites I get the error on are: 'www.baidu.com', 'www.bilibili.com', 'www.microsoft.com', 'www.apple.com'

I was expecting the code to run normally without any error.

  • Do the sites work headfully? If so, then maybe try the ideas listed in [Why does headless need to be false for Puppeteer to work?](https://stackoverflow.com/questions/63818869/why-does-headless-need-to-be-false-for-puppeteer-to-work). `networkidle2` is a bit dangerous--if the site keeps 2 long-running connections open, you can time out. What are you trying to do on the sites? – ggorlen Apr 25 '23 at 05:01
  • Yes, they work with `headless: false`. I am visiting all the frames on the webpage to look for `adblock` text. Since the number of frames differ in headless mode, i am running in headfully with xvfb because opening 5 instances of chromium GUI just blocks my RAM. – Ritik Roongta Apr 25 '23 at 15:51

0 Answers0