@@ -148,7 +148,7 @@ async def run_org_agent(
148
148
max_steps ,
149
149
use_vision ,
150
150
max_actions_per_step ,
151
- tool_call_in_content ,
151
+ tool_call_in_content
152
152
):
153
153
try :
154
154
global _global_browser , _global_browser_context
@@ -234,10 +234,7 @@ async def run_custom_agent(
234
234
use_vision ,
235
235
max_actions_per_step ,
236
236
tool_call_in_content
237
- ):
238
- controller = CustomController ()
239
- persistence_config = BrowserPersistenceConfig .from_env ()
240
-
237
+ ):
241
238
try :
242
239
global _global_browser , _global_browser_context
243
240
@@ -252,7 +249,7 @@ async def run_custom_agent(
252
249
253
250
# Initialize global browser if needed
254
251
if _global_browser is None :
255
- browser = CustomBrowser (
252
+ _global_browser = CustomBrowser (
256
253
config = BrowserConfig (
257
254
headless = headless ,
258
255
disable_security = disable_security ,
@@ -283,7 +280,7 @@ async def run_custom_agent(
283
280
record_video_dir = save_recording_path if save_recording_path else None ,
284
281
record_video_size = {"width" : window_w , "height" : window_h },
285
282
)
286
- browser_context = await browser .new_context (
283
+ browser_context = await _global_browser .new_context (
287
284
config = BrowserContextConfig (
288
285
trace_path = save_trace_path if save_trace_path else None ,
289
286
save_recording_path = save_recording_path if save_recording_path else None ,
@@ -295,7 +292,7 @@ async def run_custom_agent(
295
292
)
296
293
else :
297
294
if _global_browser_context is None :
298
- browser_context = await browser .new_context (
295
+ browser_context = await _global_browser .new_context (
299
296
config = BrowserContextConfig (
300
297
trace_path = save_trace_path if save_trace_path else None ,
301
298
save_recording_path = save_recording_path if save_recording_path else None ,
@@ -346,8 +343,8 @@ async def run_custom_agent(
346
343
await playwright .stop ()
347
344
playwright = None
348
345
349
- if browser :
350
- await browser .close ()
346
+ if _global_browser :
347
+ await _global_browser .close ()
351
348
browser = None
352
349
return final_result , errors , model_actions , model_thoughts , trace_file .get ('.webm' ), recorded_files .get ('.zip' )
353
350
0 commit comments