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:
1 parent
c010cdb44e
commit
6240392632
24 files changed
+2079
-7
No files matched your search
@@ -399,8 +399,9 @@ semif_agent/
|
||||
voice_transport.py neutral voice transport: mic capture, wake word, VAD,
|
||||
speech-to-text (faster-whisper), text-to-speech (Piper)
|
||||
gateway/ messenger COMMAND intake/reply (SimpleX, LXMF, voice)
|
||||
bridges/ standalone third-party API bridges (SimpleX, LLM, Nextcloud)
|
||||
seeds/ committed starter skills (nextcloud, simplex)
|
||||
bridges/ standalone third-party API bridges (SimpleX, LLM, Nextcloud,
|
||||
Outlook, browser)
|
||||
seeds/ committed starter skills (nextcloud, simplex, outlook, browser)
|
||||
scripts/ bootstrap.sh, simplex-address.py, systemd/*.in
|
||||
requirements/ staging.txt — the pinned engine deps
|
||||
tests/ stdlib unit tests + tests/integration (real engine + LLM)
|
||||
@@ -531,11 +532,13 @@ Key blocks:
|
||||
| `bridges.llm` | LLM bridge: host/port/token (model comes from `llm`) |
|
||||
| `bridges.nextcloud` | Nextcloud bridge: host/port/token + connection (url/username/app_password/defaults) |
|
||||
| `bridges.outlook` | Outlook bridge: host/port/token + Microsoft Graph connection (client_id/tenant/defaults) |
|
||||
| `bridges.browser` | Browser bridge: host/port/token + Playwright settings (engine/headless/profile dirs) |
|
||||
| `simplex_chat` | gateway/forward ports and bot display names (binary refs come from `pins.json`) |
|
||||
| `dashboard` | bind host/port |
|
||||
|
||||
Bridge skills read `simplex_bridge_url` / `llm_bridge_url` /
|
||||
`nextcloud_bridge_url` / `outlook_bridge_url` (+ their `_token`) from
|
||||
`nextcloud_bridge_url` / `outlook_bridge_url` / `browser_bridge_url` (+ their
|
||||
`_token`) from
|
||||
`ctx.config`; each is **derived** at startup from its `bridges.<name>`
|
||||
host/port/token, so there is no duplicate top-level key to keep in sync. A bridge
|
||||
with no block (or no port) leaves the variable unresolved and the operator is
|
||||
@@ -845,6 +848,43 @@ Seven `seeds/outlook/*` skills ship (`next_message`, `send_message`,
|
||||
`send_message` composes the message through the LLM bridge and asks for
|
||||
confirmation before it sends.
|
||||
|
||||
The **browser bridge** (`semif_agent/bridges/browser.py`) is real browser
|
||||
automation via **Playwright**: open a URL, read a page's text or links, take a
|
||||
screenshot, and click/fill/press/select to complete a flow. It is the first
|
||||
bridge with a heavy optional dependency, so it is **disabled by default** and
|
||||
installed with `scripts/bootstrap.sh --browser` (Playwright + Chromium land under
|
||||
`.runtime/browser`; the bridge sets `PLAYWRIGHT_BROWSERS_PATH` there at launch).
|
||||
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
|
||||
(`POST /reset` with `purge=true` wipes it). A dedicated event-loop thread runs
|
||||
Playwright's async API and serializes whole operations, because the sync API is
|
||||
bound to its creating thread and the bridge serves each request on a new one.
|
||||
`check_requirements()` never blocks startup, so a host without Playwright still
|
||||
runs every other bridge; a missing package/browser is a `503` install hint on the
|
||||
call, and a real navigation/timeout/selector failure is a `502`. Skills call it
|
||||
at the address derived from `bridges.browser` (`browser_bridge_url`, + optional
|
||||
`browser_bridge_token`). Its HTTP surface:
|
||||
|
||||
```
|
||||
GET /health
|
||||
GET /state # current url + title
|
||||
GET /content?format=text|html&max_chars=<n> # whole page's rendered text
|
||||
GET /text?selector=<css> # text of matching elements
|
||||
GET /links?query=<text>&limit=<n> # anchors (label + href)
|
||||
GET /screenshot?full_page=<bool>&selector=<css>&inline=<bool>
|
||||
POST /goto {"url","wait_until"?,"timeout"?}
|
||||
POST /click {"selector"?|"text"?,"index"?,"timeout"?}
|
||||
POST /fill {"selector","value","submit"?,"timeout"?}
|
||||
POST /press {"key","selector"?,"timeout"?}
|
||||
POST /select {"selector","value"?|"label"?,"timeout"?}
|
||||
POST /wait {"selector"?|"text"?,"timeout"?}
|
||||
POST /back | /forward {"timeout"?}
|
||||
POST /reset {"purge"?} # close; purge deletes the profile
|
||||
```
|
||||
|
||||
Three `seeds/browser/*` skills ship (`open_page`, `read_page`, `screenshot`).
|
||||
|
||||
### Dream report
|
||||
|
||||
```sh
|
||||
|
||||
Reference in new issue
Block a user