Skip to content

[🐛 Bug]: Incorrect screenshot size in Ubuntu 24.04 #14660

Closed as not planned
Closed as not planned
@GergelyKalmar

Description

@GergelyKalmar

What happened?

We've migrated from Ubuntu 20.04 to Ubuntu 24.04, and suddenly our Selenium screenshot sizes changed.

It seems that the initial window size now includes the search bar / bookmarks bar (and potentially other elements like notification bars), therefore the actual space left for the page content is smaller than the specified window size, even in headless mode. (Tried both the old and new headless modes, the results are the same.)

While the window size is 1800x900 pixels as specified (and as returned by get_window_size), the actual screenshot size is only 1800x708 pixels. Occasionally (for some tests) we also observed widths that were different from the originally specified widths.

It does seem like this might be an issue with Chrome / ChromeDriver, but I wanted to open an issue here as well to see if there's maybe something we can do as a workaround in the meantime.

How can we reproduce the issue?

#!/usr/bin/env python3
import logging

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.webdriver import WebDriver

logger = logging.getLogger('selenium')
logger.setLevel(logging.DEBUG)
logging.basicConfig(level=logging.DEBUG)

chrome_path = '{...}/chrome/130.0.6723.69/chrome'
chromedriver_path = '{...}/chromedriver/130.0.6723.69/chromedriver'
screenshot_destination = '{...}/selenium-test/test.png'

width = 1800
height = 900

service = Service(executable_path=chromedriver_path)
options = Options()
options.binary_location = chrome_path
options.add_argument('--headless=new')
options.add_argument(f'--window-size={width},{height}')

driver = WebDriver(options=options, service=service)
print(driver.get_window_size())
driver.get_screenshot_as_file(screenshot_destination)

Relevant log output

DEBUG:selenium.webdriver.common.driver_finder:Skipping Selenium Manager; path to chrome driver specified in Service class: .../chromedriver/130.0.6723.69/chromedriver
DEBUG:selenium.webdriver.common.service:Started executable: `.../chromedriver/130.0.6723.69/chromedriver` in a child process with pid: 9673 using 0 to output -3
DEBUG:selenium.webdriver.remote.remote_connection:POST http://localhost:37079/session {'capabilities': {'firstMatch': [{}], 'alwaysMatch': {'browserName': 'chrome', 'pageLoadStrategy': <PageLoadStrategy.normal: 'normal'>, 'goog:chromeOptions': {'extensions': [], 'binary': '.../chrome/130.0.6723.69/chrome', 'args': ['--headless=new', '--window-size=1800,900']}}}}
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): localhost:37079
DEBUG:urllib3.connectionpool:http://localhost:37079 "POST /session HTTP/11" 200 0
DEBUG:selenium.webdriver.remote.remote_connection:Remote response: status=200 | data={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"130.0.6723.69","chrome":{"chromedriverVersion":"130.0.6723.69 (3ec172b971b9478c515a58f591112c5c23fa4965-refs/branch-heads/6723@{#1452})","userDataDir":"/tmp/.org.chromium.Chromium.2zos6E"},"fedcm:accounts":true,"goog:chromeOptions":{"debuggerAddress":"localhost:39321"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"linux","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:extension:credBlob":true,"webauthn:extension:largeBlob":true,"webauthn:extension:minPinLength":true,"webauthn:extension:prf":true,"webauthn:virtualAuthenticators":true},"sessionId":"714b6a83442847ecbccee4eb7ea89edd"}} | headers=HTTPHeaderDict({'Content-Length': '848', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request
DEBUG:selenium.webdriver.remote.remote_connection:GET http://localhost:37079/session/714b6a83442847ecbccee4eb7ea89edd/window/rect {}
DEBUG:urllib3.connectionpool:http://localhost:37079 "GET /session/714b6a83442847ecbccee4eb7ea89edd/window/rect HTTP/11" 200 0
DEBUG:selenium.webdriver.remote.remote_connection:Remote response: status=200 | data={"value":{"height":900,"width":1800,"x":10,"y":10}} | headers=HTTPHeaderDict({'Content-Length': '51', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request
{'width': 1800, 'height': 900}
DEBUG:selenium.webdriver.remote.remote_connection:GET http://localhost:37079/session/714b6a83442847ecbccee4eb7ea89edd/screenshot {}
DEBUG:urllib3.connectionpool:http://localhost:37079 "GET /session/714b6a83442847ecbccee4eb7ea89edd/screenshot HTTP/11" 200 0
DEBUG:selenium.webdriver.remote.remote_connection:Remote response: status=200 | data={"value":"..."} | headers=HTTPHeaderDict({'Content-Length': '7224', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request

Operating System

Ubuntu 24.04

Selenium version

Python 3.12

What are the browser(s) and version(s) where you see this issue?

Chrome for Testing 130.0.6723.69

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 130.0.6723.69

Are you using Selenium Grid?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-defectSomething is not working as intendedJ-awaiting answerQuestion asked of user; a reply moves it to triage again

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions