Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close the new page/window opened by file download action #1404

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion skyvern/webeye/actions/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
wintonzheng marked this conversation as resolved.
Show resolved Hide resolved
else:
results = await chain_click(
task,
Expand Down
5 changes: 2 additions & 3 deletions skyvern/webeye/browser_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions skyvern/webeye/scraper/domUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you revert this change? it looks like something weired happened in syng PR 😂

}

let elementObj = {
Expand Down
Loading