Skip to content

Commit

Permalink
Merge pull request #10 from umihico/feature/native-chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
umihico authored Nov 9, 2021
2 parents 0283eb5 + 03f3e25 commit 2b53017
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
FROM public.ecr.aws/lambda/python:3.9 as build
RUN yum install -y unzip && \
curl -SL https://chromedriver.storage.googleapis.com/2.43/chromedriver_linux64.zip > /tmp/chromedriver.zip && \
curl -SL https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-55/stable-headless-chromium-amazonlinux-2017-03.zip > /tmp/headless-chromium.zip && \
curl -Lo "/tmp/chromedriver.zip" "https://chromedriver.storage.googleapis.com/89.0.4389.23/chromedriver_linux64.zip" && \
curl -Lo "/tmp/chrome-linux.zip" "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F843831%2Fchrome-linux.zip?alt=media" && \
unzip /tmp/chromedriver.zip -d /opt/ && \
unzip /tmp/headless-chromium.zip -d /opt/
unzip /tmp/chrome-linux.zip -d /opt/

FROM public.ecr.aws/lambda/python:3.9
RUN yum install -y https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
RUN yum install atk cups-libs gtk3 libXcomposite alsa-lib \
libXcursor libXdamage libXext libXi libXrandr libXScrnSaver \
libXtst pango at-spi2-atk libXt xorg-x11-server-Xvfb \
xorg-x11-xauth dbus-glib dbus-glib-devel -y
RUN pip install selenium
COPY --from=build /opt/headless-chromium /opt/
COPY --from=build /opt/chrome-linux /opt/chrome
COPY --from=build /opt/chromedriver /opt/
COPY test.py ./
CMD [ "test.handler" ]
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ This is minimum demo of headless chrome and selenium on container image on AWS L
This image goes with these versions.

- Python 3.9
- serverless-chrome v1.0.0-55
- chromium 69.0.3497.81 (stable channel) for amazonlinux:2017.03
- chromedriver 2.43
- selenium 3.141.0 (latest)
- chromium 89.0.4389.47
- chromedriver 89.0.4389.23
- selenium 4.0.0

### Running the demo

Expand Down
8 changes: 6 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@

def handler(event=None, context=None):
options = webdriver.ChromeOptions()
options.binary_location = "/opt/headless-chromium"
options.binary_location = '/opt/chrome/chrome'
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument("--disable-gpu")
options.add_argument("--window-size=1280x1696")
options.add_argument("--single-process")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-dev-tools")
options.add_argument("--no-zygote")
options.add_argument("--user-data-dir=/tmp/chrome-user-data")
options.add_argument("--remote-debugging-port=9222")
chrome = webdriver.Chrome("/opt/chromedriver",
options=options)
chrome.get("https://umihi.co/")
chrome.get("https://example.com/")
return chrome.find_element_by_xpath("//html").text

0 comments on commit 2b53017

Please sign in to comment.