main
py 43 lines 1.93 KB
Raw
1 from helpers.api import ApiHandler, Request
2 from plugins._browser.helpers.config import build_browser_launch_config, get_browser_config
3 from plugins._browser.helpers.interactive_view import collect_status as collect_interactive_status
4 from plugins._browser.helpers.playwright import (
5 get_playwright_binary,
6 get_playwright_cache_dir,
7 get_playwright_cache_dirs,
8 )
9 from plugins._browser.helpers.runtime import known_context_ids
10
11
12 class Status(ApiHandler):
13 async def process(self, input: dict, request: Request) -> dict:
14 browser_config = get_browser_config()
15 launch_config = build_browser_launch_config(browser_config)
16 runtime_binary = get_playwright_binary()
17 chromium_binary = runtime_binary
18 try:
19 from plugins._a0_connector.helpers.ws_runtime import all_host_browser_metadata
20 except ImportError:
21 host_browser = {"connectors": []}
22 else:
23 host_browser = {"connectors": all_host_browser_metadata()}
24 return {
25 "plugin": "_browser",
26 "playwright": {
27 "cache_dir": get_playwright_cache_dir(),
28 "cache_dirs": [str(path) for path in get_playwright_cache_dirs()],
29 "binary_found": bool(runtime_binary),
30 "install_required": not bool(runtime_binary),
31 "binary_path": str(runtime_binary) if runtime_binary else "",
32 "chromium_binary_path": str(chromium_binary) if chromium_binary else "",
33 "launch_mode": launch_config["browser_mode"],
34 },
35 "extensions": {
36 **launch_config["extensions"],
37 "launch_mode": launch_config["browser_mode"],
38 "requires_full_browser": launch_config["requires_full_browser"],
39 },
40 "host_browser": host_browser,
41 "interactive_view": collect_interactive_status(),
42 "contexts": known_context_ids(),
43 }