How do I run headful puppeteer in a server?

Viewed 1112

I want to run puppeteer with headless = false in my Digital Ocean server with Ubuntu.

When I go into the Digital Ocean console on digitalocean.com it runs properly (I have ubuntu-desktop as a GUI, chromium actually pops up and starts running in GUI).

However, when I ssh into the console and try to run the same program the program works until it hits the puppeteer script and I get the following error messages from puppeteer:

Error: Failed to launch the browser process!

Unable to open X display.

NaCl helper process running without a sandbox!

Most likely you need to configure your SUID sandbox correctly

Here's what I've got in my puppeteer config:

import puppeteer from "puppeteer";

export const getBrowser = async () => {
  const browser = await puppeteer.launch({
    headless: false,
    args: [
      "--no-sandbox",
      "--disable-setuid-sandbox",
      "--window-size=1600,1200",
    ],
    defaultViewport: null,
  });
  return browser;
};

I've played with removing the --no-sandbox and --disable-setuid-sandbox but that didn't solve it.

If you're asking yourself "why would they do that?" - it's mainly because I've found the sites I am mining tend to notice less when it's in a headful state (I suppose I could move back to puppeteer-stealth).

1 Answers

I had the same question. I half-solved it. I enabled X11 forwarding in my terminal and now everything launches. However, I still am struggling with it, because I wanted to run headful scripts automatically on my server without me interfering, and now I'm thinking the ways I could accomplish that.

Related