Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
save recording path
Gregor Žunič1721eefa8cb5
diff --git a/browser_use/browser/context.py b/browser_use/browser/context.pyindex f3f7a480f..72631bc58 100644--- a/browser_use/browser/context.py+++ b/browser_use/browser/context.py@@ -75,6 +75,8 @@ class BrowserContextConfig:default_factory=lambda: {'width': 1280, 'height': 1024})+ save_recording_path: str | None = None+@dataclassclass BrowserSession:@@ -125,7 +127,7 @@ class BrowserContext:try:# Use sync Playwright method for force cleanupif hasattr(self.session.context, '_impl_obj'):- self.session.context._impl_obj.close()+ asyncio.run(self.session.context._impl_obj.close())self.session = Noneexcept Exception as e:logger.warning(f'Failed to force close browser context: {e}')@@ -192,6 +194,7 @@ class BrowserContext:java_script_enabled=True,bypass_csp=self.config.disable_security,ignore_https_errors=self.config.disable_security,+ record_video_dir=self.config.save_recording_path,)# Load cookies if they existdiff --git a/examples/parallel_agents.py b/examples/parallel_agents.pyindex 92d0db1b0..a8680871f 100644--- a/examples/parallel_agents.py+++ b/examples/parallel_agents.py@@ -8,8 +8,15 @@ from langchain_openai import ChatOpenAIfrom browser_use.agent.service import Agentfrom browser_use.browser.browser import Browser, BrowserConfig--browser = Browser(config=BrowserConfig(disable_security=True, headless=False))+from browser_use.browser.context import BrowserContextConfig++browser = Browser(+ config=BrowserConfig(+ disable_security=True,+ headless=True,+ new_context_config=BrowserContextConfig(save_recording_path='./tmp/recordings'),+ )+)llm = ChatOpenAI(model='gpt-4o')@@ -32,13 +39,14 @@ async def main():await asyncio.gather(*[agent.run() for agent in agents])- async with await browser.new_context() as context:- agentX = Agent(- task='Go to apple.com and find latest price of macbook pro 14 inch',- llm=llm,- browser_context=context,- )- await agentX.run()+ # async with await browser.new_context() as context:+ agentX = Agent(+ task='Go to apple.com and return the title of the page',+ llm=llm,+ browser=browser,+ # browser_context=context,+ )+ await agentX.run()await browser.close()