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
improved docs, hydrate cookies on every state get
Gregor Žuničfe249cc465cd
diff --git a/README.md b/README.mdindex 02e4b4e8f..0be50b97a 100644--- a/README.md+++ b/README.md@@ -141,6 +141,20 @@ history: list[AgentHistory] = await agent.run()print(history)```+## Browser configuration++You can configure the browser using the `BrowserConfig` class.++The most important options are:++- `headless`: Whether to run the browser in headless mode+- `keep_open`: Whether to keep the browser open after the script finishes+- `disable_security`: Whether to disable browser security features (very useful if dealing with cross-origin requests like iFrames)+- `cookies_file`: Path to a cookies file for persistence+- `minimum_wait_page_load_time`: Minimum time to wait before getting the page state for the LLM input+- `wait_for_network_idle_page_load_time`: Time to wait for network requests to finish before getting the page state+- `maximum_wait_page_load_time`: Maximum time to wait for the page to load before proceeding anyway+## More examplesFor more examples see the [examples](examples) folder or join the [Discord](https://link.browser-use.com/discord) and show off your project.diff --git a/browser_use/browser/service.py b/browser_use/browser/service.pyindex e1c6c6eb4..20d1ab76a 100644--- a/browser_use/browser/service.py+++ b/browser_use/browser/service.py@@ -39,14 +39,28 @@ class BrowserConfig:"""Configuration for the Browser.- DEFAULT:+ Default values:headless: False+ Whether to run browser in headless mode+keep_open: False+ Keep browser open after script finishes+disable_security: False+ Disable browser security features+cookies_file: None- minimum_wait_page_load_time: 1- wait_for_network_idle_page_load_time: 1- maximum_wait_page_load_time: 15+ Path to cookies file for persistence++ minimum_wait_page_load_time: 0.5+ Minimum time to wait before getting page state for LLM input++ wait_for_network_idle_page_load_time: 1.0+ Time to wait for network requests to finish before getting page state.+ Lower values may result in incomplete page loads.++ maximum_wait_page_load_time: 5.0+ Maximum time to wait for page load before proceeding anyway"""headless: bool = False@@ -488,6 +502,11 @@ class Browser:await self._wait_for_page_and_frames_load()session = await self.get_session()session.cached_state = await self._update_state(use_vision=use_vision)++ # Save cookies if a file is specified+ if self.config.cookies_file:+ asyncio.create_task(self.save_cookies())+return session.cached_stateasync def _update_state(self, use_vision: bool = False) -> BrowserState: