This commit is contained in:
@@ -263,7 +263,25 @@ async def interactions_service(
|
||||
# Ensure the page is fully loaded (helps with JS-driven UIs).
|
||||
await page.wait_for_function("document.readyState === 'complete'", timeout=30000)
|
||||
|
||||
# Best-effort cookie/banner handling (helps avoid click interception).
|
||||
cookie_buttons = [
|
||||
"Accept all",
|
||||
"Accepteer",
|
||||
"Accepteren",
|
||||
"Accept",
|
||||
]
|
||||
for button in cookie_buttons:
|
||||
try:
|
||||
element = await page.query_selector(f'text="{button}"')
|
||||
if element:
|
||||
await element.click()
|
||||
await page.wait_for_timeout(1000)
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Apply initial scroll position if provided.
|
||||
# Do this AFTER cookie/banner clicks since those can change scroll position.
|
||||
if scroll_x is not None or scroll_y is not None:
|
||||
try:
|
||||
await page.evaluate(
|
||||
@@ -293,23 +311,6 @@ async def interactions_service(
|
||||
except Exception as e:
|
||||
print(f"Error applying initial scroll position: {e}")
|
||||
|
||||
# Best-effort cookie/banner handling (helps avoid click interception).
|
||||
cookie_buttons = [
|
||||
"Accept all",
|
||||
"Accepteer",
|
||||
"Accepteren",
|
||||
"Accept",
|
||||
]
|
||||
for button in cookie_buttons:
|
||||
try:
|
||||
element = await page.query_selector(f'text="{button}"')
|
||||
if element:
|
||||
await element.click()
|
||||
await page.wait_for_timeout(1000)
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
for interaction in interactions:
|
||||
# Support both Pydantic model instances and raw dicts.
|
||||
if isinstance(interaction, dict):
|
||||
@@ -404,7 +405,8 @@ async def interactions_service(
|
||||
if return_type == "html":
|
||||
return await page.content()
|
||||
|
||||
return await page.screenshot(full_page=True, type="png")
|
||||
# For coordinate-based workflows, return the viewport screenshot so pixel coords align.
|
||||
return await page.screenshot(full_page=False, type="png")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error during interactions capture: {e}")
|
||||
|
||||
Reference in New Issue
Block a user