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

Chromedriver unexpectedly exited. #161

Open
suyash-web opened this issue Mar 25, 2023 · 25 comments
Open

Chromedriver unexpectedly exited. #161

suyash-web opened this issue Mar 25, 2023 · 25 comments

Comments

@suyash-web
Copy link

Hi, thanks for creating the image. It worked for me!
It was working well until recently when I encountered the error [ERROR] WebDriverException: Message: Service /opt/chromedriver unexpectedly exited. Status code was: 127 when I ran the code on AWS lambda.
What could possibly be causing this error? If it has something to do with the chrome version then can you please help me with how to update it with the compatible version.
Thank you.

@x-N0
Copy link

x-N0 commented May 8, 2023

Make sure to add the following to the options of your Chrome driver:

from selenium import webdriver
from tempfile import mkdtemp
def my_fn():
    options = webdriver.ChromeOptions()
    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(f"--user-data-dir={mkdtemp()}")
    options.add_argument(f"--data-path={mkdtemp()}")
    options.add_argument(f"--disk-cache-dir={mkdtemp()}")
    options.add_argument("--remote-debugging-port=9222")
    chrome = webdriver.Chrome("/opt/chromedriver", options=options)

Hope it helps, @suyash-web.

@suyash-web
Copy link
Author

Thanks, @x-N0, for the comment!
It actually started working with the same code a couple of days after I opened the issue. That's strange, but it's not throwing this error anymore.
Right now, I'm struggling to include LibreOffice to this image.

@x-N0
Copy link

x-N0 commented May 16, 2023

Hey, @suyash-web, good to know you managed to solve the issue;

About your intent to include LibreOffice, doesn't that kind of software need a whole GUI framework to be installed? To me that'd seem a bit huge, what about using other terminal-based tools that usually are lighter?

Or even use some python script to decompose and recompose the files together after you do whatever you need to do with them in LibreOffice?

I hope you get your project going soon!

@suyash-web
Copy link
Author

Thanks for the response, @x-N0 ! I have considered using terminal-based alternatives like pandoc and unoconv that perform similar functions as LibreOffice, but they would eventually require LibreOffice to be installed in the system. I tried including LibreOffice to the docker image I'm using, but everything I tried didn't work 😕

About using Python scripts, I tried using modules like docx2pdf, but it requires some supporting software like LibreOffice (for linux) to be installed in the system.

I've also considered using APIs by Aspose, smallpdf, Adobe, and similar, but they're all paid. The free versions have a limit and include a watermark in the final pdf.

@notanmay
Copy link

notanmay commented Jul 26, 2023

Hello,
I'm trying to run my docker image from my mac m1 processor and I'm getting this error continuously
Can anyone please help?
This is the error I am getting:

