Home > other >  How to run nodejs script that uses Puppeteer on Heroku
How to run nodejs script that uses Puppeteer on Heroku

Time:06-02

I have created a NodeJs script that uses Puppeteer to grab some data from a website and put it on a json file.

Here is my Dyno:

enter image description here

If I enter the heroku bash (heroku run bash -a my-app) and I run the script (npm run start) it works like a charm.

Instead, if I launch the script clicking on "Open app" button I get a page with the following error:

enter image description here

Having a look at logs I see this:

at=error code=H10 desc="App crashed" method=GET path="/" host=my-app.herokuapp.com request_id=653dbf69-d35c-4017-bxxf-cc0e1a5xxxce fwd="37.159.47.101" dyno= connect= service= status=503 bytes= protocol=https
2022-06-01T07:24:50.316302 00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=my-app.herokuapp.com request_id=b49ac035-axxx-4372-a59e-118bcxxx6a3b fwd="37.159.47.101" dyno= connect= service= status=503 bytes= protocol=https

I have spent a lot of time searching for H10 error and I have tried every solution I encountered, none worked.

The point is: what is the right way to launch a NodeJs script since I'm using Puppeteer and then I have no web page to show? If I use the bash when I close it the script is killed as well.

CodePudding user response:

Do you installed the puppeter webpack that recomends heroku? other solution that worked for me is to use "chrome-aws-lambda" library that integrates puppeteer and work in hostings like vercel or heroku

example of the library

import chromium from "chrome-aws-lambda";
const browser = chromium.puppeteer."any puppeteer function"

i hope this help you.

CodePudding user response:

I finally figure out how to run a script that is not a web app. I have changed "web" to "worker" in the Procfile:

worker: npm start

and then turn off the web dynos and turn on the fresh new worker:

enter image description here

(You can reach the same with Heroku CLI: heroku scale web=0 worker=1)

Source of solution.

  • Related