DEV Community

Using Headless Chrome with Cloud Run

Dustin Ingram on October 22, 2019

I often see folks trying to use headless Chrome with services like Google Cloud Functions. The phrase "Headless Chrome" might sound very spooky, bu...
Collapse
 
kev26 profile image
kev26

If my local code from windows machine (C:\Users\KEV\pathmycode), how will i set path for this case ? I tried on linux is OK, but with windows, i can't to set them ! I'm newbie and Thanks for your help !!!

Collapse
 
johannesoak profile image
Johannes Eklund

I ran into issues when deploying it to Cloud Run. The fix for me was too add that "wget" should be installed otherwise chrome wasn't able to be downloaded.

So this was the whole line I ran in the Docker file
RUN apt-get install -y wget gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils

Collapse
 
shreyasashtamkar profile image
Shreyas Ashtamkar

If you are using anything after python 3.7 you would face that issue, since it uses Debian Bullseye from when that package is unavailable.

try this -
FROM python: 3.8-buster

worked for me.

Collapse
 
alex512byte profile image
Alex512-byte

I am getting the following error when I try to implement this, is anyone else?

Update failed with error code BUILD_USER_ERROR
unable to stream build output: The command '/bin/sh -c apt-get install -y wget gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils' returned a non-zero code: 100. Please fix the Dockerfile and try again..
Exited with code 1.

Collapse
 
derek_p_baker profile image
Derek Baker

If anyone is interesting in an updated version of this content that outlines some pitfalls involved when running locally (outside of Docker), I threw this repo on Github: github.com/derek-baker/scraping-se...

Collapse
 
matti__4247fc773325 profile image
Matti Jensen

Local docker - I tried python 3.8-buster which solves the issue that Alex512* has.
But running the container still fails;

[2022-01-10 15:59:26 +0000] [1] [INFO] Using worker: threads
/usr/local/lib/python3.8/os.py:1023: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
return io.open(fd, *args, **kwargs)
[2022-01-10 15:59:26 +0000] [9] [INFO] Booting worker with pid: 9
[2022-01-10 15:59:27 +0000] [9] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()

Justin, would you be able to update/fix the guide - thanks!

Collapse
 
ahmetb profile image
Ahmet Alp Balkan • Edited

Nice post, thanks! When I deployed this by copy-pasting, I got HTTP 500. Logs show "Memory limit of 256M exceeded with 282M used. Consider increasing the memory limit." You might want to add this argument (and maybe make the URL configurable with ?url=).

Collapse
 
chongleichen profile image
chongleichen

This comment is for anyone finding that chrome keeps crashing inside their container, it could be due to the machine you're running on. For me it was an M1 mac. I found later that it works fine on Cloud Run itself. There may be some compatibility issues with M1 macs that I need to figure out.

Collapse
 
manishfoodtechs profile image
manish srivastava

Thanks Dustin, for this article

Collapse
 
sulun profile image
Emre

Saved my day, thanks!

Collapse
 
estbelari profile image
Esteban Beltrán

I did not know what version of chrome I have installed. It helped me install chromedriver-binary-auto. Automatically detects the required version.

pip install chromedriver-binary-auto

Thanks

Collapse
 
zhenyang0405 profile image
Zhen Yang

I'm using windows, when I build the docker file, It failed.

Unable to locate package libappindicator1

I tried online, but couldn't find any solution. Please help.
Thank you

Collapse
 
kev26 profile image
kev26

Thank you so much !!!

Collapse
 
danielsanthiago profile image
Daniel-Santhiago

Thank you Dustin!
How can I download the Google Chrome 77 with wget?

Collapse
 
jon0010 profile image
Jon Nahuel Pereyra

in my local environment it works but in cloud run the deployed version gives me a timeError waiting for selector waiting failed: 30000ms exceeded