Puppeteer browser connection timeout for chrome
Tags: programming, beginners, node, docker
Published: 2023-01-17 11:53:37

I was trying to take screenshots of a webpage using puppeteer. The screenshots flow works fine when the app was ran locally, but fails with the following error when I try to dockerize my app.

Unable to launch browser, error message: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r1069273 is guaranteed to work.

Here is how I am downloading and installing chrome & chrome driver in Dockerfile:

`RUN wget -O ./google-chrome-x64.zip "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1036826%2Fchrome-linux.zip?generation=1660863194027156&alt=media" \
  && unzip google-chrome-x64.zip -d /usr/local \
  && chmod 0755 /usr/local/chrome-linux/chrome \
  && rm google-chrome-x64.zip
# mnatching chromedriver
RUN wget -O chromedriver-x64.zip "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1036826%2Fchromedriver_linux64.zip?generation=1660863199489297&alt=media" \
    && unzip chromedriver-x64.zip -d /usr/local \
    && chmod 0755 /usr/local/chromedriver_linux64/chromedriver \
    && rm chromedriver-x64.zip

RUN dnf install -y \
    nss \
    alsa-lib atk at-spi2-atk cups-libs gtk3 libdrm\
    libXcomposite libXcursor libXdamage libXext libXi libXrandr libXScrnSaver libXtst \
    mesa-libgbm pango \
    xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-fonts-cyrillic \
    xorg-x11-fonts-misc xorg-x11-fonts-Type1 xorg-x11-utils \
    && update-crypto-policies --set LEGACY
ENV PATH="/usr/local/chrome-linux:${PATH}"`

And this is how puppeteer is instantiated:

`const cluster = await Cluster.launch({
            concurrency: Cluster.CONCURRENCY_CONTEXT,
            maxConcurrency: 3,
            puppeteer,
            puppeteerOptions: {
                executablePath: config.chrome.path,
                headless: true,
                args:[
                    '--no-sandbox',
                    '--disable-dev-shm-usage',
                    '--disable-gpu',
                    '--disable-default-apps',
                    '--disable-extensions',
                    '--disable-background-networking',
                    '--disable-setuid-sandbox',
                ]
            },
            retryLimit: 1,
            retryDelay: 30000,
            timeout: 160000
        });`

From the error message, it's quite evident that it's asking me to download the latest version or chrome and probably chrome driver. But since I am very new to this space, and not sure how to get the latest version of chrome & compatible chrome driver while using https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/... url. And yes, we inherited the code, so have pretty limited knowledge about it, and the maintainer no longer works for our org. Can someone please help us finding out the replacement urls for the below urls, so that we can download the chrome and chrome driver, while everything else in the docker file can stay the same?

Current chrome download url: https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1036826%2Fchrome-linux.zip?generation=1660863194027156&alt=media

1. Replacement url for downloading the latest version -> ?

Current chrome driver download url: https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1036826%2Fchromedriver_linux64.zip?generation=1660863199489297&alt=media

2. Replacement url for downloading the latest version -> ?

node version: v14.21.1 puppeteer and puppeteer-core versions: 19.5.2 puppeteer-cluster version: 0.23.0