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

+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