Skip to main content

Allows seamless interplay between agentic browser-use and Playwright internals

Project description

Managed Browser

A minimal wrapper to seamlessly integrate browser-use agents into your existing Playwright (Python) workflows.


Motivation

Browser agents powered by LLMs can think creatively—click links by intent, extract arbitrary data, and navigate dynamic UIs—but they remain inherently non-deterministic. They may:

  • Misinterpret a button label or page layout
  • Click the wrong element when the UI changes
  • Drift off-task if given an open-ended prompt

Meanwhile, your Playwright scripts are rock-solid and repeatable, but rigid for anything beyond well-defined interactions.

managed-browser bridges the gap:

  1. Drop-in Agent Segments
    Invoke an LLM-driven agent exactly where you need it, without refactoring your existing Playwright logic.

  2. Seamless Control Transfer
    Hand off to the agent, then regain the exact same Page—with cookies, localStorage, DOM state, and session intact—so you can resume deterministic flows.

  3. Best of Both Worlds
    Let Playwright handle the mechanical, repeatable steps; delegate the fuzzy, creative extraction to your agent, then pick up where you left off.

  4. Full Visibility & Audit
    Wrap every agent run in a Playwright trace ZIP for step-by-step replay, screenshots, network logs, and DOM snapshots.


Installation

Requires Python 3.11+.

pip install managed-browser

Quick Example

import asyncio
from browser_use import BrowserConfig
from langchain_openai import ChatOpenAI
from managed_browser import BrowserManager

async def main():
    bm = BrowserManager(browser_config=BrowserConfig(headless=True))
    llm = ChatOpenAI(model="gpt-4o")

    async with bm.managed_context(use_tracing=True, tracing_output_path=...) as session:
        page = await session.browser_context.new_page()
        await page.goto("https://example.com/product/42")

        # 1) Agentic handoff: extract product info into JSON
        agent = session.make_agent(
            start_page=page,
            llm=llm,
            task="Return JSON: {\"title\": <product title>, \"price\": <price as number>}."
        )
        product_info, page = await agent.run()
        print("Extracted:", product_info)

        # 2) Hand control back to Playwright for a follow-up action
        await page.click("button#add-to-cart")
        await page.wait_for_selector(".cart-count")
        print("Added to cart, cart count:", await page.inner_text(".cart-count"))

    await bm.shutdown()

asyncio.run(main())

Core API

BrowserManager(browser_config, *, autostart=True)

  • .managed_context(use_tracing=False, tracing_output_path=None, randomize_user_agent=True, context_kwargs=None)
    Async context manager yielding a ManagedSession.
  • .shutdown()
    Gracefully close the browser.

ManagedSession

  • .browser_context → Playwright BrowserContext
  • .make_agent(start_page: Page, llm: BaseChatModel, **agent_kwargs)
    Returns an AgentWithControlTransfer whose .run() yields (output, final_page).

License

MIT © Amrit Baveja

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

managed_browser-0.1.4.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

managed_browser-0.1.4-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file managed_browser-0.1.4.tar.gz.

File metadata

  • Download URL: managed_browser-0.1.4.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for managed_browser-0.1.4.tar.gz
Algorithm Hash digest
SHA256 6c5a1122dc5455cc808f013741332add04a1c74e0e5ee4bbe38e5c8777d068ec
MD5 144083208ce19ff03455deeebf9c9755
BLAKE2b-256 3a02974b76436c38a2455a292e77d8ae30e74559161924db4569d9ec3796d119

See more details on using hashes here.

File details

Details for the file managed_browser-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for managed_browser-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 571cd3120b776ae06cb33bad13507d78ed2fecf9350ef09b74ed171f5fa20d61
MD5 e1a7933a0ff139a0f9289a215953f9f7
BLAKE2b-256 60284ba5112f759b3a4e031f934c2d14a82c47f2cf490160ec10e0e30b4b7f77

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page