deploy
This commit is contained in:
41
agent.py
41
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
|
||||
|
||||
Reference in New Issue
Block a user