Skip to content

Commit 5acb194

Browse files
committed
2 parents 5385cf3 + 089bcbb commit 5acb194

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

‎browserbase/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import httpx
66
from playwright.sync_api import sync_playwright
7-
from pydantic import BaseModel, Field
7+
from pydantic import BaseModel, Field, TypeAdapter
88

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

149149
response.raise_for_status()
150150
data = response.json()
151-
return [Session(**item) for item in data]
151+
return TypeAdapter(list[Session]).validate_python(data)
152152

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

172172
response.raise_for_status()
173-
return Session(**response.json())
173+
return TypeAdapter(Session).validate_python(response.json())
174174

175175
def complete_session(self, session_id: str) -> Session:
176176
if not session_id or session_id == "":
@@ -194,7 +194,7 @@ def complete_session(self, session_id: str) -> Session:
194194
)
195195

196196
response.raise_for_status()
197-
return Session(**response.json())
197+
return TypeAdapter(Session).validate_python(response.json())
198198

199199
def get_session(self, session_id: str) -> Session:
200200
response = httpx.get(
@@ -206,7 +206,7 @@ def get_session(self, session_id: str) -> Session:
206206
)
207207

208208
response.raise_for_status()
209-
return Session(**response.json())
209+
return TypeAdapter(Session).validate_python(response.json())
210210

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

220220
response.raise_for_status()
221221
data = response.json()
222-
return [SessionRecording(**item) for item in data]
222+
return TypeAdapter(list[SessionRecording]).validate_python(data)
223223

224224
def get_session_downloads(
225225
self, session_id: str, retry_interval: int = 2000, retry_count: int = 2
@@ -255,7 +255,7 @@ def get_debug_connection_urls(self, session_id: str) -> DebugConnectionURLs:
255255
)
256256

257257
response.raise_for_status()
258-
return DebugConnectionURLs(**response.json())
258+
return TypeAdapter(DebugConnectionURLs).validate_python(response.json())
259259

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

269269
response.raise_for_status()
270270
data = response.json()
271-
return [SessionLog(**item) for item in data]
271+
return TypeAdapter(list[SessionLog]).validate_python(data)
272272

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

0 commit comments

Comments
 (0)