From 4d9528f2080ac7bb2a3dd94b46d5fbebe1fe3705 Mon Sep 17 00:00:00 2001 From: Zilong Zhou Date: Wed, 2 Jul 2025 18:13:15 +0800 Subject: [PATCH] feat&fix: add proxy support in get_info_from_website function (#228) --- desktop_env/evaluators/getters/chrome.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/desktop_env/evaluators/getters/chrome.py b/desktop_env/evaluators/getters/chrome.py index 602aec5..d0a8c3a 100644 --- a/desktop_env/evaluators/getters/chrome.py +++ b/desktop_env/evaluators/getters/chrome.py @@ -58,6 +58,7 @@ def get_info_from_website(env, config: Dict[Any, Any]) -> Any: server_port = env.server_port remote_debugging_url = f"http://{host}:{port}" backend_url = f"http://{host}:{server_port}" + use_proxy = env.current_use_proxy with sync_playwright() as p: # connect to remote Chrome instance try: @@ -65,10 +66,13 @@ def get_info_from_website(env, config: Dict[Any, Any]) -> Any: except Exception as e: # If the connection fails (e.g., the agent close the browser instance), start a new browser instance app = 'chromium' if 'arm' in platform.machine() else 'google-chrome' - payload = json.dumps({"command": [ + command = [ app, "--remote-debugging-port=1337" - ], "shell": False}) + ] + if use_proxy: + command.append(f"--proxy-server=127.0.0.1:18888") + payload = json.dumps({"command": command, "shell": False}) headers = {"Content-Type": "application/json"} #requests.post("http://" + host + ":" + server_port + "/setup" + "/launch", headers=headers, data=payload) requests.post(backend_url + "/setup" + "/launch", headers=headers, data=payload)