Score:1

Unable to launch the Chromium browser via Puppeteer on Ubuntu 22.04 after a reboot (unless ssh'ing in first - then it works)

np flag

please help me out here.

I have a fresh ubuntu server 22.04 setup with node (v18.12.1) / express, and PM2 as the process manager.

I have Puppeteer installed and the Chromium browser, which is working fine. I use it to generate high quality PNG files for personal use.

The problem is, when I reboot the server, PM2 successfully starts the node app, so my website is accessible. I can successfully ping it and get a response, so the web app is working fine after a reboot.

The problem is that (after a reboot) Puppeteer is unable to launch the browser if I send a request to my web app and say, hey, give me a screenshot of this. I get the following error:

Error: Failed to launch the browser process!
/usr/bin/chromium-browser: 12: xdg-settings: not found
2022/12/08 00:36:47.167545 cmd_run.go:1055: WARNING: cannot start document portal: dial unix 
/run/user/1001/bus: connect: no such file or directory
/system.slice/pm2-sammy.service is not a snap cgroup

Now, say I reboot the server, and ssh into it as the user sammy (which everything is installed and should be running as - pm2 startup saved in user /home.sammy etc.) and if I ask for the same screenshot, now everything is working as expected.

It looks like merely ssh'ing into the server triggers something then everything is working fine. I can't figure out what I'm missing. By the way, I've got this working fine on a local Vagrant machine.

I think on reboot there is no session running under the user sammy hence it works after ssh'ing in because a session is started?

Score:4
np flag

Ok guys, I've found the solution. I'll post it as an answer in case it helps someone out there.

I had to enable user lingering.

loginctl enable-linger sammy

A quick explanation from Google:

What does enable linger do?
Enable/disable user lingering for one or more users. If enabled for a specific 
user, a user manager is spawned for the user at boot and kept around after 
logouts. This allows users who are not logged in to run long-running services.

I am now able launch the chromium browser via puppeteer straight after a reboot of the server without the need of ssh'ing in first.

msonowal avatar
in flag
awesome you saved my day
threehappypenguins avatar
tr flag
Yessssss. Thank you! I was banging my head trying to figure out why I couldn't get Puppeteer to run on its own (was using pm2), and user lingering was it. I tried specifying the browser path, no sandbox, you name it. User lingering was the problem exactly.
Caedmon avatar
lt flag
Amazing - this did the trick for me after a morning of fruitless experimenting! I found puppeteer was failing if I wasn't logged in via SSH, unless I'd started PM2 myself and not automatically on reboot.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.