|
45 | 45 |
|
46 | 46 | def ensure_playwright_installed() -> None: |
47 | 47 | """Install Playwright browsers when running in ephemeral environments.""" |
48 | | - try: |
49 | | - subprocess.run( |
50 | | - ["playwright", "install", "--with-deps", "chromium"], |
51 | | - check=True, |
52 | | - capture_output=True, |
53 | | - ) |
54 | | - except FileNotFoundError: |
55 | | - st.warning("Playwright CLI not found; please ensure Playwright is installed.", icon="⚠️") |
56 | | - except subprocess.CalledProcessError as exc: |
57 | | - # Playwright returns non-zero if browsers already exist; suppress noise. |
58 | | - stderr = exc.stderr.decode("utf-8") if exc.stderr else "" |
59 | | - if "already installed" not in stderr.lower(): |
60 | | - st.warning(f"Playwright install warning: {stderr}", icon="⚠️") |
| 48 | + commands = [ |
| 49 | + ["playwright", "install", "chromium"], |
| 50 | + ["playwright", "install", "--with-deps", "chromium"], |
| 51 | + ] |
| 52 | + last_error = "" |
| 53 | + for cmd in commands: |
| 54 | + try: |
| 55 | + subprocess.run(cmd, check=True, capture_output=True) |
| 56 | + return |
| 57 | + except FileNotFoundError: |
| 58 | + st.warning("Playwright CLI not found; please ensure Playwright is installed.", icon="⚠️") |
| 59 | + return |
| 60 | + except subprocess.CalledProcessError as exc: |
| 61 | + stderr = exc.stderr.decode("utf-8") if exc.stderr else "" |
| 62 | + if "already installed" in stderr.lower(): |
| 63 | + return |
| 64 | + last_error = stderr |
| 65 | + if last_error: |
| 66 | + st.warning(f"Playwright install warning: {last_error}", icon="⚠️") |
61 | 67 |
|
62 | 68 |
|
63 | 69 | ensure_playwright_installed() |
|
0 commit comments