Puppeteer for Apple M1

Duy KN
2 min readOct 24, 2021

Here and there, I’ve found some pieces of tips to build and run the Puppeteer on Apple M1. I see that the problem may be varying on each device, so this note is a kinda thing that works for me, hope that it works for you too.

The symptom is

The chromium binary is not available for arm64:
If you are on Ubuntu, you can install with:

The solution

Firstly, make sure 3 things:

  • XCode has already been installed completely and works properly on your device.
  • Then, reach brew and follow up the instruction to install brew on your system. https://brew.sh/
  • The version of the puppeteer should be 10.4.0 or later

P/S I assume that Rosetta has already installed while you installing Docker

You must install Rosetta 2 as some binaries are still Darwin/AMD64. To install Rosetta 2 manually from the command line, run the following command:
softwareupdate --install-rosetta

1. Install chromium

> brew install chromium

2. Check if chromium works

> which chromium
/opt/homebrew/bin/chromium
> /opt/homebrew/bin/chromium

If you see kind of this error:

try this command to fix:

> xattr -cr /Applications/Chromium.app

If luckier, this screen appears:

Go to your System Preferences > Security & Privacy > General screen, and select Open Anyway.

3. Skip Chromium installs

Enter the following lines to ~/.zshrc (nano ~/.zshrc)

export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
export PUPPETEER_EXECUTABLE_PATH=`which chromium`

and, reload ~/.zshrc

> source ~/.zshrc

4. Remove all cache and install again

> rm -rf node_modules
> rm -rf package-lock.json
> npm install

P/S: You can occur the same issue with Docker. Add the following line in Dockerfile

RUN apt-get install chromium -y
RUN ln -s /usr/bin/chromium /usr/bin/chromium-browserENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

The full Docker script

FROM node:12-stretchRUN apt-get update && \
apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget dumb-init
RUN apt-get install chromium -y
RUN ln -s /usr/bin/chromium /usr/bin/chromium-browser
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
RUN npm install -g nodemon
RUN npm install -g pm2
RUN npm install -g puppeteer --unsafe-perm
WORKDIR /home/node/app
COPY --chown=node:node package.json ./package.json
RUN yarn install
COPY --chown=node:node *.js ./
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
USER node
CMD [ "pm2-runtime", "start", "ecosystem.config.js" ]

Good luck!

--

--