do not close the tab when download is not triggered (#2234)

This commit is contained in:
Shuchang Zheng
2025-04-28 14:59:31 +08:00
committed by GitHub
parent 8b184ce970
commit a3d9917386

View File

@@ -534,6 +534,7 @@ async def handle_click_action(
step_id=step.step_id, step_id=step.step_id,
workflow_run_id=task.workflow_run_id, workflow_run_id=task.workflow_run_id,
) )
results: list[ActionResult] = []
try: try:
results = await handle_click_to_download_file_action(action, page, scraped_page, task, step) results = await handle_click_to_download_file_action(action, page, scraped_page, task, step)
except Exception: except Exception:
@@ -555,12 +556,14 @@ async def handle_click_action(
workflow_run_id=task.workflow_run_id, workflow_run_id=task.workflow_run_id,
) )
if page_count_after_download > initial_page_count and browser_state and browser_state.browser_context: if page_count_after_download > initial_page_count and browser_state and browser_state.browser_context:
if results and results[-1].download_triggered:
LOG.info( LOG.info(
"Extra page opened after download, closing it", "Download triggered, closing the extra page",
task_id=task.task_id, task_id=task.task_id,
step_id=step.step_id, step_id=step.step_id,
workflow_run_id=task.workflow_run_id, workflow_run_id=task.workflow_run_id,
) )
if page == browser_state.browser_context.pages[-1]: if page == browser_state.browser_context.pages[-1]:
LOG.warning( LOG.warning(
"The extra page is the current page, closing it", "The extra page is the current page, closing it",
@@ -570,6 +573,13 @@ async def handle_click_action(
) )
# close the extra page # close the extra page
await browser_state.browser_context.pages[-1].close() await browser_state.browser_context.pages[-1].close()
else:
LOG.info(
"No download triggered, not closing the extra page",
task_id=task.task_id,
step_id=step.step_id,
workflow_run_id=task.workflow_run_id,
)
else: else:
results = await chain_click( results = await chain_click(
task, task,