Skip to content

Commit 0d1fac8

Browse files
authored
Merge pull request #15 from browserbase/miguel/stg-172-remove-api-healthcheck-from-python-sdk
remove healthcheck ping
2 parents 5b90b7b + d1f2eba commit 0d1fac8

File tree

2 files changed

+8
-71
lines changed

2 files changed

+8
-71
lines changed

stagehand/client.py

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,15 @@ async def init(self):
151151
timeout=self.timeout_settings
152152
)
153153

154-
# Check server health
155-
await self._check_server_health()
156-
157154
# Create session if we don't have one
158155
if not self.session_id:
159156
await self._create_session()
160157
self._log(f"Created new session: {self.session_id}", level=3)
161158

159+
###
160+
# TODO: throw log for unauthorized (401) key not whitelisted
161+
###
162+
162163
# Start Playwright and connect to remote
163164
self._log("Starting Playwright...", level=3)
164165
self._playwright = await async_playwright().start()
@@ -237,42 +238,6 @@ async def close(self):
237238

238239
self._closed = True
239240

240-
async def _check_server_health(self, timeout: int = 10):
241-
"""
242-
Ping /healthcheck to verify the server is available.
243-
Uses exponential backoff for retries.
244-
"""
245-
start = time.time()
246-
attempt = 0
247-
while True:
248-
try:
249-
client = self.httpx_client or httpx.AsyncClient(
250-
timeout=self.timeout_settings
251-
)
252-
async with client:
253-
headers = {
254-
"x-bb-api-key": self.browserbase_api_key,
255-
}
256-
resp = await client.get(
257-
f"{self.server_url}/healthcheck", headers=headers
258-
)
259-
if resp.status_code == 200:
260-
data = resp.json()
261-
if data.get("status") == "ok":
262-
self._log("Healthcheck passed. Server is running.", level=3)
263-
return
264-
except Exception as e:
265-
self._log(f"Healthcheck error: {str(e)}", level=3)
266-
267-
if time.time() - start > timeout:
268-
raise TimeoutError(f"Server not responding after {timeout} seconds.")
269-
270-
wait_time = min(
271-
2**attempt * 0.5, 5.0
272-
) # Exponential backoff, capped at 5 seconds
273-
await asyncio.sleep(wait_time)
274-
attempt += 1
275-
276241
async def _create_session(self):
277242
"""
278243
Create a new session by calling /sessions/start on the server.

stagehand/sync/client.py

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ def init(self):
7272
if not self._client:
7373
self._client = requests.Session()
7474

75-
# Check server health
76-
self._check_server_health()
77-
7875
# Create session if we don't have one
7976
if not self.session_id:
8077
self._create_session()
8178
self._log(f"Created new session: {self.session_id}", level=3)
8279

80+
###
81+
# TODO: throw log for unauthorized (401) key not whitelisted
82+
###
83+
8384
# Start Playwright and connect to remote
8485
self._log("Starting Playwright...", level=3)
8586
self._playwright = sync_playwright().start()
@@ -152,35 +153,6 @@ def close(self):
152153

153154
self._closed = True
154155

155-
def _check_server_health(self, timeout: int = 10):
156-
"""
157-
Check server health synchronously with exponential backoff.
158-
"""
159-
start = time.time()
160-
attempt = 0
161-
while True:
162-
try:
163-
headers = {
164-
"x-bb-api-key": self.browserbase_api_key,
165-
}
166-
resp = self._client.get(
167-
f"{self.server_url}/healthcheck", headers=headers
168-
)
169-
if resp.status_code == 200:
170-
data = resp.json()
171-
if data.get("status") == "ok":
172-
self._log("Healthcheck passed. Server is running.", level=3)
173-
return
174-
except Exception as e:
175-
self._log(f"Healthcheck error: {str(e)}", level=3)
176-
177-
if time.time() - start > timeout:
178-
raise TimeoutError(f"Server not responding after {timeout} seconds.")
179-
180-
wait_time = min(2**attempt * 0.5, 5.0)
181-
time.sleep(wait_time)
182-
attempt += 1
183-
184156
def _create_session(self):
185157
"""
186158
Create a new session synchronously.

0 commit comments

Comments
 (0)