@@ -88,27 +88,7 @@ def __init__(
88
88
self .wait_for_captcha_solves = self .config .wait_for_captcha_solves
89
89
self .system_prompt = self .config .system_prompt
90
90
self .verbose = self .config .verbose
91
-
92
- # Smart environment detection
93
- if self .config .env :
94
- self .env = self .config .env .upper ()
95
- else :
96
- # Auto-detect environment based on available configuration
97
- has_browserbase_config = bool (
98
- self .browserbase_api_key and self .browserbase_project_id
99
- )
100
- has_local_config = bool (self .config .local_browser_launch_options )
101
-
102
- if has_local_config and not has_browserbase_config :
103
- # Local browser options specified but no Browserbase config
104
- self .env = "LOCAL"
105
- elif not has_browserbase_config and not has_local_config :
106
- # No configuration specified, default to LOCAL for easier local development
107
- self .env = "LOCAL"
108
- else :
109
- # Default to BROWSERBASE if Browserbase config is available
110
- self .env = "BROWSERBASE"
111
-
91
+ self .env = self .config .env .upper () if self .config .env else "BROWSERBASE"
112
92
self .local_browser_launch_options = (
113
93
self .config .local_browser_launch_options or {}
114
94
)
@@ -218,14 +198,9 @@ def cleanup_handler(sig, frame):
218
198
return
219
199
220
200
self .__class__ ._cleanup_called = True
221
- if self .env == "BROWSERBASE" :
222
- print (
223
- f"\n [{ signal .Signals (sig ).name } ] received. Ending Browserbase session..."
224
- )
225
- else :
226
- print (
227
- f"\n [{ signal .Signals (sig ).name } ] received. Cleaning up Stagehand resources..."
228
- )
201
+ print (
202
+ f"\n [{ signal .Signals (sig ).name } ] received. Ending Browserbase session..."
203
+ )
229
204
230
205
try :
231
206
# Try to get the current event loop
@@ -264,15 +239,9 @@ async def _async_cleanup(self):
264
239
"""Async cleanup method called from signal handler."""
265
240
try :
266
241
await self .close ()
267
- if self .env == "BROWSERBASE" and self .session_id :
268
- print (f"Session { self .session_id } ended successfully" )
269
- else :
270
- print ("Stagehand resources cleaned up successfully" )
242
+ print (f"Session { self .session_id } ended successfully" )
271
243
except Exception as e :
272
- if self .env == "BROWSERBASE" :
273
- print (f"Error ending Browserbase session: { str (e )} " )
274
- else :
275
- print (f"Error cleaning up Stagehand resources: { str (e )} " )
244
+ print (f"Error ending Browserbase session: { str (e )} " )
276
245
finally :
277
246
# Force exit after cleanup completes (or fails)
278
247
# Use os._exit to avoid any further Python cleanup that might hang
0 commit comments