bridges: let the browser bridge use an installed browser

Add `bridges.browser.channel` and `bridges.browser.executable_path` so a host
can point the bridge at an already-installed Chrome/Chromium (a Playwright
channel such as `chrome`/`msedge`, or a specific binary) instead of Playwright's
managed build. `executable_path` wins when both are set. This is the no-download
escape hatch for hosts where the browser CDN is unreachable or unusable.

- `BrowserDriver` carries `channel`/`executable_path` and passes them to
  `launch_persistent_context` when set, so the managed download is skipped.
- `BrowserBridge` reads both from its config block; `config.example.json`
  documents them.
- Verified live: launching an installed Chromium via `executable_path` with an
  empty browsers path drives a real page with no managed download.
This commit is contained in:
gabby committed 2026-10-11 09:46:44 +00:00
1 parent e4961ef492
commit 3a5b90b1cb
6 files changed
+54 -7

No files matched your search

+4 -1
View File
@@ -1543,7 +1543,10 @@ CLI, unit tests (24) + integration tests (2).
forces `autoSelectFamily` + a dual-stack resolver that prefers IPv6 and hangs
instead of falling back to IPv4), bootstrap falls back to
`scripts/playwright-browsers.py`, which fetches the same pinned artifacts over
IPv4 and lays them out where Playwright expects. Playwright's sync API is
IPv4 and lays them out where Playwright expects. `bridges.browser.channel` /
`executable_path` instead launch an already-installed browser (a Playwright
channel like `chrome`/`msedge`, or a specific binary) and skip the managed
download entirely. Playwright's sync API is
bound to its creating thread and the bridge serves each request on a new one,
so the driver runs the **async** API on one dedicated event-loop thread and
serializes whole operations behind an `asyncio.Lock`, submitting coroutines
+4 -1
View File
@@ -857,7 +857,10 @@ installed with `scripts/bootstrap.sh --browser` (Playwright + Chromium land unde
If `playwright install` fails — notably on a host with an IPv6 address but no
global IPv6 route, where Playwright's downloader prefers IPv6 and hangs —
bootstrap falls back to `scripts/playwright-browsers.py`, which downloads the
same pinned artifacts over IPv4.
same pinned artifacts over IPv4. To skip the managed download altogether, set
`bridges.browser.channel` (a Playwright channel such as `chrome`/`msedge`) or
`bridges.browser.executable_path` (a browser binary) to use an already-installed
browser.
Unlike the others it owns a browser and keeps a **persistent profile**
(`.runtime/browser/profile`) so a login you do once survives across calls and
restarts — the browser analog of the SimpleX bridge owning its own daemon
+3 -1
View File
@@ -196,13 +196,15 @@
"timeout": 30
},
"browser": {
"_comment": "Browser bridge: real browser automation via Playwright — open a URL, read a page's text/links, take a screenshot, and click/fill/press/select to complete a flow — behind one uniform local JSON API, so skill bodies never bundle a browser stack. Disabled by default because it needs the optional Playwright deps + browser binaries: install with `scripts/bootstrap.sh --browser` (browsers land under .runtime/browser). The bridge keeps a PERSISTENT profile under .runtime/browser/profile, so logins/cookies survive across calls and restarts (POST /reset with purge=true wipes it); `engine` is chromium|firefox|webkit and `headless` false shows the window. Skills call it at http://host:port (derived from this block; no top-level duplicate). Binds localhost only; an optional `token` is required in the X-Semif-Token header when set. A missing Playwright/browser is a 503 install hint, never a startup failure (the other bridges keep running).",
"_comment": "Browser bridge: real browser automation via Playwright — open a URL, read a page's text/links, take a screenshot, and click/fill/press/select to complete a flow — behind one uniform local JSON API, so skill bodies never bundle a browser stack. Disabled by default because it needs the optional Playwright deps + browser binaries: install with `scripts/bootstrap.sh --browser` (browsers land under .runtime/browser). The bridge keeps a PERSISTENT profile under .runtime/browser/profile, so logins/cookies survive across calls and restarts (POST /reset with purge=true wipes it); `engine` is chromium|firefox|webkit and `headless` false shows the window. Skills call it at http://host:port (derived from this block; no top-level duplicate). Binds localhost only; an optional `token` is required in the X-Semif-Token header when set. A missing Playwright/browser is a 503 install hint, never a startup failure (the other bridges keep running). Set `channel` (e.g. chrome/msedge) or `executable_path` (a browser binary) to use an already-installed browser and skip Playwright's managed download entirely; `executable_path` wins if both are set.",
"enabled": false,
"host": "127.0.0.1",
"port": 5232,
"token": "",
"engine": "chromium",
"headless": true,
"channel": "",
"executable_path": "",
"profile_dir": "",
"browsers_path": "",
"screenshot_dir": "",
+7
View File
@@ -132,6 +132,11 @@ class BrowserBridge(BridgeService):
self.screenshot_dir = str(cfg.get("screenshot_dir") or DEFAULT_SCREENSHOT_DIR)
self.default_timeout = float(cfg.get("default_timeout", DEFAULT_TIMEOUT))
self.max_text_chars = int(cfg.get("max_text_chars", DEFAULT_MAX_TEXT_CHARS))
#: Optional escape hatch: use an installed browser instead of Playwright's
#: managed download. `channel` is a Playwright channel (chrome/msedge/...),
#: `executable_path` a specific binary; `executable_path` wins if both set.
self.channel = str(cfg.get("channel", "") or "").strip()
self.executable_path = str(cfg.get("executable_path", "") or "").strip()
#: A test seam: inject a driver double. Production builds the real one.
self.client = client or BrowserDriver(
engine=self.engine,
@@ -141,6 +146,8 @@ class BrowserBridge(BridgeService):
screenshot_dir=self.screenshot_dir,
default_timeout=self.default_timeout,
max_text_chars=self.max_text_chars,
channel=self.channel,
executable_path=self.executable_path,
)
# ---- lifecycle ----
+18 -4
View File
@@ -67,6 +67,8 @@ class BrowserDriver:
screenshot_dir: str = "",
default_timeout: float = DEFAULT_TIMEOUT,
max_text_chars: int = DEFAULT_MAX_TEXT_CHARS,
channel: str = "",
executable_path: str = "",
):
self.engine = engine if engine in ENGINES else DEFAULT_ENGINE
self.headless = bool(headless)
@@ -75,6 +77,12 @@ class BrowserDriver:
self.screenshot_dir = str(screenshot_dir or "")
self.default_timeout = float(default_timeout)
self.max_text_chars = max(200, int(max_text_chars))
#: Use an already-installed browser instead of Playwright's own build:
#: `channel` names a Playwright channel (`chrome`, `msedge`, ...) and
#: `executable_path` points at a specific binary. Both bypass the
#: managed-download requirement, useful where the CDN is unreachable.
self.channel = str(channel or "").strip()
self.executable_path = str(executable_path or "").strip()
self._loop: asyncio.AbstractEventLoop | None = None
self._thread: threading.Thread | None = None
@@ -163,11 +171,17 @@ class BrowserDriver:
# A persistent context keeps cookies/logins on disk across calls and
# restarts; it is the browser analog of the SimpleX bridge owning its
# own profile.
launch_options = {
"headless": self.headless,
"viewport": {"width": 1280, "height": 800},
"timeout": self.default_timeout * 1000,
}
if self.executable_path:
launch_options["executable_path"] = self.executable_path
elif self.channel:
launch_options["channel"] = self.channel
self._context = await browser_type.launch_persistent_context(
user_data_dir,
headless=self.headless,
viewport={"width": 1280, "height": 800},
timeout=self.default_timeout * 1000,
user_data_dir, **launch_options
)
except BrowserUnavailable:
raise
+18
View File
@@ -309,6 +309,24 @@ def test_bad_engine_falls_back_to_chromium():
assert BrowserBridge({"engine": "WebKit"}).engine == "webkit"
def test_executable_path_and_channel_are_plumbed():
bridge = BrowserBridge(
{"channel": "chrome", "executable_path": "/usr/bin/google-chrome"}
)
assert bridge.channel == "chrome"
assert bridge.executable_path == "/usr/bin/google-chrome"
# The real driver (no injected double) carries them; executable_path wins at
# launch, so the managed download is skipped entirely.
assert bridge.client.channel == "chrome"
assert bridge.client.executable_path == "/usr/bin/google-chrome"
def test_driver_defaults_to_managed_browser():
driver = BrowserDriver()
assert driver.channel == ""
assert driver.executable_path == ""
# ---- driver dependency handling ----
def test_driver_unavailable_without_playwright(monkeypatch):