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:
-
Drop-in Agent Segments
Invoke an LLM-driven agent exactly where you need it, without refactoring your existing Playwright logic. -
Seamless Control Transfer
Hand off to the agent, then regain the exact samePage—with cookies, localStorage, DOM state, and session intact—so you can resume deterministic flows. -
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. -
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 aManagedSession..shutdown()
Gracefully close the browser.
ManagedSession
.browser_context→ PlaywrightBrowserContext.make_agent(start_page: Page, llm: BaseChatModel, **agent_kwargs)
Returns anAgentWithControlTransferwhose.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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file managed_browser-0.2.0.tar.gz.
File metadata
- Download URL: managed_browser-0.2.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8e6c245ef2e8e2a0058f1fe3d7c13d30f766b3da5922165ecc36b5b701c9419
|
|
| MD5 |
89439ecda6492e6283def8d6fc19b691
|
|
| BLAKE2b-256 |
37cb8adf54f138c1cc4fc6648b274b59b63183de62584f7643039d048b2fc413
|
File details
Details for the file managed_browser-0.2.0-py3-none-any.whl.
File metadata
- Download URL: managed_browser-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99edfb3d1b7df6df4e6e1e55a0f973f4960be7a1874c21fe623020565e2f9637
|
|
| MD5 |
1fa24c73d5421333b84213351119fd93
|
|
| BLAKE2b-256 |
c35bfa864e2496f3b5f288f79ee12cfddf21078f22fb3cd9550f229d91af3b4b
|