0

I have the same error as this post:

WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium through Python on VPS

Howerver it seems as I have different issue - managing versions does not solve it.

I am trying to use Google Cloud Functions (2nd tear which is based on Cloud Run) to run Seleniu.

My code is just the basic one:

main.py:

def hello_world(request):
  print("Start")
  from selenium import webdriver
  from selenium.webdriver.chrome.options import Options
  from chromedriver_py import binary_path
  from selenium import webdriver
  from selenium.webdriver.chrome.service import Service
  from webdriver_manager.chrome import ChromeDriverManager
  chrome_options = Options()
  chrome_options.binary_location=binary_path
  chrome_options.add_argument("--remote-debugging-port=9222")
  chrome_options.add_argument("--headless")
  chrome_options.add_argument("--disable-gpu")
  chrome_options.add_argument("--window-size=1920x1080")
  chrome_options.add_argument('--no-sandbox')
  chrome_options.add_argument('--disable-extensions')
  driver = webdriver.Chrome(options=chrome_options,service=Service(ChromeDriverManager().install()))
  driver.get("https://www.google.com")
  print(driver.title)
  driver.close()
  print("End")
return "Empty - nothing"

requirements.txt:

selenium >= 4.2.0
webdriver-manager >= 3.7.0
chromedriver_py >= 103.0.5060.24

It gives error: "selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally"

Has anyone figured it out?

I found information that cloud functions does not work with Selenium: Can I use Selenium WebDriver with Google Cloud Functions?

However I set it on 2nd gen environment, which is based on Cloud Run, so I wish there is a way to make it work...

1 Answers1

0

This might be 6 months old but as you see, it appears that you can't use Selenium with Python in Cloud Function. But you can do it with Cloud Run: https://dev.to/googlecloud/using-headless-chrome-with-cloud-run-3fdp. Alternatively, you can use the Node.js in Cloud Function along with puppeteer package: https://rominirani.com/using-puppeteer-in-google-cloud-functions-809a14856e14. I am also trying to do the same thing.