Skip to content

Commit

Permalink
fix recreate workflow browser (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
LawyZheng authored Aug 5, 2024
1 parent e4fd825 commit 845ae8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions skyvern/webeye/browser_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ async def check_and_fix_state(
url: str | None = None,
proxy_location: ProxyLocation | None = None,
task_id: str | None = None,
workflow_run_id: str | None = None,
) -> None:
if self.pw is None:
LOG.info("Starting playwright")
Expand All @@ -216,6 +217,7 @@ async def check_and_fix_state(
url=url,
proxy_location=proxy_location,
task_id=task_id,
workflow_run_id=workflow_run_id,
)
self.browser_context = browser_context
self.browser_artifacts = browser_artifacts
Expand Down Expand Up @@ -276,23 +278,30 @@ async def get_or_create_page(
url: str | None = None,
proxy_location: ProxyLocation | None = None,
task_id: str | None = None,
workflow_run_id: str | None = None,
) -> Page:
if self.page is not None:
return self.page

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:
error_message = str(e)
if "net::ERR" not in error_message:
raise e
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

if not await BrowserContextFactory.validate_browser_context(self.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

return self.page
Expand Down
4 changes: 3 additions & 1 deletion skyvern/webeye/browser_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ async def get_or_create_for_workflow_run(self, workflow_run: WorkflowRun, url: s

# 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.
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
return browser_state
Expand Down

0 comments on commit 845ae8d

Please sign in to comment.