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:
1 parent
e4961ef492
commit
3a5b90b1cb
6 files changed
+54
-7
No files matched your search
@@ -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 ----
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user