bridges: browser automation via Playwright

Add a `browser` bridge: real browser automation behind the standard
token-guarded localhost JSON surface, so a codegen-authored skill body never
bundles a browser stack. It opens a URL, reads a page's text or links, takes a
screenshot, and clicks/fills/presses/selects to complete a flow.

Unlike the stdlib-only Nextcloud/Outlook bridges this one owns a browser and
needs a heavy optional dependency, so it is disabled by default and installed
with `scripts/bootstrap.sh --browser` (Playwright pinned in
requirements/browser.txt; the browser binary lands under the checkout's
.runtime/browser, which the driver points PLAYWRIGHT_BROWSERS_PATH at).

- `BrowserBridge` (`bridges/browser.py`) + `BrowserDriver`
  (`bridges/browser_client.py`). A real navigation/timeout/selector failure is a
  502, a missing package/browser a 503 install hint, bad input a 400 -- never a
  fabricated success.
- `check_requirements()` deliberately never blocks: `run_bridges()` aborts all
  bridges when one fails, and this dependency is optional, so a missing
  Playwright must degrade to a per-call 503, not take down the others.
- Playwright's sync API is bound to its creating thread while 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
  (submitted with run_coroutine_threadsafe).
- Persistent profile under .runtime/browser/profile so logins/cookies survive
  across calls and restarts; POST /reset with purge=true wipes it, and
  headless=false shows the window for a first sign-in. Route set: /health,
  /state, /content, /text, /links, /screenshot, /goto, /click, /fill, /press,
  /select, /wait, /back, /forward, /reset. No arbitrary JS evaluate (out of
  scope for this cut).
- Seeds: `seeds/browser/{open_page,read_page,screenshot}`, each hermetically
  tested against a loopback bridge. A `browser` category description is seeded
  so the leaf softmax has signal.
- `tests/test_browser_bridge.py` exercises the routes over a loopback HTTP
  server with an injected fake driver (no browser or Playwright needed). The
  live browser is a provisioned-host concern: this box could not reach the
  Playwright CDN, so no real-browser run backs it yet.
This commit is contained in:
gabby committed 2026-10-11 09:32:47 +00:00
1 parent c010cdb44e
commit 6240392632
24 files changed
+2079 -7

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
# Browser bridge deps (optional).
#
# Only needed on a host that runs the browser bridge (browser automation skills).
# Lazy-imported by semif_agent/bridges/browser_client.py, so the core stays
# stdlib-only and every other bridge keeps running without it. Install with
# scripts/bootstrap.sh --browser, or:
# .runtime/venv/bin/pip install -r requirements/browser.txt
# PLAYWRIGHT_BROWSERS_PATH=.runtime/browser \
# .runtime/venv/bin/python -m playwright install chromium
#
# The browser binaries are NOT shipped in the wheel: `playwright install`
# downloads Chromium into PLAYWRIGHT_BROWSERS_PATH. bootstrap.sh points that at
# the checkout's .runtime/browser (the containment rule); the bridge sets the
# same env var at launch, so the binaries live with the rest of the stack. Add
# `--with-deps` to the install command on a bare host to fetch the system
# libraries Chromium needs (needs sudo).
#
# Only `chromium` is installed by default; switch bridges.browser.engine to
# firefox/webkit and run `python -m playwright install firefox`/`webkit` for
# those.
playwright==1.63.0