Lim Kim
Lim Kim

Reputation: 21

Run and install X server to make puppeteer works

on my linux server I running my nodejs project which should crawl single page app by puppeteer npm module.

Here is an example of the code I use:

const puppeteer = require('puppeteer');

(async () => {

  try {

    const browser = await puppeteer.launch();

    const page = await browser.newPage();

    await page.goto('https://bvopen.abrickis.me/#/standings');

    await page.waitForSelector('.category', { timeout: 1000 });
    const body = await page.evaluate(() => {

      return document.querySelector('body').innerHTML;

    });

    console.log(body);
    await browser.close();

  } catch (error) {

    console.log(error);

  }

})();

But I've got the next error:

0|www  | Error: Failed to launch the browser process!
0|www  | [5642:5642:0511/154701.856738:ERROR:browser_main_loop.cc(1485)] Unable to open X display.
0|www  | [0511/154701.863486:ERROR:nacl_helper_linux.cc(308)] NaCl helper process running without a sandbox!
0|www  | Most likely you need to configure your SUID sandbox correctly
0|www  | TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md

I searched a lot how to install X server and tried a lot of things like sudo apt-get install xorg openbox but it doesn't helps.

Upvotes: 1

Views: 4309

Answers (1)

tchibu
tchibu

Reputation: 56

Looks like puppeteer wants to start the browser in a non-headless mode but as you don't have xorg installed it failed. But I would say that's not what you want when it's running on a server anyways. So there is no need to install xorg or anything.

Maybe try to launch the puppeteer browser with following options:

await puppeteer.launch({
  headless: true,
  args: [
    "--disable-gpu",
    "--disable-dev-shm-usage",
    "--no-sandbox",
    "--disable-setuid-sandbox"
]
});

Upvotes: 2

Related Questions