From a3d991738672b29f52b8f692cdb034e442c61600 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Mon, 28 Apr 2025 14:59:31 +0800 Subject: [PATCH] do not close the tab when download is not triggered (#2234) --- skyvern/webeye/actions/handler.py | 32 ++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py index 449ad356..561b2eb8 100644 --- a/skyvern/webeye/actions/handler.py +++ b/skyvern/webeye/actions/handler.py @@ -534,6 +534,7 @@ async def handle_click_action( step_id=step.step_id, workflow_run_id=task.workflow_run_id, ) + results: list[ActionResult] = [] try: results = await handle_click_to_download_file_action(action, page, scraped_page, task, step) except Exception: @@ -555,21 +556,30 @@ async def handle_click_action( workflow_run_id=task.workflow_run_id, ) if page_count_after_download > initial_page_count and browser_state and browser_state.browser_context: - LOG.info( - "Extra page opened after download, closing it", - task_id=task.task_id, - step_id=step.step_id, - workflow_run_id=task.workflow_run_id, - ) - if page == browser_state.browser_context.pages[-1]: - LOG.warning( - "The extra page is the current page, closing it", + if results and results[-1].download_triggered: + LOG.info( + "Download triggered, closing the extra page", + task_id=task.task_id, + step_id=step.step_id, + workflow_run_id=task.workflow_run_id, + ) + + if page == browser_state.browser_context.pages[-1]: + LOG.warning( + "The extra page is the current page, closing it", + task_id=task.task_id, + step_id=step.step_id, + workflow_run_id=task.workflow_run_id, + ) + # close the extra page + 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, ) - # close the extra page - await browser_state.browser_context.pages[-1].close() else: results = await chain_click( task,