-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Closed as not planned
Labels
A-needs-triagingA Selenium member will evaluate this soon!A Selenium member will evaluate this soon!I-defectSomething is not working as intendedSomething is not working as intended
Description
What happened?
Hello, the script does not run in the docker environment, it works without errors outside of docker.
Below is the error code and log. Selenium version 4.28.1
How can we reproduce the issue?
Dockerfile
FROM --platform=linux/amd64 python:3.9-slim
WORKDIR /app
COPY requirements.txt .
# Install the required packages
RUN pip install --no-cache-dir -r requirements.txt
RUN apt-get update && apt-get install -y \
wget \
unzip \
libnss3 \
libgconf-2-4 \
libxss1 \
libxrandr2 \
libx11-xcb1 \
libxcomposite1 \
libxcursor1 \
libxi6 \
libxtst6 \
libglib2.0-0 \
libasound2 \
fonts-liberation \
libappindicator3-1 \
libgtk-3-0 \
libdrm2 \
libgbm1 \
libvulkan1 \
xdg-utils \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y wget curl unzip gnupg --no-install-recommends
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | \
gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/google.gpg --import; \
chmod 644 /etc/apt/trusted.gpg.d/google.gpg; \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list
RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
apt-get install -y ./google-chrome-stable_current_amd64.deb && \
rm google-chrome-stable_current_amd64.deb
# ARG CHROME_VERSION="130.0.6723.69-1"
# RUN wget https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb
# RUN dpkg -i google-chrome-stable_${CHROME_VERSION}_amd64.deb
# RUN rm -f google-chrome-stable_${CHROME_VERSION}_amd64.deb
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY . .
CMD ["python", "main.py"]
main.py
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
def test_fullpage_screenshot(url: str, filename: str):
custom_options = Options()
custom_options.add_argument("--disable-extensions")
custom_options.add_argument('--headless=new')
custom_options.add_argument('--no-sandbox')
custom_options.add_argument('--lang=ko-KR')
custom_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=custom_options)
try:
driver.get(url)
time.sleep(10)
ele = driver.find_element(By.TAG_NAME, 'body')
height = driver.execute_script("return document.body.scrollHeight")
driver.set_window_size(1920, height)
driver.save_screenshot(f"screenshots/{filename}")
except Exception:
pass
finally:
driver.close()
driver.quit()
if __name__ == "__main__":
test_fullpage_screenshot("https://tproger.ru", "tproger.png")
test_fullpage_screenshot("https://stackoverflow.com", "stackoverflow.png")Relevant log output
selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id: session deleted as the browser has closed the connection
from disconnected: Unable to receive message from renderer
(Session info: chrome=132.0.6834.110)
Stacktrace:
#0 0x0040009e5dca <unknown>
#1 0x0040004dc3f0 <unknown>
#2 0x0040004c46ae <unknown>
#3 0x0040004c43b9 <unknown>
#4 0x0040004c2346 <unknown>
#5 0x0040004c29ba <unknown>
#6 0x0040004c1311 <unknown>
#7 0x0040004c9814 <unknown>
#8 0x0040004c105b <unknown>
#9 0x0040004c402d <unknown>
#10 0x0040004c2346 <unknown>
#11 0x0040004c29ba <unknown>
#12 0x0040004c1311 <unknown>
#13 0x0040004b7b87 <unknown>
#14 0x0040004c105b <unknown>
#15 0x0040004c0982 <unknown>
#16 0x0040004c0495 <unknown>
#17 0x0040004de65e <unknown>
#18 0x0040004b167e <unknown>
#19 0x0040004b1161 <unknown>
#20 0x00400055ceac <unknown>
#21 0x00400055c2f6 <unknown>
falsehuman@MacBook-Air-Emil test_docker_chrome % docker build -t full_screenshot .
[+] Building 406.0s (14/14) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/python:3.9-slim 1.0s
=> [1/9] FROM docker.io/library/python:3.9-slim@sha256:bb8009c87ab69e751a1dd2c6c7f8abaae3d9fce8e072802d4a23c95594d16d84 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 151B 0.0s
=> CACHED [2/9] WORKDIR /app 0.0s
=> [3/9] COPY requirements.txt . 0.0s
=> [4/9] RUN pip install --no-cache-dir -r requirements.txt 52.5s
=> [5/9] RUN apt-get update && apt-get install -y wget unzip libnss3 libgconf-2-4 libxss1 libxrandr2 libx11-xcb1 libxcomposite1 210.8s
=> [6/9] RUN apt-get update && apt-get install -y wget curl unzip gnupg --no-install-recommends 47.1s
falsehuman@MacBook-Air-Emil test_docker_chrome % docker run -v $(pwd)/screenshots:/app/screenshots --name test full_screenshot
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Traceback (most recent call last):
File "/app/main.py", line 32, in <module>
test_fullpage_screenshot("https://tproger.ru", "tproger.png")
File "/app/main.py", line 15, in test_fullpage_screenshot
driver = webdriver.Chrome(options=custom_options)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
super().__init__(
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 66, in __init__
super().__init__(command_executor=executor, options=options)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 250, in __init__
self.start_session(capabilities)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 342, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id: session deleted as the browser has closed the connection
from disconnected: Unable to receive message from renderer
(Session info: chrome=132.0.6834.110)
Stacktrace:
#0 0x0040009e5dca <unknown>
#1 0x0040004dc3f0 <unknown>
#2 0x0040004c46ae <unknown>
#3 0x0040004c43b9 <unknown>
#4 0x0040004c2346 <unknown>
#5 0x0040004c29ba <unknown>
#6 0x0040004c1311 <unknown>
#7 0x0040004c9814 <unknown>
#8 0x0040004c105b <unknown>
#9 0x0040004c402d <unknown>
#10 0x0040004c2346 <unknown>
#11 0x0040004c29ba <unknown>
#12 0x0040004c1311 <unknown>
#13 0x0040004b7b87 <unknown>
#14 0x0040004c105b <unknown>
#15 0x0040004c0982 <unknown>
#16 0x0040004c0495 <unknown>
#17 0x0040004de65e <unknown>
#18 0x0040004b167e <unknown>
#19 0x0040004b1161 <unknown>
#20 0x00400055ceac <unknown>
#21 0x00400055c2f6 <unknown>
#22 0x004000550833 <unknown>
#23 0x00400051d5a0 <unknown>
#24 0x00400051eece <unknown>
#25 0x0040009afbdb <unknown>
#26 0x0040009b3b67 <unknown>
#27 0x00400099b3bc <unknown>
#28 0x0040009b4727 <unknown>
#29 0x00400097f74f <unknown>
#30 0x0040009d4938 <unknown>
#31 0x0040009d4b00 <unknown>
#32 0x0040009e4c46 <unknown>
#33 0x004002dd01c4 <unknown>Operating System
MacOS 15.2
Selenium version
4.28.1
What are the browser(s) and version(s) where you see this issue?
132.0.6834.110
What are the browser driver(s) and version(s) where you see this issue?
132.0.6834.110
Are you using Selenium Grid?
No response
Metadata
Metadata
Assignees
Labels
A-needs-triagingA Selenium member will evaluate this soon!A Selenium member will evaluate this soon!I-defectSomething is not working as intendedSomething is not working as intended