fix recreate workflow browser (#673)

This commit is contained in:
LawyZheng
2024-08-05 14:45:55 +08:00
committed by GitHub
parent e4fd825497
commit 845ae8d3e4
2 changed files with 15 additions and 4 deletions

View File

@@ -200,6 +200,7 @@ class BrowserState:
url: str | None = None, url: str | None = None,
proxy_location: ProxyLocation | None = None, proxy_location: ProxyLocation | None = None,
task_id: str | None = None, task_id: str | None = None,
workflow_run_id: str | None = None,
) -> None: ) -> None:
if self.pw is None: if self.pw is None:
LOG.info("Starting playwright") LOG.info("Starting playwright")
@@ -216,6 +217,7 @@ class BrowserState:
url=url, url=url,
proxy_location=proxy_location, proxy_location=proxy_location,
task_id=task_id, task_id=task_id,
workflow_run_id=workflow_run_id,
) )
self.browser_context = browser_context self.browser_context = browser_context
self.browser_artifacts = browser_artifacts self.browser_artifacts = browser_artifacts
@@ -276,23 +278,30 @@ class BrowserState:
url: str | None = None, url: str | None = None,
proxy_location: ProxyLocation | None = None, proxy_location: ProxyLocation | None = None,
task_id: str | None = None, task_id: str | None = None,
workflow_run_id: str | None = None,
) -> Page: ) -> Page:
if self.page is not None: if self.page is not None:
return self.page return self.page
try: try:
await self.check_and_fix_state(url=url, proxy_location=proxy_location, task_id=task_id) await self.check_and_fix_state(
url=url, proxy_location=proxy_location, task_id=task_id, workflow_run_id=workflow_run_id
)
except Exception as e: except Exception as e:
error_message = str(e) error_message = str(e)
if "net::ERR" not in error_message: if "net::ERR" not in error_message:
raise e raise e
await self.close_current_open_page() await self.close_current_open_page()
await self.check_and_fix_state(url=url, proxy_location=proxy_location, task_id=task_id) await self.check_and_fix_state(
url=url, proxy_location=proxy_location, task_id=task_id, workflow_run_id=workflow_run_id
)
assert self.page is not None assert self.page is not None
if not await BrowserContextFactory.validate_browser_context(self.page): if not await BrowserContextFactory.validate_browser_context(self.page):
await self.close_current_open_page() await self.close_current_open_page()
await self.check_and_fix_state(url=url, proxy_location=proxy_location, task_id=task_id) await self.check_and_fix_state(
url=url, proxy_location=proxy_location, task_id=task_id, workflow_run_id=workflow_run_id
)
assert self.page is not None assert self.page is not None
return self.page return self.page

View File

@@ -84,7 +84,9 @@ class BrowserManager:
# The URL here is only used when creating a new page, and not when using an existing page. # The URL here is only used when creating a new page, and not when using an existing page.
# This will make sure browser_state.page is not None. # This will make sure browser_state.page is not None.
await browser_state.get_or_create_page(url=url, proxy_location=workflow_run.proxy_location) await browser_state.get_or_create_page(
url=url, proxy_location=workflow_run.proxy_location, workflow_run_id=workflow_run.workflow_run_id
)
self.pages[workflow_run.workflow_run_id] = browser_state self.pages[workflow_run.workflow_run_id] = browser_state
return browser_state return browser_state