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

@@ -15,4 +15,4 @@ class ScrapeType(StrEnum):
RELOAD = "reload" RELOAD = "reload"
SCRAPE_TYPE_ORDER = [ScrapeType.NORMAL, ScrapeType.STOPLOADING, ScrapeType.RELOAD] SCRAPE_TYPE_ORDER = [ScrapeType.NORMAL, ScrapeType.NORMAL, ScrapeType.RELOAD]

View File

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