Run puppeteer-core on Heroku (Docker edition)

There are some samples that use puppeteer-heroku-buildpack, but there aren't many examples that use Docker, so make a note.

Run a Docker container on Heroku

Almost anything works with an HTTP server that just runs one container. All you have to do is start the HTTP server on the port number specified by $ PORT.

The details are written around.

First, try deploying something that just uses Python's http.server.


FROM python:3.8-alpine


    web: Dockerfile
  web: python -m http.server $PORT

Only the first time you need to set up the app

$ heroku create
$ heroku stack:set container


Just git push. It's really easy.

$ git push heroku master


Create and deploy a Docker image with puppeteer-core and Google Chrome

puppeteer has the ability to download Chromium, but it's best to use Google Chrome (Stable) anyway. (prejudice)

So, try deploying puppeteer-core, which does not have Chromium download function, and Google Chrome in one Docker image.


# ref:
FROM node:12-slim

# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update \
    && apt-get install -y wget gnupg \
    && wget -q -O - | apt-key add - \
    && sh -c 'echo "deb [arch=amd64] stable main" >> /etc/apt/sources.list.d/google.list' \
    && apt-get update \
    && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
    --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/google-chrome-stable

RUN mkdir /app
COPY package.json /app/package.json
RUN npm install
COPY index.js /app/index.js
CMD npm start

For index.js, just create an HTTP server appropriately, search hogehoge on Google when parameters like ? Q = hogehoge are specified, and display the text of the search result screen. With things.


const http = require("http");
const url = require("url");
const puppeteer = require("puppeteer-core");

//create a server object:
  .createServer((req, res) => {
    const requestUrl = url.parse(req.url, true);
    let keyword = requestUrl.query["q"];
    if (!keyword) {
      res.write("request with ?q=xxxx");
    } else {
          args: ["--no-sandbox", "--disable-setuid-sandbox"],
          executablePath: process.env.PUPPETEER_EXECUTABLE_PATH,
        .then(async (browser) => {
          const page = (await browser.pages())[0] || (await browser.newPage());

          //Automatic operation from here
          await page.goto("");
          await page.type("input[name='q']", requestUrl.query["q"]);
          await Promise.all([

          let text = await page.evaluate(() => document.body.textContent);
          await page.close();


package.json is just like npm init --yes`` npm install puppeteer-core without any twist.


  "name": "heroku-docker-playground",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  "repository": {
    "type": "git",
    "url": "git+"
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": ""
  "homepage": "",
  "dependencies": {
    "puppeteer-core": "^5.2.1"


    web: Dockerfile
  web: npm start

It takes a long time because docker build is done at the time of deployment, but if you wait, the HTTP server will start naturally.

With this kind of feeling, if the Google case result text appears in a row, it is OK to communicate. image.png

Maybe playwright will work too

If puppeteer-core works, playwright-core will work as well.

For playwright, the Dockerfile is published by Microsoft, so you can refer to it.

It's a complete digression, but since playwright isn't intuitively available on Azure Functions at this point, Heroku is highly recommended for anyone who just wants to get playwright running in response to an HTTP request!

Recommended Posts

Run puppeteer-core on Heroku (Docker edition)
Run phpunit on Docker
Run VS Code on Docker
Run openvpn on Docker (windows)
Run SSE (Server-Sent-Event) samples on docker
Steps to run docker on Mac
Run React on a Docker container
Run the AWS CLI on Docker
How to run JavaFX on Docker
Run GUI application on Docker container
Deploy Flask's Docker image on Heroku
Run PureScript on a Docker container
Deploy Rails on Docker to heroku
Run NordVPN on Docker (Windows) Ubuntu container
Run Embulk on Docker to convert files
Until you run apache on ubuntu on docker
Run Ubuntu + ROS with Docker on Mac
Liberty on Docker
heroku: docker: deploy
Redmine on Docker
Run GUI application on Docker container (Japanese input)
Run JSP Hello World with Tomcat on Docker
Run an application made with Go on Heroku
Run Docker environment Rails MySQL on Heroku. devise and hiding the twitter API
Docker installation on CentOS 6
python notes on docker
Test run on rails
Introducing Bugsnag on Heroku
Run Pico with docker
Run PostgreSQL on Java
Install Docker on Manjaro
Run the Android emulator on Docker using Android Emulator Container Scripts
Yay! I'm on Heroku!
Run Payara with Docker
Use Corretto 11 on Heroku
Run Processing on Ant
Run tiscamera on Ubuntu 18.04
M.S. docker on Windows
Docker installation on WSL2
Error resolution on Heroku
Until you run Quarkus and run docker image on Amazon ECS
Run lilypond on Docker on macOS Catalina to create sheet music
What is docker run -it?
Install Docker on Raspberry Pi
Install Docker on Windows 10 PRO
[Docker] ECS automatic deployment --Docker edition-
Introduce Rails/Basic authentication on Heroku.
Try Docker on Windows 10 Home
Oracle Java 8 on Docker Ubuntu
How to deploy on heroku
Run chromium-mir-kiosk on Ubuntu Core
Run Rails whenever with docker
Decomposing the Docker run command. .. ..
Run java applet on ubuntu
Fastest Docker introduction (Windows 10 edition)
Hosted Apicurio Studio on Docker
Install docker on AWS EC2
Run Eclipse CDT on Ubuntu
Run mruby / c on PSoC 5
Use PG Backups on Heroku
Until you put Ubuntu 20 on Windows 10 Home and WSL2 and run Docker