agent-zero/plugins/_browser/helpers/playwright.py
Alessandro 983d431a5e browser: replace browser-use agent with native browser
Introduce the new built-in Browser plugin for Agent Zero, replacing the legacy
browser-use-based browser agent with a direct Playwright-powered browser tool,
live WebUI viewer, browser session controls, status APIs, configuration, and
extension-management support.

Add browser-specific modal behavior so the browser can run as a floating,
resizable, no-backdrop window, including modal focus, toggle, and idempotent
open helpers for richer WebUI surfaces.

Remove the old `_browser_agent` core plugin and the `browser-use` dependency,
then clean up stale browser-model wiring and references across agent code,
model configuration docs, setup guides, troubleshooting docs, skills, and
Agent Zero knowledge.

Update regression and WebUI extension-surface coverage for the new browser
architecture and modal behavior.

The legacy browser-use implementation has been extracted from core so it can
continue separately as a community plugin published through the A0 Plugin Index for any user or professional that were relying on it for workflow.
2026-04-24 15:43:52 +02:00

57 lines
1.6 KiB
Python

import os
import subprocess
from pathlib import Path
from helpers import files
HEADLESS_SHELL_PATTERNS = (
"chromium_headless_shell-*/chrome-*/headless_shell",
"chromium_headless_shell-*/chrome-*/headless_shell.exe",
)
FULL_CHROMIUM_PATTERNS = (
"chromium-*/chrome-linux/chrome",
"chromium-*/chrome-win/chrome.exe",
)
def get_playwright_cache_dir() -> str:
return files.get_abs_path("tmp/playwright")
def configure_playwright_env() -> str:
cache_dir = get_playwright_cache_dir()
os.environ["PLAYWRIGHT_BROWSERS_PATH"] = cache_dir
return cache_dir
def get_playwright_binary(*, full_browser: bool = False) -> Path | None:
cache_dir = Path(get_playwright_cache_dir())
patterns = FULL_CHROMIUM_PATTERNS if full_browser else (HEADLESS_SHELL_PATTERNS + FULL_CHROMIUM_PATTERNS)
for pattern in patterns:
binary = next(cache_dir.glob(pattern), None)
if binary and binary.exists():
return binary
return None
def ensure_playwright_binary(*, full_browser: bool = False) -> Path:
binary = get_playwright_binary(full_browser=full_browser)
if binary:
return binary
cache_dir = configure_playwright_env()
env = os.environ.copy()
env["PLAYWRIGHT_BROWSERS_PATH"] = cache_dir
install_command = ["playwright", "install", "chromium"]
if not full_browser:
install_command.append("--only-shell")
subprocess.check_call(
install_command,
env=env,
)
binary = get_playwright_binary(full_browser=full_browser)
if not binary:
raise RuntimeError("Playwright Chromium binary not found after installation")
return binary