Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat: support browser session startup URL (#7029)
Sardor Taylakov8934cf87088a
diff --git a/docs/api-reference/openapi.json b/docs/api-reference/openapi.jsonindex 96a2bc976..4105efa22 100644--- a/docs/api-reference/openapi.json+++ b/docs/api-reference/openapi.json@@ -11093,6 +11093,18 @@},"CreateBrowserSessionRequest": {"properties": {+ "url": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Url",+ "description": "Optional URL to open when the standalone browser session starts."+ },"timeout": {"anyOf": [{diff --git a/fern/browser-sessions/introduction.mdx b/fern/browser-sessions/introduction.mdxindex fa43dda3e..58b7a9fc7 100644--- a/fern/browser-sessions/introduction.mdx+++ b/fern/browser-sessions/introduction.mdx@@ -19,10 +19,12 @@ from skyvern import Skyvernskyvern = Skyvern(api_key="YOUR_API_KEY")browser_session = await skyvern.create_browser_session(+ url="https://example.com",timeout=60,)```+- The `url` parameter opens the browser session to that page when the session starts. Omit it to start from a blank page.- The `timeout` parameter (`>=5, <=10080`) is the max time in minutes that the browser session can run. By default, the timeout is 60 minutes.- The `browser_session_id` the session ID you should note.@@ -48,4 +50,4 @@ skyvern = Skyvern(api_key="YOUR_API_KEY")await skyvern.close_browser_session(browser_session_id="YOUR_BROWSER_SESSION_ID",)-```\ No newline at end of file+```diff --git a/fern/openapi/skyvern_openapi.json b/fern/openapi/skyvern_openapi.jsonindex 515c267f6..c064e2eb4 100644--- a/fern/openapi/skyvern_openapi.json+++ b/fern/openapi/skyvern_openapi.json@@ -10698,6 +10698,18 @@},"CreateBrowserSessionRequest": {"properties": {+ "url": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Url",+ "description": "Optional URL to open when the standalone browser session starts."+ },"timeout": {"anyOf": [{diff --git a/skyvern-ts/client/src/api/client/requests/CreateBrowserSessionRequest.ts b/skyvern-ts/client/src/api/client/requests/CreateBrowserSessionRequest.tsindex 947624f7a..64bc46fb5 100644--- a/skyvern-ts/client/src/api/client/requests/CreateBrowserSessionRequest.ts+++ b/skyvern-ts/client/src/api/client/requests/CreateBrowserSessionRequest.ts@@ -7,6 +7,8 @@ import type * as Skyvern from "../../index.js";* {}*/export interface CreateBrowserSessionRequest {+ /** Optional URL to open when the standalone browser session starts. */+ url?: string;/** Timeout in minutes for the session. Timeout is applied after the session is started. Must be between 5 and 1440. Defaults to 60. */timeout?: number;/**diff --git a/skyvern/client/client.py b/skyvern/client/client.pyindex db102f1d0..c6ccfd591 100644--- a/skyvern/client/client.py+++ b/skyvern/client/client.py@@ -2135,6 +2135,7 @@ class Skyvern:def create_browser_session(self,*,+ url: typing.Optional[str] = OMIT,timeout: typing.Optional[int] = OMIT,proxy_location: typing.Optional[CreateBrowserSessionRequestProxyLocation] = OMIT,proxy_session_id: typing.Optional[str] = OMIT,@@ -2149,6 +2150,9 @@ class Skyvern:Parameters----------+ url : typing.Optional[str]+ Optional URL to open when the standalone browser session starts.+timeout : typing.Optional[int]Timeout in minutes for the session. Timeout is applied after the session is started. Must be between 5 and 1440. Defaults to 60.@@ -2222,6 +2226,7 @@ class Skyvern:client.create_browser_session()"""_response = self._raw_client.create_browser_session(+ url=url,timeout=timeout,proxy_location=proxy_location,proxy_session_id=proxy_session_id,@@ -6285,6 +6290,7 @@ class AsyncSkyvern:async def create_browser_session(self,*,+ url: typing.Optional[str] = OMIT,timeout: typing.Optional[int] = OMIT,proxy_location: typing.Optional[CreateBrowserSessionRequestProxyLocation] = OMIT,proxy_session_id: typing.Optional[str] = OMIT,@@ -6299,6 +6305,9 @@ class AsyncSkyvern:Parameters----------+ url : typing.Optional[str]+ Optional URL to open when the standalone browser session starts.+timeout : typing.Optional[int]Timeout in minutes for the session. Timeout is applied after the session is started. Must be between 5 and 1440. Defaults to 60.@@ -6380,6 +6389,7 @@ class AsyncSkyvern:asyncio.run(main())"""_response = await self._raw_client.create_browser_session(+ url=url,timeout=timeout,proxy_location=proxy_location,proxy_session_id=proxy_session_id,diff --git a/skyvern/client/raw_client.py b/skyvern/client/raw_client.pyindex 66b8141a3..d008055ed 100644--- a/skyvern/client/raw_client.py+++ b/skyvern/client/raw_client.py@@ -3193,6 +3193,7 @@ class RawSkyvern:def create_browser_session(self,*,+ url: typing.Optional[str] = OMIT,timeout: typing.Optional[int] = OMIT,proxy_location: typing.Optional[CreateBrowserSessionRequestProxyLocation] = OMIT,proxy_session_id: typing.Optional[str] = OMIT,@@ -3207,6 +3208,9 @@ class RawSkyvern:Parameters----------+ url : typing.Optional[str]+ Optional URL to open when the standalone browser session starts.+timeout : typing.Optional[int]Timeout in minutes for the session. Timeout is applied after the session is started. Must be between 5 and 1440. Defaults to 60.@@ -3274,6 +3278,7 @@ class RawSkyvern:"v1/browser_sessions",method="POST",json={+ "url": url,"timeout": timeout,"proxy_location": convert_and_respect_annotation_metadata(object_=proxy_location, annotation=CreateBrowserSessionRequestProxyLocation, direction="write"@@ -8793,6 +8798,7 @@ class AsyncRawSkyvern:async def create_browser_session(self,*,+ url: typing.Optional[str] = OMIT,timeout: typing.Optional[int] = OMIT,proxy_location: typing.Optional[CreateBrowserSessionRequestProxyLocation] = OMIT,proxy_session_id: typing.Optional[str] = OMIT,@@ -8807,6 +8813,9 @@ class AsyncRawSkyvern:Parameters----------+ url : typing.Optional[str]+ Optional URL to open when the standalone browser session starts.+timeout : typing.Optional[int]Timeout in minutes for the session. Timeout is applied after the session is started. Must be between 5 and 1440. Defaults to 60.@@ -8874,6 +8883,7 @@ class AsyncRawSkyvern:"v1/browser_sessions",method="POST",json={+ "url": url,"timeout": timeout,"proxy_location": convert_and_respect_annotation_metadata(object_=proxy_location, annotation=CreateBrowserSessionRequestProxyLocation, direction="write"diff --git a/skyvern/forge/sdk/routes/browser_sessions.py b/skyvern/forge/sdk/routes/browser_sessions.pyindex 9b8edc96a..4b37a0f05 100644--- a/skyvern/forge/sdk/routes/browser_sessions.py+++ b/skyvern/forge/sdk/routes/browser_sessions.py@@ -201,6 +201,7 @@ async def create_browser_session(browser_session = await app.PERSISTENT_SESSIONS_MANAGER.create_session(organization_id=current_org.organization_id,+ url=browser_session_request.url,timeout_minutes=browser_session_request.timeout,proxy_location=proxy_location,proxy_session_id=proxy_session_id,diff --git a/skyvern/schemas/browser_sessions.py b/skyvern/schemas/browser_sessions.pyindex 4a38060f0..47cc9e2fb 100644--- a/skyvern/schemas/browser_sessions.py+++ b/skyvern/schemas/browser_sessions.py@@ -8,9 +8,22 @@ from skyvern.schemas.docs.doc_strings import PROXY_LOCATION_DOC_STRINGfrom skyvern.schemas.proxy_pinning import validate_proxy_session_idfrom skyvern.schemas.runs import GeoTarget, ProxyLocationInputfrom skyvern.services.browser_recording.types import RecordingDraftStep+from skyvern.utils.url_validators import validate_urlclass CreateBrowserSessionRequest(BaseModel):+ url: str | None = Field(+ default=None,+ description="Optional URL to open when the standalone browser session starts.",+ )++ @field_validator("url")+ @classmethod+ def validate_start_url(cls, value: str | None) -> str | None:+ if not value:+ return value+ return validate_url(value)+timeout: int | None = Field(default=DEFAULT_TIMEOUT,description=f"Timeout in minutes for the session. Timeout is applied after the session is started. Must be between {MIN_TIMEOUT} and {MAX_TIMEOUT}. Defaults to {DEFAULT_TIMEOUT}.",diff --git a/tests/unit/test_browser_session_profile_export_gate.py b/tests/unit/test_browser_session_profile_export_gate.pyindex e84a4679f..cbff8106f 100644--- a/tests/unit/test_browser_session_profile_export_gate.py+++ b/tests/unit/test_browser_session_profile_export_gate.py@@ -1,5 +1,11 @@from datetime import datetime+from types import SimpleNamespace+from unittest.mock import AsyncMock, MagicMock, patch+import pytest++from skyvern.exceptions import SkyvernHTTPException+from skyvern.forge.sdk.routes import browser_sessions as browser_sessions_modfrom skyvern.forge.sdk.schemas.persistent_browser_sessions import (PersistentBrowserSession,export_profile_storage_id,@@ -38,6 +44,53 @@ def test_create_request_defaults_to_opt_out() -> None:assert CreateBrowserSessionRequest().generate_browser_profile is False+def test_create_request_accepts_start_url() -> None:+ request = CreateBrowserSessionRequest(url="https://example.com/path", generate_browser_profile=True)++ assert request.url == "https://example.com/path"+++def test_create_request_rejects_invalid_start_url() -> None:+ with pytest.raises(SkyvernHTTPException):+ CreateBrowserSessionRequest(url="ftp://example.com")+++async def test_create_browser_session_passes_start_url_to_session_manager() -> None:+ created_session = SimpleNamespace(persistent_browser_session_id="pbs_1")+ response = SimpleNamespace(browser_session_id="pbs_1")+ app_mock = MagicMock()+ app_mock.PERSISTENT_SESSIONS_MANAGER.create_session = AsyncMock(return_value=created_session)+ from_browser_session = AsyncMock(return_value=response)++ with (+ patch.object(browser_sessions_mod, "app", app_mock),+ patch.object(browser_sessions_mod.BrowserSessionResponse, "from_browser_session", from_browser_session),+ ):+ result = await browser_sessions_mod.create_browser_session(+ CreateBrowserSessionRequest(+ url="https://example.com/login",+ timeout=120,+ generate_browser_profile=True,+ ),+ current_org=SimpleNamespace(organization_id="org_1"),+ )++ assert result is response+ app_mock.PERSISTENT_SESSIONS_MANAGER.create_session.assert_awaited_once_with(+ organization_id="org_1",+ url="https://example.com/login",+ timeout_minutes=120,+ proxy_location=None,+ proxy_session_id=None,+ extensions=None,+ browser_type=None,+ browser_profile_id=None,+ generate_browser_profile=True,+ )+ from_browser_session.assert_awaited_once_with(created_session)++def test_update_request_carries_flag() -> None:assert UpdateBrowserSessionRequest(generate_browser_profile=True).generate_browser_profile is Trueassert UpdateBrowserSessionRequest(generate_browser_profile=False).generate_browser_profile is False