Skip to main content

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(base_url="https://api.browserfabric.com") 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.

Complete interface contract.

The SDK retains its self-hosted default (http://localhost:9000). For the hosted service, set the base URL to https://api.browserfabric.com, as in these examples.

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(base_url="https://api.browserfabric.com", 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(base_url="https://api.browserfabric.com", 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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for browserfabric 1.1.1
File Size Uploaded Provenance
browserfabric-1.1.1.tar.gz 14.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for browserfabric 1.1.1
File Interpreter ABI Platform
browserfabric-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.2 kB

Release files / browserfabric-1.1.1.tar.gz

Download URL browserfabric-1.1.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
73d3012da986867c9b1b6455c7e8d6d696b21083b4c3e6b1f5ca96315027f02f
BLAKE2b-256 checksum
How to use checksums
b0ecee577e461dc4516f05b945090592f871267eca0145dc33025a9ec5370590
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.1-py3-none-any.whl

Download URL browserfabric-1.1.1-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9118b98ec8f36b4c016074b1f339872139389355fc6d4d6aceba184fd11df44
BLAKE2b-256 checksum
How to use checksums
853c95b05bea39618a23e2c713e99ff7bbbcf2133ad007076513ec8ceac6d05b
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.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page