bug fix - task v2 keeps going back to the original url (#4462)
This commit is contained in:
@@ -621,49 +621,46 @@ async def run_task_v2_helper(
|
|||||||
browser_session_id=browser_session_id,
|
browser_session_id=browser_session_id,
|
||||||
browser_profile_id=workflow_run.browser_profile_id,
|
browser_profile_id=workflow_run.browser_profile_id,
|
||||||
)
|
)
|
||||||
|
page = await browser_state.get_working_page()
|
||||||
fallback_occurred = False
|
should_fallback = False
|
||||||
if url != current_url:
|
# if page is None:
|
||||||
if page is None:
|
# page = await browser_state.get_or_create_page(
|
||||||
page = await browser_state.get_or_create_page(
|
# url=url,
|
||||||
url=url,
|
# proxy_location=workflow_run.proxy_location,
|
||||||
proxy_location=workflow_run.proxy_location,
|
# task_id=task_v2.task_id,
|
||||||
task_id=task_v2.task_id,
|
# workflow_run_id=workflow_run_id,
|
||||||
workflow_run_id=workflow_run_id,
|
# script_id=task_v2.script_id,
|
||||||
script_id=task_v2.script_id,
|
# organization_id=organization_id,
|
||||||
organization_id=organization_id,
|
# extra_http_headers=task_v2.extra_http_headers,
|
||||||
extra_http_headers=task_v2.extra_http_headers,
|
# browser_profile_id=workflow_run.browser_profile_id,
|
||||||
browser_profile_id=workflow_run.browser_profile_id,
|
# )
|
||||||
)
|
if page:
|
||||||
else:
|
current_url = await SkyvernFrame.get_url(page)
|
||||||
await browser_state.navigate_to_url(page, url)
|
|
||||||
|
|
||||||
page_loaded = False
|
page_loaded = False
|
||||||
if page:
|
try:
|
||||||
try:
|
# Check if the page has a body element to verify it loaded
|
||||||
# Check if the page has a body element to verify it loaded
|
# page will always be None if browser state failed to load
|
||||||
# page will always be None if browser state failed to load
|
page_loaded = await browser_state.validate_browser_context(page)
|
||||||
page_loaded = await browser_state.validate_browser_context(page)
|
except Exception:
|
||||||
except Exception:
|
page_loaded = False
|
||||||
page_loaded = False
|
LOG.warning(
|
||||||
LOG.warning(
|
"Page failed to load properly, fallback to Google",
|
||||||
"Page failed to load properly, fallback to Google",
|
exc_info=True,
|
||||||
exc_info=True,
|
url=url,
|
||||||
url=url,
|
current_url=current_url,
|
||||||
current_url=current_url,
|
)
|
||||||
)
|
|
||||||
|
|
||||||
if not page_loaded:
|
if not page_loaded:
|
||||||
# Page failed to load properly, fallback to Google
|
# Page failed to load properly, fallback to Google
|
||||||
if page:
|
if page:
|
||||||
try:
|
try:
|
||||||
await page.goto(fallback_url, timeout=settings.BROWSER_LOADING_TIMEOUT_MS)
|
await page.goto(fallback_url, timeout=settings.BROWSER_LOADING_TIMEOUT_MS)
|
||||||
fallback_occurred = True
|
should_fallback = True
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.exception("Failed to load Google fallback", exc_info=True, url=url, current_url=current_url)
|
LOG.exception("Failed to load Google fallback", exc_info=True, url=url, current_url=current_url)
|
||||||
|
|
||||||
if i == 0 and current_url != url:
|
if i == 0 and current_url != url:
|
||||||
if fallback_occurred:
|
if should_fallback:
|
||||||
plan = f"Go to Google because the intended website ({url}) failed to load properly."
|
plan = f"Go to Google because the intended website ({url}) failed to load properly."
|
||||||
task_type = "goto_url"
|
task_type = "goto_url"
|
||||||
task_history_record = {"type": task_type, "task": plan}
|
task_history_record = {"type": task_type, "task": plan}
|
||||||
|
|||||||
Reference in New Issue
Block a user