Introduction
Puppeteer is a Node.js library which provides a high-level API to control Chromium (or Firefox) browsers over the DevTools ...
For further actions, you may consider blocking this person and/or reporting abuse
After running the code and I got into multiple errors of browser not launching caused by using wrong executablePath etc, Below code help in resolving the issue
where is that
locateChromefunction tho?npmjs.com/package/locate-chrome here
Hi there, I know it's an old post, but it's still valid. I provide a config that works for image oraclelinux based on rh.
And the lunch:
Hi there,
I used your Dockerfile content along with mine as i am trying to to generate pdf file for this service that i'm building with typescript. now everything works locally but i can't deploy it to AWS as it exceeds the lambda limit. now i am trying to dockerize it and it get's deployed but throws the following error.
here is my Dockerfile
and here is my code
Hi! Here, you're using a multi-stage build in Docker. You are taken the
node:slimimage, installing puppeteer there. But then you started a new stage withFROM public.ecr.aws/lambda/nodejs:14and you don't haveaptor Chrome neither in this image because is based on Amazon Linux and it usesyumas package manager (like RHEL).You can check some approaches like github.com/shelfio/chrome-aws-lamb... or github.com/alixaxel/chrome-aws-lambda that explains how to use pptr inside Lambdas.
Also, I found this here stackoverflow.com/a/66099373, but I didn't test it
i just tried this.
my Dockerfile
and my code
and i get this error
"Protocol error (Target.setAutoAttach): Target closed."Any solution to this? Having the exact same error.
You should install all these X Window System dependencies in your Docker image:
alsa-lib
atk
cups-libs
ipa-gothic-fonts
libXcomposite
libXcursor
libXdamage
libXext
libXi
libXrandr
libXScrnSaver
libXtst
pango
xorg-x11-fonts-100dpi
xorg-x11-fonts-75dpi
xorg-x11-fonts-cyrillic
xorg-x11-fonts-misc
xorg-x11-fonts-Type1
xorg-x11-utils
Also, would have a look in here please? I'm so stuck!
stackoverflow.com/questions/737184...
@navarroaxel - nice article - helped me even though I am using the
pythonversionThanks! It works fine for me.
Thank you for this, it got me unstuck. Do you know if installing the latest Google Chrome could lead to problems if using an older version of Puppeteer? How to avoid this?
Yep, puppeteer is tested with a specific version of Chromium, details here: pptr.dev/chromium-support.
Also in each release you can see that version: github.com/puppeteer/puppeteer/rel....
You can check the available version starting a container with:
And then these commands for
chromiumorgoogle-chrome-stable:For
node:18-slimyou'll see this output:Just look for a puppeteer version that works fine with the given Chromium version.
This saved the day! :)
Hi! I just wanted to share a new solution for this. I know it's a bit late, but maybe someone will find it useful.
Step 1:
Create a simple Express server that receives the HTML and returns the buffer.
Step 2:
Build the Docker image that uses Debian Bullseye (here puppeteer works better.) and install dependencies for chromium
Step 3:
I won’t go into detail on this part, but you’ll need to create a docker-compose.yml with a network. Then, in your backend (for example, I use NestJS), you connect to the Puppeteer service to generate the PDF.
(In my use case, I return the response as a download link to the frontend.)
Hope this helps! 🚀
I made an account just to thank You.
I have been trying to run @unlighthouse and Puppeteer in a docker for two days now, with nothing working. I installed Chrome in twenty different ways with no luck; the puppeteer couldn't spawn Chrome. Miraculously this exact snipped worked! The dopamine rush and ecstasy were something indescribable.
how ridiculously hard is it to run puppeteer on a server. my mind is bending right now.
SOLVED If you're on an M1 mac you have to add
--platform linux/amd64to your docker build command.When I run this same docker file I receive the following error:
The entire dockerfile is:
are u fixed this issue ??
For anyone having troubles here is my solution (That runs on my machine lul)
Dockerfile
script.js
Getting this error - ****
Error: Failed to launch the browser process!
[74:122:0316/214552.693705:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[0316/214552.821672:ERROR:scoped_ptrace_attach.cc(27)] ptrace: Function not implemented (38)
Assertion failed: p_rcu_reader->depth != 0 (/qemu/include/qemu/rcu.h: rcu_read_unlock: 102)
TROUBLESHOOTING: pptr.dev/troubleshooting
at ChildProcess.onClose (/work/node_modules/@puppeteer/browsers/lib/cjs/launch.js:277:24)
at ChildProcess.emit (node:events:530:35)
at ChildProcess._handle.onexit (node:internal/child_process:294:12)
{"success":false,"data":"{\"status\":\"\",\"headers\":[],\"content\":\"\",\"trace\":\"PUPPET_LOG: INPUT_JSON = {\"url\":\"example.com\",\"user_agent\"...} StartLoading > ERROR > Cannot read properties of undefined (reading 'newPage')\"}"}TypeError: Cannot read properties of undefined (reading 'close')
at closeBrowser (/work/download_page_html.js:330:24)
at killProcess (/work/download_page_html.js:345:8)
at outputResult (/work/download_page_html.js:378:3)
at /work/download_page_html.js:367:4
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
My docker file looks like - FROM --platform=linux/amd64 node:20
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV PUPPETEER_SKIP_DOWNLOAD true
RUN apt-get update && apt-get install curl gnupg -y \
&& curl --location --silent dl-ssl.google.com/linux/linux_sign... | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install google-chrome-stable -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /work
COPY package.json ./
RUN npm install
RUN npx puppeteer browsers install chrome
COPY app.js download_page_html.js crawler-browser.js start-crawler-browser.sh start-download-page-html.sh ./
EXPOSE 3000
And I am using Apple M1 laptop
good guide — the docker + puppeteer setup works but the image ends up heavier than you'd want (chromium alone is ~300MB). one approach to keep docker images lean: use a hosted screenshot API and skip the chromium dependency entirely. snapapi.pics does this — REST call, returns PNG or PDF, your container stays small
When I try to use the docker file above to build an image, I get
#5 7.862 E: Unable to locate package google-chrome-stableWorks for me using this Dockerfile gist.github.com/navarroaxel/3f4492..., I built it with
Are you using another base image instead of
FROM node:slim AS app?Wonderful, thanks!
I had to add
ENV PUPPETEER_SKIP_DOWNLOAD trueto the env variables.ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD truewasn't enough.this tutorial is great. but i have an issue, when i try to install chromium in node:18-alpine3.16, i add some command like this : RUN apk add --no-cache chromium
but it still not work, chromium not installed in container. any one has tutorials or some advice?
As you working on puppeteer, and if you suffer from zombie process then use below docker commands , it will not create zombie process
FROM node:18-slim
RUN apt-get update
RUN apt-get upgrade
RUN apt-get update && apt-get install curl gnupg -y \
&& curl --location --silent dl-ssl.google.com/linux/linux_sign... | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install google-chrome-stable -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && \
apt-get upgrade && apt-get install -y vim
ADD ./puppetron.tar /usr/share/
WORKDIR /usr/share/puppetron
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV SERVICE_PATH=/usr/share/puppetron
CMD node main.js;
And path of browser
executablePath: '/usr/bin/google-chrome',
also VERY important is to include --init when starting your container
Thank you, after so much searching I found the correct solution.
what is your solution, can you post ?
Can anyone give dockerfile to work with puppeteer under python? I can't find one working correctly anywhere.
Here is a working docker file for an arm based docker image.
thanks for updating the article. 💗