Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Add documentation for CodeAgent parameters and exporting sessions

kalil0321da3773fd59b5
diff --git a/docs/customize/code-agent/all-parameters.mdx b/docs/customize/code-agent/all-parameters.mdx
new file mode 100644
index 000000000..4b2f2ce8f
--- /dev/null
+++ b/docs/customize/code-agent/all-parameters.mdx
@@ -0,0 +1,31 @@
+---
+title: "All Parameters"
+description: "Complete reference for all CodeAgent configuration options"
+icon: "sliders"
+mode: "wide"
+---
+
+## CodeAgent Parameters
+
+### Core Settings
+- `task`: Task description string that defines what the agent should accomplish
+- `llm`: LLM instance for code generation (required: ChatBrowserUse)
+- `browser`: Browser session object for automation
+- `tools`: Registry of tools the agent can call
+- `max_steps` (default: `20`): Maximum number of execution steps before termination
+- `max_failures` (default: `8`): Maximum consecutive errors before termination
+- `max_validations` (default: `0`): Maximum number of times to run the validator agent (default: 0)
+
+### Vision & Processing
+- `use_vision` (default: `"auto"`): Vision mode - `"auto"` includes screenshot tool but only uses vision when requested, `True` always includes screenshots, `False` never includes screenshots and excludes screenshot tool
+- `page_extraction_llm`: Separate LLM model for page content extraction. You can choose a small & fast model because it only needs to extract text from the page (default: same as `llm`)
+
+### Actions & Behavior
+- `use_thinking` (default: `True`): Controls whether the agent uses its internal "thinking" field for explicit reasoning steps
+
+### File & Data Management
+- `available_file_paths`: List of file paths the agent can access
+- `sensitive_data`: Dictionary of sensitive data to handle carefully
+
+### Advanced Options
+- `calculate_cost` (default: `False`): Calculate and track API costs (see ... to track costs)
diff --git a/docs/customize/code-agent/basics.mdx b/docs/customize/code-agent/basics.mdx
index 4718e739f..6b72df224 100644
--- a/docs/customize/code-agent/basics.mdx
+++ b/docs/customize/code-agent/basics.mdx
@@ -95,3 +95,35 @@ The agent has access to browser control functions:
- `upload_file(path)` - Upload a file
- `evaluate(code, variables={})` - Execute JavaScript and return results
- `done(text, success, files_to_display=[])` - Mark task complete
+
+## Exporting Sessions
+
+CodeAgent automatically saves all executed code and JavaScript blocks during your session. You can export your complete automation workflow for sharing, version control, or re-running later.
+
+### Quick Export
+
+```python
+from browser_use.code_use.notebook_export import export_to_ipynb, session_to_python_script
+
+# After running your agent
+await agent.run()
+
+# Export to Jupyter notebook
+notebook_path = export_to_ipynb(agent, "my_automation.ipynb")
+
+# Export to Python script
+script = session_to_python_script(agent)
+with open("my_automation.py", "w") as f:
+ f.write(script)
+```
+
+### Export Formats
+
+- **Jupyter Notebook (.ipynb)**: Interactive development, sharing, documentation
+- **Python Script (.py)**: Production deployment, version control, automation
+
+Both formats include:
+- Setup code with browser initialization
+- JavaScript code blocks as Python variables
+- All executed Python cells with outputs
+- Ready-to-run automation workflows
diff --git a/docs/customize/code-agent/exporting.mdx b/docs/customize/code-agent/exporting.mdx
new file mode 100644
index 000000000..1441dde45
--- /dev/null
+++ b/docs/customize/code-agent/exporting.mdx
@@ -0,0 +1,129 @@
+---
+title: "Exporting Sessions"
+description: "Save and share your CodeAgent sessions as Jupyter notebooks or Python scripts"
+icon: "download"
+---
+
+CodeAgent automatically saves all executed code and JavaScript blocks during your session. You can export your complete automation workflow in multiple formats for sharing, version control, or re-running later.
+
+## Quick Start
+
+```python
+import asyncio
+from browser_use import CodeAgent, ChatBrowserUse
+from browser_use.code_use.notebook_export import export_to_ipynb, session_to_python_script
+
+async def main():
+ agent = CodeAgent(
+ task="Extract product data from https://example.com",
+ llm=ChatBrowserUse(),
+ max_steps=10
+ )
+
+ # Run your automation
+ await agent.run()
+
+ # Export to Jupyter notebook
+ notebook_path = export_to_ipynb(agent, "product_scraping.ipynb")
+
+ # Export to Python script
+ python_script = session_to_python_script(agent)
+ with open("product_scraping.py", "w") as f:
+ f.write(python_script)
+
+if __name__ == '__main__':
+ asyncio.run(main())
+```
+
+## Export Formats
+
+### Jupyter Notebook (.ipynb)
+
+**Contains:**
+- Setup cell with browser initialization and imports
+- JavaScript code blocks as Python string variables
+- All executed Python cells with outputs and errors
+- Browser state snapshots
+
+**Structure:**
+```python
+# Cell 1: Setup
+import asyncio
+import json
+from browser_use import BrowserSession
+from browser_use.code_use import create_namespace
+
+browser = BrowserSession()
+await browser.start()
+namespace = create_namespace(browser)
+globals().update(namespace)
+
+# Cell 2: JavaScript variables
+extract_products = """(function(){
+ return Array.from(document.querySelectorAll('.product')).map(product => ({
+ name: product.querySelector('.name')?.textContent,
+ price: product.querySelector('.price')?.textContent
+ }));
+})()"""
+
+# Remaining cells: Python execution
+await navigate('https://example.com')
+
+...
+
+products = await evaluate(extract_products)
+print(f"Found {len(products)} products")
+```
+
+### Python Script (.py)
+
+**Best for:** Production deployment, version control, automation
+
+**Contains:**
+- Complete runnable script with all imports
+- JavaScript code blocks as Python string variables
+- All executed code with proper indentation
+- Ready to run with `python script.py`
+
+**Structure:**
+```python
+# Generated from browser-use code-use session
+import asyncio
+import json
+from browser_use import BrowserSession
+from browser_use.code_use import create_namespace
+
+async def main():
+ # Initialize browser and namespace
+ browser = BrowserSession()
+ await browser.start()
+
+ # Create namespace with all browser control functions
+ namespace = create_namespace(browser)
+
+ # Extract functions from namespace for direct access
+ navigate = namespace["navigate"]
+ click = namespace["click"]
+ evaluate = namespace["evaluate"]
+ # ... other functions
+
+ # JavaScript Code Block: extract_products
+ extract_products = """(function(){
+ return Array.from(document.querySelectorAll('.product')).map(product => ({
+ name: product.querySelector('.name')?.textContent,
+ price: product.querySelector('.price')?.textContent
+ }));
+ })()"""
+
+ # Cell 1
+ await navigate('https://example.com')
+
+ # Cell 2
+ products = await evaluate(extract_products)
+ print(f"Found {len(products)} products")
+
+ await browser.stop()
+
+if __name__ == '__main__':
+ asyncio.run(main())
+```