From 50ee33fefc5b9a87b369eab9d698dc4ff38e7a2b Mon Sep 17 00:00:00 2001 From: a2a-platform Date: Sat, 27 Jun 2026 15:43:18 +0000 Subject: [PATCH] deploy --- agent.py | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/agent.py b/agent.py index 73291f5..013a337 100644 --- a/agent.py +++ b/agent.py @@ -13,6 +13,8 @@ import html import json import os import re +import subprocess +import sys import time from dataclasses import asdict, dataclass, field from pathlib import Path @@ -254,14 +256,7 @@ def capture_browser_traffic( samples_by_request: dict[int, TrafficSample] = {} with sync_playwright() as p: - browser = p.chromium.launch( - headless=True, - args=[ - "--disable-dev-shm-usage", - "--disable-blink-features=AutomationControlled", - "--no-sandbox", - ], - ) + browser = _launch_chromium(p, log) context = browser.new_context( viewport={"width": 1440, "height": 1000}, ignore_https_errors=True, @@ -334,6 +329,36 @@ def capture_browser_traffic( return list(samples_by_request.values()), log +def _launch_chromium(p: Any, log: list[str]) -> Any: + launch_kwargs = { + "headless": True, + "args": [ + "--disable-dev-shm-usage", + "--disable-blink-features=AutomationControlled", + "--no-sandbox", + ], + } + try: + return p.chromium.launch(**launch_kwargs) + except Exception as exc: # noqa: BLE001 + message = str(exc) + if "Executable doesn't exist" not in message and "playwright install" not in message: + raise + log.append("browser: chromium executable missing; installing with playwright") + proc = subprocess.run( + [sys.executable, "-m", "playwright", "install", "chromium"], + text=True, + capture_output=True, + timeout=300, + check=False, + ) + if proc.returncode != 0: + detail = (proc.stderr or proc.stdout or "").strip()[-2000:] + raise RuntimeError(f"playwright install chromium failed: {detail}") from exc + log.append("browser: playwright chromium install complete") + return p.chromium.launch(**launch_kwargs) + + def _fill_search_inputs(page: Any, search_term: str | None, log: list[str]) -> None: if not search_term: return