Search code examples
centos7chromiumpuppeteerheadless

how tu run puppeteer chromium/chrome `headless:false` on centos 6/7 server


I am trying to get some info from a website, the data is not available at the initial load so I need it to be loaded into a browser so I can scrape it.

I am using puppeteer. when I run chromium with headless:false in my centos 7 server I get this error (chrome:5006): Gtk-WARNING **: cannot open display:.

I installed the xorg-x11-server-Xvfb and all the dependencies .

The chromium itself runs when headless:true, but the site I am trying to open gives net::ERR_CONNECTION_RESET.

How can I tell the chromium to use the Xvfb server?? Is it even possible?

My code :

    const browser = await puppeteer.launch({ headless: false, args: ['--no-sandbox'] });
    const page    = await browser.newPage();
    await page.goto('https://targetdomain/', { waitUntil: 'networkidle2' });

Solution

  • Seems there was a simpler solution to my problem.

    Found the solution here : https://github.com/GoogleChrome/puppeteer/issues/1477

    await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3419.0 Safari/537.36');