Heroku is my favorite cloud platform to host my apps.
During Covid-19 I created myself some cool automation(I'm working on another post on it) and was looking for a place to run it for free.
For example, notify me when my restaurant is open in Wolt.
So my requirement was:
- Running puppeteer
- Easy to create a scheduled task
- Easy to deploy
- Free
I have experience with Heroku, so it was my first choice.
The free tier is giving you more than 500h per month.
Easy to sync with my GitHub repo already integrated into Heroku.
Scheduled task - There is a simple addon named - Heroku Scheduler which allows you to run commands in scheduled time. Super easy to use, and doesn't require any additional runtime of the instance itself(so we're still in the free tier)
The biggest problem for me was to find the right configuration to run a puppeteer in Heroku.
BTW, if you don't know puppeteer yet. Puppeteer is a Node library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol.
I was looking at how to run it, but couldn't find a configuration that worked for me...
So, this is my configuration(it's not necessarily ideal, but it works)
Buildpacks:
- https://github.com/jontewks/puppeteer-heroku-buildpack
- heroku/nodejs
JS code
const chromeOptions = {
headless: true,
defaultViewport: null,
args: [
"--incognito",
"--no-sandbox",
"--single-process",
"--no-zygote"
],
};
const browser = await puppeteer.launch(chromeOptions);
const page = await browser.newPage();
Use the following flags when you launch puppeteer
- "--incognito",
- "--no-sandbox",
- "--single-process",
- "--no-zygote"
Feel free to read more about it...
I hope it solved your problem:)
Good luck
Top comments (3)
any reason why you came up with those launch options? Can't find documentation about those.
So regarding
headless: true
that's because it's running on a Linux without GUI,defaultViewport: null
is related to the width and height, it's not mandatory--incognito
was for my use(in order to start without any cookies and etc.and regarding the last three args
I'm not really sure, but that worked for me after a couple of tries...
Not sure what is running in Heroku that made this configuration worked for me:)
--no-sandbox
i believe it means all page related process in main thread.peter.sh/experiments/chromium-comm...
--single-process
means no parallelism for plugins and graphics.peter.sh/experiments/chromium-comm...
--no-zygote
no "main forker".peter.sh/experiments/chromium-comm...
That all together enforces only one chromium process.