@@ -143,7 +143,8 @@ async def run_browser_agent(
143
143
max_steps ,
144
144
use_vision ,
145
145
max_actions_per_step ,
146
- tool_calling_method
146
+ tool_calling_method ,
147
+ chrome_cdp
147
148
):
148
149
global _global_agent_state
149
150
_global_agent_state .clear_stop () # Clear any previous stop requests
@@ -192,7 +193,8 @@ async def run_browser_agent(
192
193
max_steps = max_steps ,
193
194
use_vision = use_vision ,
194
195
max_actions_per_step = max_actions_per_step ,
195
- tool_calling_method = tool_calling_method
196
+ tool_calling_method = tool_calling_method ,
197
+ chrome_cdp = chrome_cdp
196
198
)
197
199
elif agent_type == "custom" :
198
200
final_result , errors , model_actions , model_thoughts , trace_file , history_file = await run_custom_agent (
@@ -211,7 +213,8 @@ async def run_browser_agent(
211
213
max_steps = max_steps ,
212
214
use_vision = use_vision ,
213
215
max_actions_per_step = max_actions_per_step ,
214
- tool_calling_method = tool_calling_method
216
+ tool_calling_method = tool_calling_method ,
217
+ chrome_cdp = chrome_cdp
215
218
)
216
219
else :
217
220
raise ValueError (f"Invalid agent type: { agent_type } " )
@@ -273,7 +276,8 @@ async def run_org_agent(
273
276
max_steps ,
274
277
use_vision ,
275
278
max_actions_per_step ,
276
- tool_calling_method
279
+ tool_calling_method ,
280
+ chrome_cdp
277
281
):
278
282
try :
279
283
global _global_browser , _global_browser_context , _global_agent_state , _global_agent
@@ -282,9 +286,10 @@ async def run_org_agent(
282
286
_global_agent_state .clear_stop ()
283
287
284
288
extra_chromium_args = [f"--window-size={ window_w } ,{ window_h } " ]
285
- cdp_url = None
289
+ cdp_url = chrome_cdp
290
+
286
291
if use_own_browser :
287
- cdp_url = os .getenv ("CHROME_CDP" , None )
292
+ cdp_url = os .getenv ("CHROME_CDP" , chrome_cdp )
288
293
chrome_path = os .getenv ("CHROME_PATH" , None )
289
294
if chrome_path == "" :
290
295
chrome_path = None
@@ -295,6 +300,7 @@ async def run_org_agent(
295
300
chrome_path = None
296
301
297
302
if _global_browser is None :
303
+
298
304
_global_browser = Browser (
299
305
config = BrowserConfig (
300
306
headless = headless ,
@@ -310,6 +316,7 @@ async def run_org_agent(
310
316
config = BrowserContextConfig (
311
317
trace_path = save_trace_path if save_trace_path else None ,
312
318
save_recording_path = save_recording_path if save_recording_path else None ,
319
+ cdp_url = cdp_url ,
313
320
no_viewport = False ,
314
321
browser_window_size = BrowserContextWindowSize (
315
322
width = window_w , height = window_h
@@ -373,7 +380,8 @@ async def run_custom_agent(
373
380
max_steps ,
374
381
use_vision ,
375
382
max_actions_per_step ,
376
- tool_calling_method
383
+ tool_calling_method ,
384
+ chrome_cdp
377
385
):
378
386
try :
379
387
global _global_browser , _global_browser_context , _global_agent_state , _global_agent
@@ -382,9 +390,9 @@ async def run_custom_agent(
382
390
_global_agent_state .clear_stop ()
383
391
384
392
extra_chromium_args = [f"--window-size={ window_w } ,{ window_h } " ]
385
- cdp_url = None
393
+ cdp_url = chrome_cdp
386
394
if use_own_browser :
387
- cdp_url = os .getenv ("CHROME_CDP" , None )
395
+ cdp_url = os .getenv ("CHROME_CDP" , chrome_cdp )
388
396
389
397
chrome_path = os .getenv ("CHROME_PATH" , None )
390
398
if chrome_path == "" :
@@ -398,7 +406,8 @@ async def run_custom_agent(
398
406
controller = CustomController ()
399
407
400
408
# Initialize global browser if needed
401
- if _global_browser is None :
409
+ #if chrome_cdp not empty string nor None
410
+ if ((_global_browser is None ) or (cdp_url and cdp_url != "" and cdp_url != null )) :
402
411
_global_browser = CustomBrowser (
403
412
config = BrowserConfig (
404
413
headless = headless ,
@@ -409,7 +418,7 @@ async def run_custom_agent(
409
418
)
410
419
)
411
420
412
- if _global_browser_context is None :
421
+ if ( _global_browser_context is None or ( chrome_cdp and cdp_url != "" and cdp_url != null )) :
413
422
_global_browser_context = await _global_browser .new_context (
414
423
config = BrowserContextConfig (
415
424
trace_path = save_trace_path if save_trace_path else None ,
@@ -420,7 +429,8 @@ async def run_custom_agent(
420
429
),
421
430
)
422
431
)
423
-
432
+
433
+
424
434
# Create and run agent
425
435
if _global_agent is None :
426
436
_global_agent = CustomAgent (
@@ -489,7 +499,8 @@ async def run_with_stream(
489
499
max_steps ,
490
500
use_vision ,
491
501
max_actions_per_step ,
492
- tool_calling_method
502
+ tool_calling_method ,
503
+ chrome_cdp
493
504
):
494
505
global _global_agent_state
495
506
stream_vw = 80
@@ -518,7 +529,8 @@ async def run_with_stream(
518
529
max_steps = max_steps ,
519
530
use_vision = use_vision ,
520
531
max_actions_per_step = max_actions_per_step ,
521
- tool_calling_method = tool_calling_method
532
+ tool_calling_method = tool_calling_method ,
533
+ chrome_cdp = chrome_cdp
522
534
)
523
535
# Add HTML content at the start of the result array
524
536
html_content = f"<h1 style='width:{ stream_vw } vw; height:{ stream_vh } vh'>Using browser...</h1>"
@@ -551,7 +563,8 @@ async def run_with_stream(
551
563
max_steps = max_steps ,
552
564
use_vision = use_vision ,
553
565
max_actions_per_step = max_actions_per_step ,
554
- tool_calling_method = tool_calling_method
566
+ tool_calling_method = tool_calling_method ,
567
+ chrome_cdp = chrome_cdp
555
568
)
556
569
)
557
570
@@ -665,7 +678,7 @@ async def close_global_browser():
665
678
await _global_browser .close ()
666
679
_global_browser = None
667
680
668
- async def run_deep_search (research_task , max_search_iteration_input , max_query_per_iter_input , llm_provider , llm_model_name , llm_num_ctx , llm_temperature , llm_base_url , llm_api_key , use_vision , use_own_browser , headless ):
681
+ async def run_deep_search (research_task , max_search_iteration_input , max_query_per_iter_input , llm_provider , llm_model_name , llm_num_ctx , llm_temperature , llm_base_url , llm_api_key , use_vision , use_own_browser , headless , google_cdp ):
669
682
from src .utils .deep_research import deep_research
670
683
global _global_agent_state
671
684
@@ -685,7 +698,8 @@ async def run_deep_search(research_task, max_search_iteration_input, max_query_p
685
698
max_query_num = max_query_per_iter_input ,
686
699
use_vision = use_vision ,
687
700
headless = headless ,
688
- use_own_browser = use_own_browser
701
+ use_own_browser = use_own_browser ,
702
+ chrome_cdp = chrome_cdp
689
703
)
690
704
691
705
return markdown_content , file_path , gr .update (value = "Stop" , interactive = True ), gr .update (interactive = True )
@@ -870,6 +884,14 @@ def update_llm_num_ctx_visibility(llm_provider):
870
884
interactive = True , # Allow editing only if recording is enabled
871
885
)
872
886
887
+ chrome_cdp = gr .Textbox (
888
+ label = "CDP URL" ,
889
+ placeholder = "http://localhost:9222" ,
890
+ value = "" ,
891
+ info = "CDP for google remote debugging" ,
892
+ interactive = True , # Allow editing only if recording is enabled
893
+ )
894
+
873
895
save_recording_path = gr .Textbox (
874
896
label = "Recording Path" ,
875
897
placeholder = "e.g. ./tmp/record_videos" ,
@@ -974,7 +996,7 @@ def update_llm_num_ctx_visibility(llm_provider):
974
996
agent_type , llm_provider , llm_model_name , llm_num_ctx , llm_temperature , llm_base_url , llm_api_key ,
975
997
use_own_browser , keep_browser_open , headless , disable_security , window_w , window_h ,
976
998
save_recording_path , save_agent_history_path , save_trace_path , # Include the new path
977
- enable_recording , task , add_infos , max_steps , use_vision , max_actions_per_step , tool_calling_method
999
+ enable_recording , task , add_infos , max_steps , use_vision , max_actions_per_step , tool_calling_method , chrome_cdp
978
1000
],
979
1001
outputs = [
980
1002
browser_view , # Browser view
@@ -993,7 +1015,7 @@ def update_llm_num_ctx_visibility(llm_provider):
993
1015
# Run Deep Research
994
1016
research_button .click (
995
1017
fn = run_deep_search ,
996
- inputs = [research_task_input , max_search_iteration_input , max_query_per_iter_input , llm_provider , llm_model_name , llm_num_ctx , llm_temperature , llm_base_url , llm_api_key , use_vision , use_own_browser , headless ],
1018
+ inputs = [research_task_input , max_search_iteration_input , max_query_per_iter_input , llm_provider , llm_model_name , llm_num_ctx , llm_temperature , llm_base_url , llm_api_key , use_vision , use_own_browser , headless , chrome_cdp ],
997
1019
outputs = [markdown_output_display , markdown_download , stop_research_button , research_button ]
998
1020
)
999
1021
# Bind the stop button click event after errors_output is defined
0 commit comments