Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions browserbase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import httpx
from playwright.sync_api import sync_playwright
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, TypeAdapter

BrowserType = Literal["chrome", "firefox", "edge", "safari"]
DeviceType = Literal["desktop", "mobile"]
Expand Down Expand Up @@ -148,7 +148,7 @@ def list_sessions(self) -> list[Session]:

response.raise_for_status()
data = response.json()
return [Session(**item) for item in data]
return TypeAdapter(list[Session]).validate_python(data)

def create_session(self, options: Optional[CreateSessionOptions] = None) -> Session:
payload = {"projectId": self.project_id}
Expand All @@ -170,7 +170,7 @@ def create_session(self, options: Optional[CreateSessionOptions] = None) -> Sess
)

response.raise_for_status()
return Session(**response.json())
return TypeAdapter(Session).validate_python(response.json())

def complete_session(self, session_id: str) -> Session:
if not session_id or session_id == "":
Expand All @@ -194,7 +194,7 @@ def complete_session(self, session_id: str) -> Session:
)

response.raise_for_status()
return Session(**response.json())
return TypeAdapter(Session).validate_python(response.json())

def get_session(self, session_id: str) -> Session:
response = httpx.get(
Expand All @@ -206,7 +206,7 @@ def get_session(self, session_id: str) -> Session:
)

response.raise_for_status()
return Session(**response.json())
return TypeAdapter(Session).validate_python(response.json())

def get_session_recording(self, session_id: str) -> list[SessionRecording]:
response = httpx.get(
Expand All @@ -219,7 +219,7 @@ def get_session_recording(self, session_id: str) -> list[SessionRecording]:

response.raise_for_status()
data = response.json()
return [SessionRecording(**item) for item in data]
return TypeAdapter(list[SessionRecording]).validate_python(data)

def get_session_downloads(
self, session_id: str, retry_interval: int = 2000, retry_count: int = 2
Expand Down Expand Up @@ -255,7 +255,7 @@ def get_debug_connection_urls(self, session_id: str) -> DebugConnectionURLs:
)

response.raise_for_status()
return DebugConnectionURLs(**response.json())
return TypeAdapter(DebugConnectionURLs).validate_python(response.json())

def get_session_logs(self, session_id: str) -> list[SessionLog]:
response = httpx.get(
Expand All @@ -268,7 +268,7 @@ def get_session_logs(self, session_id: str) -> list[SessionLog]:

response.raise_for_status()
data = response.json()
return [SessionLog(**item) for item in data]
return TypeAdapter(list[SessionLog]).validate_python(data)

def load(self, url: Union[str, Sequence[str]], **args):
if isinstance(url, str):
Expand Down