loading...
Cover image for Running Puppeteer on Heroku Free Tier

Running Puppeteer on Heroku Free Tier

ziv profile image zivka ・2 min read

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:

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();
Enter fullscreen mode Exit fullscreen mode

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

Discussion

pic
Editor guide