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

+7 -32
View File
@@ -1,36 +1,6 @@
FROM python:3.11-slim
FROM mcr.microsoft.com/playwright/python:v1.45.0-jammy
# Установка системных зависимостей
RUN apt-get update && apt-get install -y \
wget \
gnupg \
curl \
unzip \
libglib2.0-0 \
libnss3 \
libnspr4 \
libdbus-1-3 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libpango-1.0-0 \
libcairo2 \
libasound2 \
libatspi2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# Установка Playwright и браузеров
RUN pip install --no-cache-dir playwright && \
playwright install --with-deps chromium
# Установка Python зависимостей
# Установка дополнительных Python зависимостей
RUN pip install --no-cache-dir \
fastapi \
uvicorn \
@@ -42,8 +12,13 @@ RUN pip install --no-cache-dir \
WORKDIR /app
# Копируем код приложения
COPY app.py .
# Создаем директорию для данных браузера
RUN mkdir -p /app/browser-data && chmod 777 /app/browser-data
EXPOSE 8383
EXPOSE 9222
CMD ["python", "app.py"]
+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