From 48f1d62c5d1ed1120507c0eb5b0f61532e46f6d0 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Tue, 17 Dec 2024 09:43:25 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=84=20synced=20local=20'skyvern/'?= =?UTF-8?q?=20with=20remote=20'skyvern/'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > [!IMPORTANT] > Adds logic in `handle_click_action()` to close extra pages opened during file downloads and refactors `set_download_file_listener()` for clarity. > > - **Behavior**: > - In `handle_click_action()` in `handler.py`, added logic to close any extra page opened during a file download action. > - Logs page count before and after download to identify if an extra page was opened. > - **Misc**: > - Minor refactoring in `set_download_file_listener()` in `browser_factory.py` to improve code clarity. > > This description was created by [Ellipsis](https://www.ellipsis.dev?ref=Skyvern-AI%2Fskyvern-cloud&utm_source=github&utm_medium=referral) for 6fcf2d99affb1fc816380fe2b1d1490cd77ee890. It will automatically update as commits are pushed. --- skyvern/webeye/actions/handler.py | 42 +++++++++++++++++++++++++++++- skyvern/webeye/browser_factory.py | 5 ++-- skyvern/webeye/scraper/domUtils.js | 6 +---- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py index d78ccf90b..fb4231bd1 100644 --- a/skyvern/webeye/actions/handler.py +++ b/skyvern/webeye/actions/handler.py @@ -358,7 +358,47 @@ async def handle_click_action( return [ActionFailure(InteractWithDisabledElement(skyvern_element.get_id()))] if action.download: - results = await handle_click_to_download_file_action(action, page, scraped_page, task, step) + # get the initial page count + browser_state = app.BROWSER_MANAGER.get_for_task(task.task_id, workflow_run_id=task.workflow_run_id) + initial_page_count = 0 + if browser_state is not None: + initial_page_count = len(browser_state.browser_context.pages if browser_state.browser_context else []) + LOG.info( + "Page count before download file action", + initial_page_count=initial_page_count, + task_id=task.task_id, + step_id=step.step_id, + workflow_run_id=task.workflow_run_id, + ) + try: + results = await handle_click_to_download_file_action(action, page, scraped_page, task, step) + except Exception: + raise + finally: + # get the page count after download + page_count_after_download = 0 + if browser_state is not None: + page_count_after_download = len( + browser_state.browser_context.pages if browser_state.browser_context else [] + ) + + LOG.info( + "Page count after download file action", + initial_page_count=initial_page_count, + page_count_after_download=page_count_after_download, + task_id=task.task_id, + step_id=step.step_id, + 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, + ) + # close the extra page + await browser_state.browser_context.pages[-1].close() else: results = await chain_click( task, diff --git a/skyvern/webeye/browser_factory.py b/skyvern/webeye/browser_factory.py index 3de70e362..594f5a2d2 100644 --- a/skyvern/webeye/browser_factory.py +++ b/skyvern/webeye/browser_factory.py @@ -63,10 +63,9 @@ async def browser_console_log(msg: ConsoleMessage) -> None: def set_download_file_listener(browser_context: BrowserContext, **kwargs: Any) -> None: async def listen_to_download(download: Download) -> None: + workflow_run_id = kwargs.get("workflow_run_id") + task_id = kwargs.get("task_id") try: - workflow_run_id = kwargs.get("workflow_run_id") - task_id = kwargs.get("task_id") - async with asyncio.timeout(BROWSER_DOWNLOAD_TIMEOUT): file_path = await download.path() if file_path.suffix: diff --git a/skyvern/webeye/scraper/domUtils.js b/skyvern/webeye/scraper/domUtils.js index 57ad903bd..f94e8900a 100644 --- a/skyvern/webeye/scraper/domUtils.js +++ b/skyvern/webeye/scraper/domUtils.js @@ -1134,11 +1134,7 @@ function buildElementObject(frame, element, interactable, purgeable = false) { } if (elementTagNameLower === "input" || elementTagNameLower === "textarea") { - if (element.type === "password") { - attrs["value"] = element.value ? "*".repeat(element.value.length) : ""; - } else { - attrs["value"] = element.value; - } + attrs["value"] = element.value; } let elementObj = { From 9b9edbb87cf78c10df9e6083b12ffc39310728af Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Tue, 17 Dec 2024 01:49:14 -0800 Subject: [PATCH 2/3] undo --- skyvern/webeye/scraper/domUtils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/skyvern/webeye/scraper/domUtils.js b/skyvern/webeye/scraper/domUtils.js index f94e8900a..57ad903bd 100644 --- a/skyvern/webeye/scraper/domUtils.js +++ b/skyvern/webeye/scraper/domUtils.js @@ -1134,7 +1134,11 @@ function buildElementObject(frame, element, interactable, purgeable = false) { } if (elementTagNameLower === "input" || elementTagNameLower === "textarea") { - attrs["value"] = element.value; + if (element.type === "password") { + attrs["value"] = element.value ? "*".repeat(element.value.length) : ""; + } else { + attrs["value"] = element.value; + } } let elementObj = { From 03b18fe3ebe2bfd004cd0b54059f916116310c30 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Tue, 17 Dec 2024 01:52:31 -0800 Subject: [PATCH 3/3] add warning --- skyvern/webeye/actions/handler.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py index fb4231bd1..834b741ed 100644 --- a/skyvern/webeye/actions/handler.py +++ b/skyvern/webeye/actions/handler.py @@ -397,6 +397,13 @@ async def handle_click_action( 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: