do not close the tab when download is not triggered (#2234)
This commit is contained in:
@@ -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,21 +556,30 @@ 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:
|
||||||
LOG.info(
|
if results and results[-1].download_triggered:
|
||||||
"Extra page opened after download, closing it",
|
LOG.info(
|
||||||
task_id=task.task_id,
|
"Download triggered, closing the extra page",
|
||||||
step_id=step.step_id,
|
task_id=task.task_id,
|
||||||
workflow_run_id=task.workflow_run_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 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,
|
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,
|
||||||
)
|
)
|
||||||
# close the extra page
|
|
||||||
await browser_state.browser_context.pages[-1].close()
|
|
||||||
else:
|
else:
|
||||||
results = await chain_click(
|
results = await chain_click(
|
||||||
task,
|
task,
|
||||||
|
|||||||
Reference in New Issue
Block a user