fix: Flakiness around scrolling during taking tiled screenshots with Playwright (#36051)

(cherry picked from commit 63dfd95aa2)
This commit is contained in:
Kamil Gabryjelski
2025-11-10 12:57:28 +01:00
committed by Joe Li
parent 70117eb55f
commit 933ec0a918
3 changed files with 151 additions and 203 deletions

View File

@@ -162,11 +162,13 @@ class WebDriverPlaywright(WebDriverProxy):
browser_args = app.config["WEBDRIVER_OPTION_ARGS"]
browser = playwright.chromium.launch(args=browser_args)
pixel_density = app.config["WEBDRIVER_WINDOW"].get("pixel_density", 1)
viewport_height = self._window[1]
viewport_width = self._window[0]
context = browser.new_context(
bypass_csp=True,
viewport={
"height": self._window[1],
"width": self._window[0],
"height": viewport_height,
"width": viewport_width,
},
device_scale_factor=pixel_density,
)
@@ -266,15 +268,15 @@ class WebDriverPlaywright(WebDriverProxy):
height_threshold = app.config.get(
"SCREENSHOT_TILED_HEIGHT_THRESHOLD", 5000
)
viewport_height = app.config.get(
"SCREENSHOT_TILED_VIEWPORT_HEIGHT", self._window[1]
tile_height = app.config.get(
"SCREENSHOT_TILED_VIEWPORT_HEIGHT", viewport_height
)
# Use tiled screenshots for large dashboards
use_tiled = (
chart_count >= chart_threshold
or dashboard_height > height_threshold
)
) and dashboard_height > tile_height
if use_tiled:
logger.info(
@@ -283,9 +285,11 @@ class WebDriverPlaywright(WebDriverProxy):
f"{dashboard_height}px height. Using tiled screenshots."
)
)
img = take_tiled_screenshot(
page, element_name, viewport_height=viewport_height
# set viewport height to tile height for easier calculations
page.set_viewport_size(
{"height": tile_height, "width": viewport_width}
)
img = take_tiled_screenshot(page, element_name, tile_height)
if img is None:
logger.warning(
(