flash-total-remake

This commit is contained in:
nafer committed 2026-03-06 01:38:53 +03:00
1 parent 5b9e9ffc29
commit cdba9a29f3
2 files changed
+33 -38

No files matched your search

+26 -6
View File
@@ -148,11 +148,13 @@ async def run_browser_task(task_id: str, task: str, max_steps: int, model: str):
print(f"[{task_id}] Executing command: {' '.join(chrome_cmd)}")
# Запускаем процесс (без блокировки, в фоне)
subprocess.Popen(
# Запускаем процесс
print(f"[{task_id}] Starting Chrome process...")
log_file = open(f"/tmp/chrome_{task_id}.log", "w")
process = subprocess.Popen(
chrome_cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdout=log_file,
stderr=log_file,
start_new_session=True
)
@@ -160,18 +162,36 @@ async def run_browser_task(task_id: str, task: str, max_steps: int, model: str):
cdp_ready = False
for i in range(30): # Ждем до 30 секунд
await asyncio.sleep(1)
# Проверяем порты через python (замена netstat)
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
is_open = s.connect_ex(('127.0.0.1', REMOTE_DEBUGGING_PORT)) == 0
if is_open:
print(f"[{task_id}] Port {REMOTE_DEBUGGING_PORT} is OPEN!")
try:
response = urllib.request.urlopen(f"{cdp_url}/json/version", timeout=2)
if response.status == 200:
cdp_ready = True
print(f"[{task_id}] CDP is ready at {cdp_url}")
break
except Exception:
except Exception as e:
if i % 5 == 0:
print(f"[{task_id}] Waiting for CDP at {cdp_url}... (attempt {i})")
# Читаем последние строки лога Chrome
try:
with open(f"/tmp/chrome_{task_id}.log", "r") as f:
lines = f.readlines()[-5:]
print(f"[{task_id}] Last Chrome logs: {''.join(lines)}")
except:
pass
if not cdp_ready:
raise RuntimeError(f"Failed to start Chrome or CDP not ready after 30s at {cdp_url}")
# Читаем весь лог при ошибке
with open(f"/tmp/chrome_{task_id}.log", "r") as f:
chrome_logs = f.read()
raise RuntimeError(f"Failed to start Chrome or CDP not ready. Chrome Logs:\n{chrome_logs}")
# Подключаемся через CDP
from browser_use import BrowserConfig