Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems running chromote in Google Cloud Run #180

Open
aaelony-fb opened this issue Sep 19, 2024 · 0 comments
Open

Problems running chromote in Google Cloud Run #180

aaelony-fb opened this issue Sep 19, 2024 · 0 comments

Comments

@aaelony-fb
Copy link

Thanks for writing an excellent library!

  • I am using chromote to generate a pdf file from HTML/CSS.
  • It works great on macosx!
  • but... triggers errors and fails when run in Google Cloud Run (via Dockerfile containing Chrome and R code and Google Cloud Build)

Chrome is installed via Dockerfile based on rocker/r-ver:4.3.2.

Relevant parts of the Dockerfile for the DISPLAY env variable setting:

ENV DEBIAN_FRONTEND="noninteractive" \
    LANG=en_US.UTF-8 \
    LANGUAGE=en_US.UTF-8 \
    LC_ALL=C.UTF-8 \
    DISPLAY=:0

and chrome installation:

RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
    apt-get update && apt-get install -y ./google-chrome-stable_current_amd64.deb && \
    rm google-chrome-stable_current_amd64.deb && \
    apt-get install -f -y


## Chromium dependencies
RUN apt-get update && apt-get install -y \
    libcurl4-openssl-dev \
    libssl-dev \
    libxml2-dev \
    libxt-dev \
    libfontconfig1-dev \
    xvfb \
    wget \
    curl \
    chromium-driver

# Set the environment variables for Chromium
ENV CHROME_BIN=/usr/bin/chromium-browser
ENV CHROME_ARGS="--no-sandbox --disable-gpu --headless"

And chromote is used as follows from the R session:

library(chromote)
packageVersion("chromote")
[1] ‘0.2.0.9000’
b <- ChromoteSession$new()
b$Page$navigate(url)
b$Page$loadEventFired()
b$screenshot_pdf(
 filename = "test.pdf",
 pagesize = "Letter",
 margins = c(0.1, 0.1, 0.1, 0.1),
 units = "cm",
 landscape = TRUE,
 wait_ = TRUE
)
b$close()

The errors in Google cloud are typically lines stating:

Error in with_random_port()
! Cannot find an available port. Please try again.
Caused by error in startup()
Failed to start chrome. Error
Old Headless mode will be removed from the Chrome binary soon. 
Please use the new Headless mode (https://developer.chrome.com/docs/chromium/new-headless) 
or the chrome-headless-shell which is a standalone implementation of the old Headless mode (https://developer.chrome.com/blog/chrome-headless-shell).

As mentioned previously, this runs correctly from Macosx generally without issue (if the HTML file is too large it may a timeout and fail but works great for HTML files of normal size).

Any insight into how to make this work in Google Cloud Run per the errors above would be keenly appreciated! thank-you in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant