So I have been trying on launching selenium with google chrome, later with chromium. None of these works fine on my Apple Silicon M2 MacOS system. I am running selenium on docker to just simply open google,com website. However, for the past days I get error of
Message: session not created: Chrome failed to start: exited normally.
(The process started from chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Here is the Dockerfile
FROM --platform=linux/amd64 python:3.9
ENV DEBIAN_FRONTEND noninteractive
RUN pip install --upgrade pip
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt --no-cache-dir
COPY . .
RUN apt update -y && apt install libgl1-mesa-glx sudo chromium chromium-driver -y
# Command to run the script
CMD ["python", "main.py"]
main.py file:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time
chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless") # Ensure GUI is off
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument("--remote-debugging-port=9222") # this
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://www.google.com")
time.sleep(10)
print(driver.title)
driver.quit()
display.stop()
I have been trying on changing different options, adding –remote-debugging-port=9222 like other suggest, adding --no-sandbox
way before --headless
, but none of the actions came to fix this issue.