Skip to content

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

bumped up version

Gregor Žunič03b83d60a647
diff --git a/README.md b/README.md
index e8a4adbb6..348c49fc2 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,12 @@ With pip:
pip install browser-use
```
+(optional) install playwright:
+
+```bash
+playwright install
+```
+
Spin up your agent:
```python
@@ -71,6 +77,8 @@ https://github.com/user-attachments/assets/de73ee39-432c-4b97-b4e8-939fd7f323b3
If you want to add custom actions your agent can take, you can register them like this:
+You can use BOTH sync or async functions.
+
```python
from browser_use.agent.service import Agent
from browser_use.browser.service import Browser
@@ -94,11 +102,12 @@ class JobDetails(BaseModel):
salary: Optional[str] = None
@controller.action('Save job details which you found on page', param_model=JobDetails, requires_browser=True)
-def save_job(params: JobDetails, browser: Browser):
+async def save_job(params: JobDetails, browser: Browser):
print(params)
# use the browser normally
- browser.driver.get(params.job_link)
+ page = browser.get_current_page()
+ page.go_to(params.job_link)
```
and then run your agent:
diff --git a/browser_use/__init__.py b/browser_use/__init__.py
index cefa744e3..05c0eedc5 100644
--- a/browser_use/__init__.py
+++ b/browser_use/__init__.py
@@ -8,4 +8,4 @@ from browser_use.browser.service import Browser as Browser
from browser_use.controller.service import Controller as Controller
from browser_use.dom.service import DomService
-__all__ = ['Agent', 'Browser', 'Controller', 'DomService', 'SystemPrompt']
+__all__ = ["Agent", "Browser", "Controller", "DomService", "SystemPrompt"]
diff --git a/browser_use/browser/tests/test_clicks.py b/browser_use/browser/tests/test_clicks.py
index 76ded4482..248491827 100644
--- a/browser_use/browser/tests/test_clicks.py
+++ b/browser_use/browser/tests/test_clicks.py
@@ -8,58 +8,62 @@ from browser_use.utils import time_execution_sync
@pytest.mark.asyncio
async def test_highlight_elements():
- browser = Browser(headless=False, keep_open=False)
+ browser = Browser(headless=False, keep_open=False)
- session = await browser.get_session()
+ session = await browser.get_session()
- print(session)
+ print(session)
- page = await browser.get_current_page()
- # await page.goto('https://immobilienscout24.de')
- await page.goto('https://kayak.com')
+ page = await browser.get_current_page()
+ # await page.goto('https://immobilienscout24.de')
+ await page.goto("https://kayak.com")
- time.sleep(3)
- # browser._click_element_by_xpath(
- # '/html/body/div[5]/div/div[2]/div/div/div[3]/div/div[1]/button[1]'
- # )
- # browser._click_element_by_xpath("//button[div/div[text()='Alle akzeptieren']]")
+ time.sleep(3)
+ # browser._click_element_by_xpath(
+ # '/html/body/div[5]/div/div[2]/div/div/div[3]/div/div[1]/button[1]'
+ # )
+ # browser._click_element_by_xpath("//button[div/div[text()='Alle akzeptieren']]")
- while True:
- state = await browser.get_state()
+ while True:
+ state = await browser.get_state()
- await time_execution_sync('highlight_selector_map_elements')(
- browser.highlight_selector_map_elements
- )(state.selector_map)
+ await time_execution_sync("highlight_selector_map_elements")(
+ browser.highlight_selector_map_elements
+ )(state.selector_map)
- print(state.dom_items_to_string(use_tabs=False))
- # print(state.selector_map)
+ print(state.dom_items_to_string(use_tabs=False))
+ # print(state.selector_map)
- # Find and print duplicate XPaths
- xpath_counts = {}
- for selector in state.selector_map.values():
- if selector in xpath_counts:
- xpath_counts[selector] += 1
- else:
- xpath_counts[selector] = 1
+ # Find and print duplicate XPaths
+ xpath_counts = {}
+ for selector in state.selector_map.values():
+ if selector in xpath_counts:
+ xpath_counts[selector] += 1
+ else:
+ xpath_counts[selector] = 1
- print('\nDuplicate XPaths found:')
- for xpath, count in xpath_counts.items():
- if count > 1:
- print(f'XPath: {xpath}')
- print(f'Count: {count}\n')
+ print("\nDuplicate XPaths found:")
+ for xpath, count in xpath_counts.items():
+ if count > 1:
+ print(f"XPath: {xpath}")
+ print(f"Count: {count}\n")
- print(state.selector_map.keys(), 'Selector map keys')
- action = input('Select next action: ')
+ print(state.selector_map.keys(), "Selector map keys")
+ action = input("Select next action: ")
- await time_execution_sync('remove_highlight_elements')(browser.remove_highlights)()
+ await time_execution_sync("remove_highlight_elements")(
+ browser.remove_highlights
+ )()
- xpath = state.selector_map[int(action)]
+ xpath = state.selector_map[int(action)]
- # check if index of selector map are the same as index of items in dom_items
+ # check if index of selector map are the same as index of items in dom_items
- indcies = list(state.selector_map.keys())
- dom_items = state.items
- dom_indices = [item.index for item in dom_items if not item.is_text_only]
- assert indcies == dom_indices, 'Indices of selector map and dom items do not match'
+ indcies = list(state.selector_map.keys())
+ dom_items = state.items
+ dom_indices = [item.index for item in dom_items if not item.is_text_only]
+ assert (
+ indcies == dom_indices
+ ), "Indices of selector map and dom items do not match"
- await browser._click_element_by_xpath(xpath)
+ await browser._click_element_by_xpath(xpath)
diff --git a/browser_use/telemetry/views.py b/browser_use/telemetry/views.py
index 6ce12c17e..1e69c1770 100644
--- a/browser_use/telemetry/views.py
+++ b/browser_use/telemetry/views.py
@@ -5,47 +5,47 @@ from typing import Any, Dict, Optional
@dataclass
class BaseTelemetryEvent(ABC):
- @property
- @abstractmethod
- def name(self) -> str:
- pass
+ @property
+ @abstractmethod
+ def name(self) -> str:
+ pass
- @property
- def properties(self) -> Dict[str, Any]:
- return {k: v for k, v in asdict(self).items() if k != 'name'}
+ @property
+ def properties(self) -> Dict[str, Any]:
+ return {k: v for k, v in asdict(self).items() if k != "name"}
@dataclass
class RegisteredFunction:
- name: str
- params: dict[str, Any]
+ name: str
+ params: dict[str, Any]
@dataclass
class ControllerRegisteredFunctionsTelemetryEvent(BaseTelemetryEvent):
- registered_functions: list[RegisteredFunction]
- name: str = 'controller_registered_functions'
+ registered_functions: list[RegisteredFunction]
+ name: str = "controller_registered_functions"
@dataclass
class AgentRunTelemetryEvent(BaseTelemetryEvent):
- agent_id: str
- task: str
- name: str = 'agent_run'
+ agent_id: str
+ task: str
+ name: str = "agent_run"
@dataclass
class AgentStepErrorTelemetryEvent(BaseTelemetryEvent):
- agent_id: str
- error: str
- name: str = 'agent_step_error'
+ agent_id: str
+ error: str
+ name: str = "agent_step_error"
@dataclass
class AgentEndTelemetryEvent(BaseTelemetryEvent):
- agent_id: str
- task: str
- steps: int
- success: bool
- error: Optional[str] = None
- name: str = 'agent_end'
+ agent_id: str
+ task: str
+ steps: int
+ success: bool
+ error: Optional[str] = None
+ name: str = "agent_end"
diff --git a/pyproject.toml b/pyproject.toml
index 8cc34735e..5f8b2c8ec 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ description = "Make websites accessible for AI agents"
authors = [
{ name = "Gregor Zunic" }
]
-version = "0.1.6"
+version = "0.1.7"
readme = "README.md"
requires-python = ">=3.11"
classifiers = [
@@ -12,7 +12,7 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
-dependencies = [
+dependencies = [4
"MainContentExtractor>=0.0.4",
"beautifulsoup4>=4.12.3",
"langchain>=0.3.7",