This commit is contained in:
a2a-platform
2026-06-27 15:43:18 +00:00
parent 46b4132727
commit 50ee33fefc

View File

@@ -13,6 +13,8 @@ import html
import json import json
import os import os
import re import re
import subprocess
import sys
import time import time
from dataclasses import asdict, dataclass, field from dataclasses import asdict, dataclass, field
from pathlib import Path from pathlib import Path
@@ -254,14 +256,7 @@ def capture_browser_traffic(
samples_by_request: dict[int, TrafficSample] = {} samples_by_request: dict[int, TrafficSample] = {}
with sync_playwright() as p: with sync_playwright() as p:
browser = p.chromium.launch( browser = _launch_chromium(p, log)
headless=True,
args=[
"--disable-dev-shm-usage",
"--disable-blink-features=AutomationControlled",
"--no-sandbox",
],
)
context = browser.new_context( context = browser.new_context(
viewport={"width": 1440, "height": 1000}, viewport={"width": 1440, "height": 1000},
ignore_https_errors=True, ignore_https_errors=True,
@@ -334,6 +329,36 @@ def capture_browser_traffic(
return list(samples_by_request.values()), log 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: def _fill_search_inputs(page: Any, search_term: str | None, log: list[str]) -> None:
if not search_term: if not search_term:
return return