'Running Puppeteer with headless: false & Firebase Functions
I'm trying to use Puppeteer + Firebase Functions while using the headless: false option
await puppeteer.launch({
headless: false
});
It works well locally. I use the headless: false so it won't trigger a bot check, which work well.
When I deploy it to Firebase Functions it doesn't seem to be able to launch a browser:
Error: Failed to launch the browser process!
[15:32:0209/162803.759118:ERROR:file_path_watcher_linux.cc(78)] Failed to read /proc/sys/fs/inotify/max_user_watches
[15:15:0209/162804.834741:ERROR:ozone_platform_x11.cc(234)] Missing X server or $DISPLAY
[15:15:0209/162804.834794:ERROR:env.cc(225)] The platform failed to initialize. Exiting.
Is there some sort of a solution to run it as a Firebase Function?
Solution 1:[1]
I’ll start with the cases that combined Cloud functions and Puppeteer. Here is an old question that discusses the same log error. I think this is the first place to look for a solution, as it provides links to a couple of Github Issues reporting similar error logs. In this other Github issue, a user recommended code to start Puppeteer in Cloud functions. This example can help you as well.
I’ll leave these two guides that can walk you through. This old medium article and this more updated version from logrocket.
Other question has several workarounds; unfortunately, none of them include Cloud Functions, just in case this is caused purely by Puppeteer. And here is how to run Headful Mode.
However, if you want to avoid being detected by the bot, there is also a discussion about this that could give you some hints.
There is no exact solution for this, as it seems there are several causes and workarounds. I would advise you to open a new question once you have tried some alternatives already provided by the community, and see if there's a more specific solution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alex |
