[SKY-6974] Browser Profiles [2/3] Marc/backend browser session profiles (#3923)

This commit is contained in:
Marc Kelechava
2025-11-06 01:24:39 -08:00
committed by GitHub
parent f0172a22df
commit 3db5ec6cd7
24 changed files with 662 additions and 27 deletions

View File

@@ -664,6 +664,7 @@ class BrowserState:
organization_id: str | None = None,
extra_http_headers: dict[str, str] | None = None,
browser_address: str | None = None,
browser_profile_id: str | None = None,
) -> None:
if self.browser_context is None:
LOG.info("creating browser context")
@@ -681,6 +682,7 @@ class BrowserState:
organization_id=organization_id,
extra_http_headers=extra_http_headers,
browser_address=browser_address,
browser_profile_id=browser_profile_id,
)
self.browser_context = browser_context
self.browser_artifacts = browser_artifacts
@@ -844,6 +846,7 @@ class BrowserState:
organization_id: str | None = None,
extra_http_headers: dict[str, str] | None = None,
browser_address: str | None = None,
browser_profile_id: str | None = None,
) -> Page:
page = await self.get_working_page()
if page is not None:
@@ -859,6 +862,7 @@ class BrowserState:
organization_id=organization_id,
extra_http_headers=extra_http_headers,
browser_address=browser_address,
browser_profile_id=browser_profile_id,
)
except Exception as e:
error_message = str(e)
@@ -876,6 +880,7 @@ class BrowserState:
organization_id=organization_id,
extra_http_headers=extra_http_headers,
browser_address=browser_address,
browser_profile_id=browser_profile_id,
)
page = await self.__assert_page()
@@ -892,6 +897,7 @@ class BrowserState:
organization_id=organization_id,
extra_http_headers=extra_http_headers,
browser_address=browser_address,
browser_profile_id=browser_profile_id,
)
page = await self.__assert_page()
return page

View File

@@ -34,6 +34,7 @@ class BrowserManager:
organization_id: str | None = None,
extra_http_headers: dict[str, str] | None = None,
browser_address: str | None = None,
browser_profile_id: str | None = None,
) -> BrowserState:
pw = await async_playwright().start()
(
@@ -50,6 +51,7 @@ class BrowserManager:
organization_id=organization_id,
extra_http_headers=extra_http_headers,
browser_address=browser_address,
browser_profile_id=browser_profile_id,
)
return BrowserState(
pw=pw,
@@ -145,9 +147,12 @@ class BrowserManager:
workflow_run: WorkflowRun,
url: str | None = None,
browser_session_id: str | None = None,
browser_profile_id: str | None = None,
) -> BrowserState:
parent_workflow_run_id = workflow_run.parent_workflow_run_id
workflow_run_id = workflow_run.workflow_run_id
if browser_profile_id is None:
browser_profile_id = workflow_run.browser_profile_id
browser_state = self.get_for_workflow_run(
workflow_run_id=workflow_run_id, parent_workflow_run_id=parent_workflow_run_id
)
@@ -192,6 +197,7 @@ class BrowserManager:
organization_id=workflow_run.organization_id,
extra_http_headers=workflow_run.extra_http_headers,
browser_address=workflow_run.browser_address,
browser_profile_id=browser_profile_id,
)
if browser_session_id:
@@ -213,6 +219,7 @@ class BrowserManager:
organization_id=workflow_run.organization_id,
extra_http_headers=workflow_run.extra_http_headers,
browser_address=workflow_run.browser_address,
browser_profile_id=browser_profile_id,
)
return browser_state