📜  heroku puppeteer buildpack (1)

📅  最后修改于: 2023-12-03 14:41:43.053000             🧑  作者: Mango

Heroku Puppeteer Buildpack

Heroku Puppeteer Buildpack Logo

If you're building a node.js app that requires web scraping or automation, you're probably familiar with Puppeteer. Puppeteer is a powerful, headless browser API that can do anything a regular browser can do, including generating screenshots, PDFs, and even scraping data from websites.

However, Puppeteer requires a Chromium browser to be installed on the machine running the code. This means that if you want to run Puppeteer on Heroku or another cloud platform, you'll need to manually install Chromium or use a third-party buildpack.

That's where the Heroku Puppeteer Buildpack comes in. This buildpack automates the process of installing Chromium and configuring Puppeteer on your Heroku dyno.

How to Use

To use the Heroku Puppeteer Buildpack, you'll need to add it to your app as a buildpack. You can do this using the Heroku CLI or the Heroku Dashboard.

Heroku CLI
  1. Navigate to your app's directory in the Terminal
  2. Run heroku buildpacks:add jontewks/puppeteer
  3. Push your changes to Heroku using Git
Heroku Dashboard
  1. Open your app in the Heroku Dashboard
  2. Click on the "Settings" tab
  3. Scroll down to the "Buildpacks" section and click "Add buildpack"
  4. Enter jontewks/puppeteer in the search bar and select it
  5. Click "Save changes"

That's it! The next time you deploy your app, the Heroku Puppeteer Buildpack will automatically install Chromium and configure Puppeteer.

Configuration

By default, the Heroku Puppeteer Buildpack installs the latest version of Chromium and Puppeteer. However, you can configure the buildpack to use a specific version if necessary.

To do this, you'll need to set the PUPPETEER_VERSION and/or CHROMIUM_VERSION environment variables in your Heroku app. For example, to use Puppeteer version 5.5.0 and Chromium version 93.0.4577.82, you would set the following environment variables:

heroku config:set PUPPETEER_VERSION=5.5.0
heroku config:set CHROMIUM_VERSION=93.0.4577.82
Conclusion

The Heroku Puppeteer Buildpack makes it easy to use Puppeteer on Heroku and other cloud platforms. With just a few simple steps, you can automate web scraping, generate screenshots and PDFs, and more. Give it a try and let us know what you think!