try to auto accept cookies
Build and Push Docker Images / build-and-push (push) Successful in 28s

This commit is contained in:
2026-04-02 16:19:04 +02:00
parent 39eabf5940
commit 50838ee7bc
+20 -18
View File
@@ -263,7 +263,25 @@ async def interactions_service(
# Ensure the page is fully loaded (helps with JS-driven UIs). # Ensure the page is fully loaded (helps with JS-driven UIs).
await page.wait_for_function("document.readyState === 'complete'", timeout=30000) 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. # 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: if scroll_x is not None or scroll_y is not None:
try: try:
await page.evaluate( await page.evaluate(
@@ -293,23 +311,6 @@ async def interactions_service(
except Exception as e: except Exception as e:
print(f"Error applying initial scroll position: {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: for interaction in interactions:
# Support both Pydantic model instances and raw dicts. # Support both Pydantic model instances and raw dicts.
if isinstance(interaction, dict): if isinstance(interaction, dict):
@@ -404,7 +405,8 @@ async def interactions_service(
if return_type == "html": if return_type == "html":
return await page.content() 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: except Exception as e:
print(f"Error during interactions capture: {e}") print(f"Error during interactions capture: {e}")