cancel stop loading window (#535)

This commit is contained in:
LawyZheng
2024-07-02 12:33:09 +08:00
committed by GitHub
parent 257ba1601e
commit 98713b0584
2 changed files with 11 additions and 11 deletions

View File

@@ -876,24 +876,24 @@ class ForgeAgent:
# Scrape the web page and get the screenshot and the elements
# HACK: try scrape_website three time to handle screenshot timeout
# first time: normal scrape to take screenshot
# second time: stop window loading before scraping
# second time: try again the normal scrape, (stopping window loading before scraping barely helps, but causing problem)
# third time: reload the page before scraping
scraped_page: ScrapedPage | None = None
for scrape_type in SCRAPE_TYPE_ORDER:
for idx, scrape_type in enumerate(SCRAPE_TYPE_ORDER):
try:
scraped_page = await self._scrape_with_type(
task=task, step=step, browser_state=browser_state, scrape_type=scrape_type
)
break
except FailedToTakeScreenshot as e:
if scrape_type == ScrapeType.RELOAD:
LOG.error(
"Failed to take screenshot after stop-loading and reload-page retry",
task_id=task.task_id,
step_id=step.step_id,
)
raise e
continue
if idx < len(SCRAPE_TYPE_ORDER) - 1:
continue
LOG.error(
"Failed to take screenshot after two normal attemps and reload-page retry",
task_id=task.task_id,
step_id=step.step_id,
)
raise e
if scraped_page is None:
raise EmptyScrapePage