BrowserFabric
Python SDK for BrowserFabric — the cloud browser for AI agents. Run remote sessions with saved context, live human takeover, and tools to observe, act, and verify.
Install
pip install browserfabric
Quick Start
import browserfabric
import asyncio
async def main():
async with browserfabric.browser() as session:
await session.navigate("https://example.com")
state = await session.observe_page()
print(state["elements"])
asyncio.run(main())
Agent interface (1.1.0+)
After navigating to your form, use the names in the current observation:
state = await session.observe_page()
submit = next(e["ref"] for e in state["elements"] if e["name"] == "Continue")
result = await session.act(
state["tab_id"], state["observation_id"],
[{"type": "click", "ref": submit}],
wait_for={"text": "Welcome"},
)
print(result["status"])
The sync session exposes the same methods. Use tabs() for explicit tab control,
observe_page(since=...) for a diff, browser_screenshot(tab_id) for base64 PNG,
and cancel() to interrupt running work.
act preserves recovery observations on tool failures. Check status:
verified means your condition matched; completed means actions ran without
an outcome check. On failure or interruption, inspect the current page and
completed steps before retrying. Transport errors still raise.
SDK-generated request IDs stay the same across transport retries. Explicit IDs must be unique per operation and reused only with identical payloads. Deduplication covers the last 64 requests in the live session, not a backend restart.
Authentication
Set your API key as an environment variable or pass it directly:
# Via environment variable
export BROWSERFABRIC_API_KEY=bf_your_key_here
# Or pass directly
async with browserfabric.browser(api_key="bf_...") as session:
...
Persistent Sessions
Save and restore browser state (cookies, localStorage) across sessions:
# Save state on close
async with browserfabric.browser(persist=True) as session:
await session.navigate("https://app.example.com/login")
await session.type("#email", "user@example.com")
await session.type("#password", "secret")
await session.click("#submit")
ctx = await session.save_context("my-app-login")
# Restore later
async with browserfabric.browser(context_id=ctx["context_id"]) as session:
# Already logged in
await session.navigate("https://app.example.com/dashboard")
CDP WebSocket
Connect with Playwright directly for full browser control:
from playwright.async_api import async_playwright
# Get the CDP WebSocket URL from session info
info = await session.session_info()
ws_url = info["ws_url"]
# Connect with Playwright
pw = await async_playwright().start()
browser = await pw.chromium.connect_over_cdp(ws_url)
page = browser.contexts[0].pages[0]
await page.goto("https://example.com")
Available Methods
| Method | Description |
|---|---|
navigate(url) |
Go to a URL |
click(selector) |
Click an element |
type(selector, text) |
Type into an input |
find(selector) |
Find elements |
screenshot(filename) |
Take a screenshot |
observe() |
Get interactive DOM elements |
snapshot() |
Get accessibility tree |
page_info() |
Get page URL and title |
session_info() |
Get session metadata + CDP URL |
save_context(name) |
Save browser state |
close() |
Close the session |
Self-Hosted
Point to your own BrowserFabric instance:
async with browserfabric.browser(base_url="http://your-server:9000") as session:
...
License
MIT
Metadata
Release files for browserfabric 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| browserfabric-1.1.0.tar.gz | 14.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| browserfabric-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.0 kB
Release files / browserfabric-1.1.0.tar.gz
| Download URL | browserfabric-1.1.0.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d43334b57d341082521f65ab54ae051f37c5f72d19a62a0f012598de3e07eef
|
|
BLAKE2b-256 checksum How to use checksums |
f278ffe76eb52f0887ce579100cd3f0f9b376e2a615bc926160dc7f4f8ab766c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / browserfabric-1.1.0-py3-none-any.whl
| Download URL | browserfabric-1.1.0-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
850237836aab353d1dc1a6d0deecb3d8a51da07c59a0470c9681f9a93f31c8e8
|
|
BLAKE2b-256 checksum How to use checksums |
0328c757e862fde29d74ef8e6213fe285d586793c15db075dde2d8951100a1a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for browserfabric 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.