Fix screenshotter again

This commit is contained in:
2026-03-21 23:16:43 +01:00
parent 5fc7bfafad
commit a6deeeaebf

View File

@@ -31,14 +31,12 @@ class Screenshotter:
page.evaluate(f""" page.evaluate(f"""
let el = document.querySelector('{ticket_selector}'); let el = document.querySelector('{ticket_selector}');
if (el) {{ if (el) {{
// Roztáhneme samotný kontejner se zápasy
let wrapper = el.querySelector('.betslip-selections'); let wrapper = el.querySelector('.betslip-selections');
if (wrapper) {{ if (wrapper) {{
wrapper.style.setProperty('height', 'auto', 'important'); wrapper.style.setProperty('height', 'auto', 'important');
wrapper.style.setProperty('overflow', 'visible', 'important'); wrapper.style.setProperty('overflow', 'visible', 'important');
}} }}
// A teď projdeme všechny nadřazené prvky až k <body>
while (el && el !== document.body) {{ while (el && el !== document.body) {{
el.style.setProperty('height', 'auto', 'important'); el.style.setProperty('height', 'auto', 'important');
el.style.setProperty('max-height', 'none', 'important'); el.style.setProperty('max-height', 'none', 'important');
@@ -62,4 +60,16 @@ class Screenshotter:
}}); }});
""") """)
# Resize viewport if the element extends beyond the bottom edge.
# The modal is vertically centered, so increasing the viewport by X shifts the element
# down by X/2. To compensate: new_height = 2 * bottom - current_height.
bbox = page.locator(ticket_selector).bounding_box()
bottom = bbox["y"] + bbox["height"]
vp_h = page.viewport_size["height"]
if bottom > vp_h:
page.set_viewport_size({"width": page.viewport_size["width"], "height": int(2 * bottom - vp_h) + 10})
# Wait for the browser to reflow after style changes before screenshotting
page.wait_for_timeout(500)
page.locator(ticket_selector).screenshot(path=target_path) page.locator(ticket_selector).screenshot(path=target_path)