feat&fix: add proxy support in get_info_from_website function (#228)

This commit is contained in:
Zilong Zhou
2025-07-02 18:13:15 +08:00
committed by GitHub
parent 595a704aff
commit 4d9528f208

View File

@@ -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)