Skip to main content

Allows seamless interplay between agentic browser-use and Playwright internals

Project description

managed-browser

A simple wrapper to integrate language-model agents into your existing Playwright (Python) scripts via the popular browser-use library, with built-in Playwright tracing support.

Supports

  • Python 3.11+

Objective

Agents are still unreliable and far from production-ready—especially web agents, given the enormous diversity and challenges of navigating real-world sites. This package lets you keep your existing Playwright flows and seamlessly “drop in” agent tasks where you need them, without wrestling with a clunky API. It also exposes Playwright’s powerful tracing features around each agent run so you can debug and audit exactly what happened in the browser.

Installation

Requires Python 3.11+ and a PEP 517-compatible build backend.

# UV
uv add managed-browser
# Pip
pip install managed-browser

Usage

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

async def main():
    # Initialize the manager with your Playwright config
    bm = BrowserManager(
        browser_config=BrowserConfig(headless=False)
    )

    # Your LLM of choice
    llm = ChatOpenAI(model='gpt-4o')

    # Create a managed context (with tracing enabled under the hood)
    async with bm.managed_context() as session:
        page = await session.browser_context.new_page()

        # -- Your deterministic Playwright steps --
        await page.goto("https://github.com", wait_until="domcontentloaded")
        await page.wait_for_timeout(1_000)
        await page.evaluate("window.scrollTo(0, document.body.scrollHeight)")
        await page.wait_for_timeout(1_000)

        # -- Drop in an agent task --
        agent = session.make_agent(
            llm=llm,
            task=(
                "Extract the visible link text in the website's footer. "
                "Return your answer wrapped in <result>...</result>."
            )
        )
        result = await agent.run()
        print(result)

    # After exit, Playwright trace(s) for the agent run will be saved in ./playwright_traces/

if __name__ == '__main__':
    asyncio.run(main())

API Reference

BrowserManager

BrowserManager(
    browser_config: BrowserConfig,
    *,
    trace_dir: Optional[str] = "./playwright_traces"
)
  • browser_config: your browser-use/Playwright settings
  • trace_dir: where to dump Playwright trace ZIPs

.managed_context()

An async context manager yielding a ManagedSession:

  • session.browser_context → Playwright BrowserContext
  • session.make_agent(llm: BaseChatModel, task: str, **kwargs) → ready-to-run agent

ManagedSession.make_agent(...)

Wraps browser-use arguments into an LLM agent. Returns an object with a .run() coroutine.

Tracing

By default, each agent.run() invocation is wrapped in a Playwright trace. Trace files (ZIP) will appear under trace_dir with timestamps for easy playback:

# Playwright CLI
npx playwright show-trace ./playwright_traces/<timestamp>.zip

Contributing

Contributions, issues, and feature requests are welcome!
Please fork the repo and submit a pull request, or open an issue for discussion.

License

This project is licensed under the MIT License. See LICENSE for details.

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.3.tar.gz (6.2 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.3-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: managed_browser-0.1.3.tar.gz
  • Upload date:
  • Size: 6.2 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.3.tar.gz
Algorithm Hash digest
SHA256 0f92368c65ee8f3c9bd2e19f3bcf3703479c5f7309dbf884d4d8ebee4ee3baae
MD5 84f6f62a306e8c45debdc851c451accc
BLAKE2b-256 f9385c350427f20d5fb58426b2449f1648e6d865b1ad59cb5ce6bff0e73d9529

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for managed_browser-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5079132f59cdc871c006e3de23b9cbb2dec8015c22e1055c526c8838ff93d2da
MD5 29a16cdf7fc45b8cc2f42e14e1f2d908
BLAKE2b-256 5b24d0701fecdf48459e22a89b2a61a597ea4318632e8fe2e58006b89a39d881

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