Docs/SDK/Browser Setup

Browser Setup

Learn how to initialize and configure the PredicateBrowser for your automation needs.

PredicateBrowser Initialization

from predicate import PredicateBrowser

# Free tier (local processing only)
browser = PredicateBrowser(headless=False)

# Pro tier (server-side processing)
browser = PredicateBrowser(api_key="sk_...",

Parameters:

Viewport Configuration

Configure the browser viewport size to match your target screen resolution. The default viewport is 1280x800, which works well for most websites.

from predicate import PredicateBrowser

# Default viewport (1280x800)
browser = PredicateBrowser()

# Custom viewport for desktop (1920x1080)
browser = PredicateBrowser(viewport={"width": 1920, "height": 1080})

Common Viewport Sizes:

Why viewport matters:

Working with Existing Playwright Contexts

NEW in v0.90.16: Integrate PredicateBrowser with your existing Playwright workflows using from_existing() and from_page() class methods.

From Existing BrowserContext

Create a PredicateBrowser from an existing Playwright BrowserContext:

from predicate import PredicateBrowser
from playwright.sync_api import sync_playwright

# Create Playwright context with custom settings
with sync_playwright() as p:
    # Launch with custom settings
    context = p.chromium.launch_persistent_context(

From Existing Page

Create a PredicateBrowser from an existing Playwright Page:

from predicate import PredicateBrowser
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)
    context = browser.

Use Cases:

Benefits:

Residential Proxy Support

If you're running your agents from a datacenter (AWS, DigitalOcean, etc.), your IP address may be flagged by anti-bot services like Cloudflare. Using a residential proxy routes your traffic through a residential IP address, making your agent appear more like a regular user.

# Method 1: Pass proxy directly when creating browser
browser = PredicateBrowser(
    api_key="your_key",
    proxy="http://username:password@proxy.example.com:8080"
)

# Method 2: Use environment variable (easier for production)
# export SENTIENCE_PROXY="http://username:password@proxy.example.com:8080"
browser = PredicateBrowser(api_key="your_key")

Supported proxy formats:

What happens automatically:

Authentication Session Injection

Save time and tokens by starting your agent already logged in! Instead of having your agent click through login screens (which costs 5-10 steps and hundreds of tokens), you can inject a pre-saved authentication session.

Option 1: Pre-recorded Session (Best for Testing)

from predicate import PredicateBrowser, save_storage_state

# Step 1: Log in manually and save the session
browser = PredicateBrowser()
browser.start()
browser.goto("https://example.com")
# ... log in manually in the browser window ...
save_storage_state(browser.context,

Option 2: Persistent Sessions (Best for Production)

# First run: Agent logs in, session is saved
browser = PredicateBrowser(user_data_dir="./chrome_profile")
browser.start()
browser.goto("https://example.com")
agent.act("Click sign in")
agent.act("Type email"

Benefits:

Video Recording

Record your browser automation sessions as video files! This is perfect for creating tutorial videos, debugging automation failures, monitoring agent behavior, and generating documentation.

from predicate import PredicateBrowser

# Enable video recording by specifying output directory
browser = PredicateBrowser(record_video_dir="./recordings")
browser.start()

# All browser actions are now being recorded
browser.page.goto("https://example.com")
browser.

Video Format:

Tips: