From 8a6746f595785f942d31689c28af6f4e039f160d Mon Sep 17 00:00:00 2001 From: Bram Date: Wed, 29 Apr 2026 16:39:15 +0200 Subject: [PATCH] I hate AI --- Dockers/puppeteer-api/app/services/browser.py | 43 +++++-------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/Dockers/puppeteer-api/app/services/browser.py b/Dockers/puppeteer-api/app/services/browser.py index d9faa46..af1583e 100644 --- a/Dockers/puppeteer-api/app/services/browser.py +++ b/Dockers/puppeteer-api/app/services/browser.py @@ -346,20 +346,11 @@ async def interactions_service( if not xpath_selector: raise ValueError("xpath_selector must be a non-empty string") await wait_for_xpath(xpath_selector, timeout_ms=30000) - await page.evaluate( - """(xpath) => { - const el = document.evaluate( - xpath, - document, - null, - XPathResult.FIRST_ORDERED_NODE_TYPE, - null - ).singleNodeValue; - if (!el) throw new Error(`No element for xpath: ${xpath}`); - el.click(); - }""", - xpath_selector[len("xpath=") :] if xpath_selector.startswith("xpath=") else xpath_selector, - ) + normalized_xpath = xpath_selector[len("xpath=") :] if xpath_selector.startswith("xpath=") else xpath_selector + # Use Playwright's click to generate real pointer/mouse events. + locator = page.locator(f"xpath={normalized_xpath}").first + await locator.wait_for(timeout=30000) + await locator.click(force=True, timeout=30000) elif action == "type": if text is None: @@ -385,25 +376,11 @@ async def interactions_service( raise ValueError("xpath_selector must be a non-empty string") await wait_for_xpath(xpath_selector, timeout_ms=30000) normalized_xpath = xpath_selector[len("xpath=") :] if xpath_selector.startswith("xpath=") else xpath_selector - await page.evaluate( - """({ xpath, value }) => { - const el = document.evaluate( - xpath, - document, - null, - XPathResult.FIRST_ORDERED_NODE_TYPE, - null - ).singleNodeValue; - if (!el) throw new Error(`No element for xpath: ${xpath}`); - el.focus?.(); - if ('value' in el) { - el.value = value; - el.dispatchEvent(new Event('input', { bubbles: true })); - el.dispatchEvent(new Event('change', { bubbles: true })); - } - }""", - {"xpath": normalized_xpath, "value": text}, - ) + locator = page.locator(f"xpath={normalized_xpath}").first + await locator.wait_for(timeout=30000) + # Prefer fill/type so frameworks see real input events. + await locator.click(force=True, timeout=30000) + await locator.fill(text, timeout=30000) else: raise ValueError(f"Unknown interaction action: {action}")