driver = webdriver.Chrome(service=service, options=options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/lang/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 49, in __init__
    super().__init__(
  File "/var/lang/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 51, in __init__
    self.service.start()
  File "/var/lang/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 97, in start
    self.assert_process_still_running()
  File "/var/lang/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
selenium.common.exceptions.WebDriverException: Message: Service /opt/chromedriver unexpectedly exited. Status code was: 255

script.py where I'm defining driver:

options = webdriver.ChromeOptions()
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("--remote-debugging-port=9222")
service = selenium.webdriver.chrome.service.Service('/opt/chromedriver')
driver = webdriver.Chrome(service=service, options=options)

My Dockerfile:


FROM public.ecr.aws/lambda/python@sha256:10dbb67ede15b5fd516be87dd71c3f7968904b0b840235720486476b34ef9b67 as build
RUN yum install -y unzip && \
    curl -Lo "/tmp/chromedriver.zip" "https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip" && \
    curl -Lo "/tmp/chrome-linux.zip" "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1135561%2Fchrome-linux.zip?alt=media" && \
    unzip /tmp/chromedriver.zip -d /opt/ && \
    unzip /tmp/chrome-linux.zip -d /opt/

FROM public.ecr.aws/lambda/python@sha256:10dbb67ede15b5fd516be87dd71c3f7968904b0b840235720486476b34ef9b67
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==4.9.1
COPY --from=build /opt/chrome-linux /opt/chrome
COPY --from=build /opt/chromedriver /opt/

COPY script.py /var/task
COPY utils.py /var/task
COPY func.py /var/task
COPY requirements.txt /var/task

RUN pip install -r requirements.txt
CMD ["script.py"]
ENTRYPOINT [ "python" ]

@fyodor-av
Copy link

fyodor-av commented Aug 15, 2023

I'm running into the same issue as @notanmay. The images work remotely on non-apple silicon though.
The docker site has some more info about possible culprits.

@vinhliem
Copy link

vinhliem commented Aug 18, 2023

Make sure to add the following to the options of your Chrome driver:

from selenium import webdriver
from tempfile import mkdtemp
def my_fn():
    options = webdriver.ChromeOptions()
    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(f"--user-data-dir={mkdtemp()}")
    options.add_argument(f"--data-path={mkdtemp()}")
    options.add_argument(f"--disk-cache-dir={mkdtemp()}")
    options.add_argument("--remote-debugging-port=9222")
    chrome = webdriver.Chrome("/opt/chromedriver", options=options)

Hope it helps, @suyash-web.

I tried to use the same options block code, but I got this error after that when trying to run on docker container with Ubuntu 22.04 as base image.

/root/test.py:24: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  chrome = webdriver.Chrome("/opt/chromedriver",
Traceback (most recent call last):
  File "/root/test.py", line 28, in <module>
    handler()
  File "/root/test.py", line 24, in handler
    chrome = webdriver.Chrome("/opt/chromedriver",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chrome/webdriver.py", line 84, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chromium/webdriver.py", line 104, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 286, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 378, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (chrome not reachable)
  (The process started from chrome location /opt/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x5631d8adee23 <unknown>
#1 0x5631d88077a7 <unknown>
#2 0x5631d883250a <unknown>
#3 0x5631d882fa25 <unknown>
#4 0x5631d886fd92 <unknown>
#5 0x5631d886f3af <unknown>
#6 0x5631d8866de3 <unknown>
#7 0x5631d883aa7b <unknown>
#8 0x5631d883b81e <unknown>
#9 0x5631d8aa0638 <unknown>
#10 0x5631d8aa4507 <unknown>
#11 0x5631d8aaec4c <unknown>
#12 0x5631d8aa5136 <unknown>
#13 0x5631d8a739cf <unknown>
#14 0x5631d8ac8b98 <unknown>
#15 0x5631d8ac8d68 <unknown>
#16 0x5631d8ad7cb3 <unknown>
#17 0x7f150dc54b43 <unknown>

I'm using:
selenium: 4.9.1
chrome version 116.0.5845.96 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chrome-linux64.zip
chromedriver 116.0.5845.96 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip

Can you check it on your side @x-N0 ? Thank you in advance

@suyash-web
Copy link
Author

suyash-web commented Aug 18, 2023

Hi,
Update about me wanting to add libreoffice to my docker image: I actually wanted to convert a docx file to pdf on aws lambda using libreoffice but i found an alternative. I instead created an HTML code and converted it into pdf. I found not all the modules available to convert html to pdf work in this case as its on aws lambda and won't have any supporting software that the modules may require to perform conversion. The module worked for me is xhtml2pdf
Example code:

import xhtml2pdf.pisa as pisa
from io import BytesIO

html_content = """
        Your html code here
"""

pdf_bytes_data = BytesIO()
pisa.CreatePDF(html_content, pdf_bytes_data)

with open("doc.pdf", "wb") as pdf_file:
    pdf_file.write(pdf_bytes_data.getvalue())

It can also add images to the pdf document. Just place the image path in <img> tag
@x-N0

@umihico
Copy link
Owner

umihico commented Aug 18, 2023

If you have M1 Macbook and find difficulty to try on local, how about this? My M1 Macbook is okay so far.

@umihico
Copy link
Owner

umihico commented Aug 18, 2023

Also please see #12 (comment)

@lambertrezon
Copy link

@umihico - Can you please guide how to use chrome driver and chrome without docker. I am using AWS lambda to do some web automation using selenium. Lastly the config worked on python 3.7 selenium 3.14 chrome and chromium 88.

I tried your chrome driver and chrome browser version 114 but ended in error below

"errorMessage": "Message: Service /tmp/chrome/chromedriver unexpectedly exited. Status code was: 127\n",

@umihico
Copy link
Owner

umihico commented Sep 29, 2023

@lambertrezon
The latest version worked this morning too. What is the exact changes between your code and my example?

@lambertrezon
Copy link

@umihico - I have downloaded the chrome driver and chrome browser with the links provided. Zipped the library and attached to the S3.While program execution this library is copied to /tmp directory and then Copied the same sample code which you have used.

import os
import sys
import boto3
import zipfile
os.system("pip --version")
os.system("mkdir /tmp/python")
os.system("pip install boto3 -t /tmp/python")
os.system("pip install requests -t /tmp/python")
os.system("pip install selenium -t /tmp/python")
sys.path.insert(0, '/tmp/python/')
from selenium import webdriver
from tempfile import mkdtemp
from selenium.webdriver.common.by import By
def lambda_handler(event, context):
download_dir = "/tmp/downloads"
s3_bucket_name = 'test'
s3_file_key = 'imports/lib_for_lambda_func/working.zip'
s3_client = boto3.client('s3')

# Download the library ZIP file from S3 to the /tmp directory
s3_client.download_file(s3_bucket_name, s3_file_key, '/tmp/library.zip')

# Extract the library ZIP file to the /tmp directory
with zipfile.ZipFile('/tmp/library.zip', 'r') as zip_ref:
    zip_ref.extractall('/tmp')

os.system("chmod 777 /tmp/chrome/*")


options = webdriver.ChromeOptions()
service = webdriver.ChromeService("/tmp/chrome/chromedriver")

options.binary_location = '/tmp/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(f"--user-data-dir={mkdtemp()}")
options.add_argument(f"--data-path={mkdtemp()}")
options.add_argument(f"--disk-cache-dir={mkdtemp()}")
options.add_argument("--remote-debugging-port=9222")
chrome = webdriver.Chrome(options=options, service=service)
chrome.get("https://example.com/")


return chrome.find_element(by=By.XPATH, value="//html").text

@vinhliem
Copy link

The main ideal that you should use the same version of Chrome and Chromium, but I suggest that you should run your chromedriver by Docker due to it supports up to 10GB for both source code and dependencies while the zip layer upload will be limited at 250MB ( which hard for you to handle layer of chrome or the other dependencies ). I did test it and only zip packed file of ( chromedriver & chrome ) took over 500MB and when I compress this zip file, it just can only reduce a half to around 225MB ~ 230MB which means only 20MB available space for both your source code and dependencies. So please be careful to consider which way is fix for your work.

By the way, I found the stable version you could use for test

The stable chromedriver: https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip
and
chrome binary: https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1135561%2Fchrome-linux.zip?alt=media

or you can find more version at https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html

@lambertrezon
Copy link

Previously i had python 3.7 and chrome driver, headless chromium 88 which was running smoothly. Since I upgraded to python 3.11 i had to update everything.

Is there any possibility to get headless chromium for latest chrome

@umihico
Copy link
Owner

umihico commented Oct 1, 2023

@lambertrezon
How about dependencies? They are all required to be installed.

@lambertrezon
Copy link

@umihico All the dependency are downloaded dynamically when the lambda function starts to execute

@boilsquid
Copy link

Im not using this image but one constructed myself and ran into a similar issue, when chrome was exiting it writes a core dump to /tmp. These progressively fill the memory of a warm lambda and eventually it OOM's itself. I have a method in my lambda now to clean the /tmp of core dumps after every invocation if they are present.

@lambertrezon
Copy link

@boilsquid can you please share me the method or project which worked for you.

@boilsquid
Copy link

@boilsquid can you please share me the method or project which worked for you.

I can't share my Dockerfile but its effectively the same as this build, this gist is what got it working for me.

@Kapil619
Copy link

Make sure to add the following to the options of your Chrome driver:

from selenium import webdriver
from tempfile import mkdtemp
def my_fn():
    options = webdriver.ChromeOptions()
    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(f"--user-data-dir={mkdtemp()}")
    options.add_argument(f"--data-path={mkdtemp()}")
    options.add_argument(f"--disk-cache-dir={mkdtemp()}")
    options.add_argument("--remote-debugging-port=9222")
    chrome = webdriver.Chrome("/opt/chromedriver", options=options)

Hope it helps, @suyash-web.

I tried to use the same options block code, but I got this error after that when trying to run on docker container with Ubuntu 22.04 as base image.

/root/test.py:24: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  chrome = webdriver.Chrome("/opt/chromedriver",
Traceback (most recent call last):
  File "/root/test.py", line 28, in <module>
    handler()
  File "/root/test.py", line 24, in handler
    chrome = webdriver.Chrome("/opt/chromedriver",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chrome/webdriver.py", line 84, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chromium/webdriver.py", line 104, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 286, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 378, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (chrome not reachable)
  (The process started from chrome location /opt/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x5631d8adee23 <unknown>
#1 0x5631d88077a7 <unknown>
#2 0x5631d883250a <unknown>
#3 0x5631d882fa25 <unknown>
#4 0x5631d886fd92 <unknown>
#5 0x5631d886f3af <unknown>
#6 0x5631d8866de3 <unknown>
#7 0x5631d883aa7b <unknown>
#8 0x5631d883b81e <unknown>
#9 0x5631d8aa0638 <unknown>
#10 0x5631d8aa4507 <unknown>
#11 0x5631d8aaec4c <unknown>
#12 0x5631d8aa5136 <unknown>
#13 0x5631d8a739cf <unknown>
#14 0x5631d8ac8b98 <unknown>
#15 0x5631d8ac8d68 <unknown>
#16 0x5631d8ad7cb3 <unknown>
#17 0x7f150dc54b43 <unknown>

I'm using: selenium: 4.9.1 chrome version 116.0.5845.96 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chrome-linux64.zip chromedriver 116.0.5845.96 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip

Can you check it on your side @x-N0 ? Thank you in advance

I'm also getting the same error . Is there any fix for this ?

@vinhliem
Copy link

Make sure to add the following to the options of your Chrome driver:

from selenium import webdriver
from tempfile import mkdtemp
def my_fn():
    options = webdriver.ChromeOptions()
    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(f"--user-data-dir={mkdtemp()}")
    options.add_argument(f"--data-path={mkdtemp()}")
    options.add_argument(f"--disk-cache-dir={mkdtemp()}")
    options.add_argument("--remote-debugging-port=9222")
    chrome = webdriver.Chrome("/opt/chromedriver", options=options)

Hope it helps, @suyash-web.

I tried to use the same options block code, but I got this error after that when trying to run on docker container with Ubuntu 22.04 as base image.

/root/test.py:24: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  chrome = webdriver.Chrome("/opt/chromedriver",
Traceback (most recent call last):
  File "/root/test.py", line 28, in <module>
    handler()
  File "/root/test.py", line 24, in handler
    chrome = webdriver.Chrome("/opt/chromedriver",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chrome/webdriver.py", line 84, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chromium/webdriver.py", line 104, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 286, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 378, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (chrome not reachable)
  (The process started from chrome location /opt/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x5631d8adee23 <unknown>
#1 0x5631d88077a7 <unknown>
#2 0x5631d883250a <unknown>
#3 0x5631d882fa25 <unknown>
#4 0x5631d886fd92 <unknown>
#5 0x5631d886f3af <unknown>
#6 0x5631d8866de3 <unknown>
#7 0x5631d883aa7b <unknown>
#8 0x5631d883b81e <unknown>
#9 0x5631d8aa0638 <unknown>
#10 0x5631d8aa4507 <unknown>
#11 0x5631d8aaec4c <unknown>
#12 0x5631d8aa5136 <unknown>
#13 0x5631d8a739cf <unknown>
#14 0x5631d8ac8b98 <unknown>
#15 0x5631d8ac8d68 <unknown>
#16 0x5631d8ad7cb3 <unknown>
#17 0x7f150dc54b43 <unknown>

I'm using: selenium: 4.9.1 chrome version 116.0.5845.96 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chrome-linux64.zip chromedriver 116.0.5845.96 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip

Can you check it on your side @x-N0 ? Thank you in advance

I'm also getting the same error . Is there any fix for this ?

The problem was that I placed the chrome binary on the wrong directory with a declaration for the code block. Furthermore, you can check more this issue which I mentioned here #161 (comment)

Let me know if it solves your problem

@Kapil619
Copy link

Make sure to add the following to the options of your Chrome driver:

from selenium import webdriver
from tempfile import mkdtemp
def my_fn():
    options = webdriver.ChromeOptions()
    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(f"--user-data-dir={mkdtemp()}")
    options.add_argument(f"--data-path={mkdtemp()}")
    options.add_argument(f"--disk-cache-dir={mkdtemp()}")
    options.add_argument("--remote-debugging-port=9222")
    chrome = webdriver.Chrome("/opt/chromedriver", options=options)

Hope it helps, @suyash-web.

I tried to use the same options block code, but I got this error after that when trying to run on docker container with Ubuntu 22.04 as base image.

/root/test.py:24: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  chrome = webdriver.Chrome("/opt/chromedriver",
Traceback (most recent call last):
  File "/root/test.py", line 28, in <module>
    handler()
  File "/root/test.py", line 24, in handler
    chrome = webdriver.Chrome("/opt/chromedriver",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chrome/webdriver.py", line 84, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chromium/webdriver.py", line 104, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 286, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 378, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (chrome not reachable)
  (The process started from chrome location /opt/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x5631d8adee23 <unknown>
#1 0x5631d88077a7 <unknown>
#2 0x5631d883250a <unknown>
#3 0x5631d882fa25 <unknown>
#4 0x5631d886fd92 <unknown>
#5 0x5631d886f3af <unknown>
#6 0x5631d8866de3 <unknown>
#7 0x5631d883aa7b <unknown>
#8 0x5631d883b81e <unknown>
#9 0x5631d8aa0638 <unknown>
#10 0x5631d8aa4507 <unknown>
#11 0x5631d8aaec4c <unknown>
#12 0x5631d8aa5136 <unknown>
#13 0x5631d8a739cf <unknown>
#14 0x5631d8ac8b98 <unknown>
#15 0x5631d8ac8d68 <unknown>
#16 0x5631d8ad7cb3 <unknown>
#17 0x7f150dc54b43 <unknown>

I'm using: selenium: 4.9.1 chrome version 116.0.5845.96 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chrome-linux64.zip chromedriver 116.0.5845.96 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip
Can you check it on your side @x-N0 ? Thank you in advance

I'm also getting the same error . Is there any fix for this ?

The problem was that I placed the chrome binary on the wrong directory with a declaration for the code block. Furthermore, you can check more this issue which I mentioned here #161 (comment)

Let me know if it solves your problem

I don't know what solved my problem. But , When i ran my lambda function today in morning, It didn't throw any error. And Yah, If it works : Don't touch it!

@vinhliem
Copy link

Make sure to add the following to the options of your Chrome driver:

from selenium import webdriver
from tempfile import mkdtemp
def my_fn():
    options = webdriver.ChromeOptions()
    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(f"--user-data-dir={mkdtemp()}")
    options.add_argument(f"--data-path={mkdtemp()}")
    options.add_argument(f"--disk-cache-dir={mkdtemp()}")
    options.add_argument("--remote-debugging-port=9222")
    chrome = webdriver.Chrome("/opt/chromedriver", options=options)

Hope it helps, @suyash-web.

I tried to use the same options block code, but I got this error after that when trying to run on docker container with Ubuntu 22.04 as base image.

/root/test.py:24: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  chrome = webdriver.Chrome("/opt/chromedriver",
Traceback (most recent call last):
  File "/root/test.py", line 28, in <module>
    handler()
  File "/root/test.py", line 24, in handler
    chrome = webdriver.Chrome("/opt/chromedriver",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chrome/webdriver.py", line 84, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/chromium/webdriver.py", line 104, in __init__
    super().__init__(
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 286, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 378, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.11/dist-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (chrome not reachable)
  (The process started from chrome location /opt/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x5631d8adee23 <unknown>
#1 0x5631d88077a7 <unknown>
#2 0x5631d883250a <unknown>
#3 0x5631d882fa25 <unknown>
#4 0x5631d886fd92 <unknown>
#5 0x5631d886f3af <unknown>
#6 0x5631d8866de3 <unknown>
#7 0x5631d883aa7b <unknown>
#8 0x5631d883b81e <unknown>
#9 0x5631d8aa0638 <unknown>
#10 0x5631d8aa4507 <unknown>
#11 0x5631d8aaec4c <unknown>
#12 0x5631d8aa5136 <unknown>
#13 0x5631d8a739cf <unknown>
#14 0x5631d8ac8b98 <unknown>
#15 0x5631d8ac8d68 <unknown>
#16 0x5631d8ad7cb3 <unknown>
#17 0x7f150dc54b43 <unknown>

I'm using: selenium: 4.9.1 chrome version 116.0.5845.96 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chrome-linux64.zip chromedriver 116.0.5845.96 https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip
Can you check it on your side @x-N0 ? Thank you in advance

I'm also getting the same error . Is there any fix for this ?

The problem was that I placed the chrome binary on the wrong directory with a declaration for the code block. Furthermore, you can check more this issue which I mentioned here #161 (comment)
Let me know if it solves your problem

I don't know what solved my problem. But , When i ran my lambda function today in morning, It didn't throw any error. And Yah, If it works : Don't touch it!

One more thing, we should stay the both chromedriver and chrome at 114 ( please be sure that match with a prefix as well ). It should work over time, due to version above 115 are on test stage, not a stable version

@rsergiuistoc
Copy link

rsergiuistoc commented Mar 9, 2024

Hello, I'm trying to run my docker image from my mac m1 processor and I'm getting this error continuously Can anyone please help? This is the error I am getting:

driver = webdriver.Chrome(service=service, options=options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/lang/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 49, in __init__
    super().__init__(
  File "/var/lang/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 51, in __init__
    self.service.start()
  File "/var/lang/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 97, in start
    self.assert_process_still_running()
  File "/var/lang/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
selenium.common.exceptions.WebDriverException: Message: Service /opt/chromedriver unexpectedly exited. Status code was: 255

script.py where I'm defining driver:

options = webdriver.ChromeOptions()
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("--remote-debugging-port=9222")
service = selenium.webdriver.chrome.service.Service('/opt/chromedriver')
driver = webdriver.Chrome(service=service, options=options)

My Dockerfile:


FROM public.ecr.aws/lambda/python@sha256:10dbb67ede15b5fd516be87dd71c3f7968904b0b840235720486476b34ef9b67 as build
RUN yum install -y unzip && \
    curl -Lo "/tmp/chromedriver.zip" "https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip" && \
    curl -Lo "/tmp/chrome-linux.zip" "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1135561%2Fchrome-linux.zip?alt=media" && \
    unzip /tmp/chromedriver.zip -d /opt/ && \
    unzip /tmp/chrome-linux.zip -d /opt/

FROM public.ecr.aws/lambda/python@sha256:10dbb67ede15b5fd516be87dd71c3f7968904b0b840235720486476b34ef9b67
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==4.9.1
COPY --from=build /opt/chrome-linux /opt/chrome
COPY --from=build /opt/chromedriver /opt/

COPY script.py /var/task
COPY utils.py /var/task
COPY func.py /var/task
COPY requirements.txt /var/task

RUN pip install -r requirements.txt
CMD ["script.py"]
ENTRYPOINT [ "python" ]

Had the same error, you can check if the chromedriver starts by inserting this command in your Dockerfile RUN /opt/chromedriver by this you can see the reason, maybe you're missing some dependencies for me it was qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory because I am running on M1, built it with docker buildx build --platform linux/amd64 and did the trick.

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

10 participants