@@ -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,7 +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 } " ]
289
+ cdp_url = chrome_cdp
290
+
285
291
if use_own_browser :
292
+ cdp_url = os .getenv ("CHROME_CDP" , chrome_cdp )
286
293
chrome_path = os .getenv ("CHROME_PATH" , None )
287
294
if chrome_path == "" :
288
295
chrome_path = None
@@ -293,9 +300,11 @@ async def run_org_agent(
293
300
chrome_path = None
294
301
295
302
if _global_browser is None :
303
+
296
304
_global_browser = Browser (
297
305
config = BrowserConfig (
298
306
headless = headless ,
307
+ cdp_url = cdp_url ,
299
308
disable_security = disable_security ,
300
309
chrome_instance_path = chrome_path ,
301
310
extra_chromium_args = extra_chromium_args ,
@@ -307,6 +316,7 @@ async def run_org_agent(
307
316
config = BrowserContextConfig (
308
317
trace_path = save_trace_path if save_trace_path else None ,
309
318
save_recording_path = save_recording_path if save_recording_path else None ,
319
+ cdp_url = cdp_url ,
310
320
no_viewport = False ,
311
321
browser_window_size = BrowserContextWindowSize (
312
322
width = window_w , height = window_h
@@ -370,7 +380,8 @@ async def run_custom_agent(
370
380
max_steps ,
371
381
use_vision ,
372
382
max_actions_per_step ,
373
- tool_calling_method
383
+ tool_calling_method ,
384
+ chrome_cdp
374
385
):
375
386
try :
376
387
global _global_browser , _global_browser_context , _global_agent_state , _global_agent
@@ -379,7 +390,10 @@ async def run_custom_agent(
379
390
_global_agent_state .clear_stop ()
380
391
381
392
extra_chromium_args = [f"--window-size={ window_w } ,{ window_h } " ]
393
+ cdp_url = chrome_cdp
382
394
if use_own_browser :
395
+ cdp_url = os .getenv ("CHROME_CDP" , chrome_cdp )
396
+
383
397
chrome_path = os .getenv ("CHROME_PATH" , None )
384
398
if chrome_path == "" :
385
399
chrome_path = None
@@ -392,17 +406,19 @@ async def run_custom_agent(
392
406
controller = CustomController ()
393
407
394
408
# Initialize global browser if needed
395
- 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 != None )) :
396
411
_global_browser = CustomBrowser (
397
412
config = BrowserConfig (
398
413
headless = headless ,
399
414
disable_security = disable_security ,
415
+ cdp_url = cdp_url ,
400
416
chrome_instance_path = chrome_path ,
401
417
extra_chromium_args = extra_chromium_args ,
402
418
)
403
419
)
404
420
405
- if _global_browser_context is None :
421
+ if ( _global_browser_context is None or ( chrome_cdp and cdp_url != "" and cdp_url != None )) :
406
422
_global_browser_context = await _global_browser .new_context (
407
423
config = BrowserContextConfig (
408
424
trace_path = save_trace_path if save_trace_path else None ,
@@ -413,7 +429,8 @@ async def run_custom_agent(
413
429
),
414
430
)
415
431
)
416
-
432
+
433
+
417
434
# Create and run agent
418
435
if _global_agent is None :
419
436
_global_agent = CustomAgent (
@@ -482,7 +499,8 @@ async def run_with_stream(
482
499
max_steps ,
483
500
use_vision ,
484
501
max_actions_per_step ,
485
- tool_calling_method
502
+ tool_calling_method ,
503
+ chrome_cdp
486
504
):
487
505
global _global_agent_state
488
506
stream_vw = 80
@@ -511,7 +529,8 @@ async def run_with_stream(
511
529
max_steps = max_steps ,
512
530
use_vision = use_vision ,
513
531
max_actions_per_step = max_actions_per_step ,
514
- tool_calling_method = tool_calling_method
532
+ tool_calling_method = tool_calling_method ,
533
+ chrome_cdp = chrome_cdp
515
534
)
516
535
# Add HTML content at the start of the result array
517
536
html_content = f"<h1 style='width:{ stream_vw } vw; height:{ stream_vh } vh'>Using browser...</h1>"
@@ -544,7 +563,8 @@ async def run_with_stream(
544
563
max_steps = max_steps ,
545
564
use_vision = use_vision ,
546
565
max_actions_per_step = max_actions_per_step ,
547
- tool_calling_method = tool_calling_method
566
+ tool_calling_method = tool_calling_method ,
567
+ chrome_cdp = chrome_cdp
548
568
)
549
569
)
550
570
@@ -658,7 +678,7 @@ async def close_global_browser():
658
678
await _global_browser .close ()
659
679
_global_browser = None
660
680
661
- 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 , chrome_cdp ):
662
682
from src .utils .deep_research import deep_research
663
683
global _global_agent_state
664
684
@@ -678,7 +698,8 @@ async def run_deep_search(research_task, max_search_iteration_input, max_query_p
678
698
max_query_num = max_query_per_iter_input ,
679
699
use_vision = use_vision ,
680
700
headless = headless ,
681
- use_own_browser = use_own_browser
701
+ use_own_browser = use_own_browser ,
702
+ chrome_cdp = chrome_cdp
682
703
)
683
704
684
705
return markdown_content , file_path , gr .update (value = "Stop" , interactive = True ), gr .update (interactive = True )
@@ -854,6 +875,23 @@ def update_llm_num_ctx_visibility(llm_provider):
854
875
info = "Browser window height" ,
855
876
)
856
877
878
+
879
+ save_recording_path = gr .Textbox (
880
+ label = "Recording Path" ,
881
+ placeholder = "e.g. ./tmp/record_videos" ,
882
+ value = config ['save_recording_path' ],
883
+ info = "Path to save browser recordings" ,
884
+ interactive = True , # Allow editing only if recording is enabled
885
+ )
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
+
857
895
save_recording_path = gr .Textbox (
858
896
label = "Recording Path" ,
859
897
placeholder = "e.g. ./tmp/record_videos" ,
@@ -958,7 +996,7 @@ def update_llm_num_ctx_visibility(llm_provider):
958
996
agent_type , llm_provider , llm_model_name , llm_num_ctx , llm_temperature , llm_base_url , llm_api_key ,
959
997
use_own_browser , keep_browser_open , headless , disable_security , window_w , window_h ,
960
998
save_recording_path , save_agent_history_path , save_trace_path , # Include the new path
961
- 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
962
1000
],
963
1001
outputs = [
964
1002
browser_view , # Browser view
@@ -977,7 +1015,7 @@ def update_llm_num_ctx_visibility(llm_provider):
977
1015
# Run Deep Research
978
1016
research_button .click (
979
1017
fn = run_deep_search ,
980
- 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 ],
981
1019
outputs = [markdown_output_display , markdown_download , stop_research_button , research_button ]
982
1020
)
983
1021
# Bind the stop button click event after errors_output is defined
0 commit comments