From c9a0b0c1aa41762b01edf435aa2ac54f1fe7a539 Mon Sep 17 00:00:00 2001 From: Bram Date: Thu, 23 Apr 2026 15:49:03 +0200 Subject: [PATCH] refactor interactions_service to use object destructuring for scroll coordinates, enhancing code clarity and maintainability --- Dockers/puppeteer-api/app/services/browser.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Dockers/puppeteer-api/app/services/browser.py b/Dockers/puppeteer-api/app/services/browser.py index 57c8655..8482869 100644 --- a/Dockers/puppeteer-api/app/services/browser.py +++ b/Dockers/puppeteer-api/app/services/browser.py @@ -225,19 +225,17 @@ async def interactions_service( target_scroll_y = max(0.0, y - (inner_h / 2.0)) await page.evaluate( - """(sx, sy) => { + """({ sx, sy }) => { window.scrollTo({ left: sx, top: sy, behavior: 'auto' }); }""", - target_scroll_x, - target_scroll_y, + {"sx": target_scroll_x, "sy": target_scroll_y}, ) # Wait for scroll offsets to settle before resolving the viewport point. try: await page.wait_for_function( - """(sx, sy) => Math.abs(window.scrollX - sx) <= 2 && Math.abs(window.scrollY - sy) <= 2""", - target_scroll_x, - target_scroll_y, + """({ sx, sy }) => Math.abs(window.scrollX - sx) <= 2 && Math.abs(window.scrollY - sy) <= 2""", + {"sx": target_scroll_x, "sy": target_scroll_y}, timeout=10000, ) except Exception: