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
flatten the extract action and some small things
mertunsalle5df80a0d699
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.pyindex adfad5e2c..c53493501 100644--- a/browser_use/tools/service.py+++ b/browser_use/tools/service.py@@ -38,7 +38,6 @@ from browser_use.tools.views import (ClickElementAction,CloseTabAction,DoneAction,- ExtractAction,GetDropdownOptionsAction,InputTextAction,NavigateAction,@@ -206,7 +205,7 @@ class Tools(Generic[Context]):# Return error in ActionResult instead of re-raisingreturn ActionResult(error=f'Navigation failed: {str(e)}')- @self.registry.action('', param_model=NoParamsAction)+ @self.registry.action('Go back', param_model=NoParamsAction)async def go_back(_: NoParamsAction, browser_session: BrowserSession):try:event = browser_session.event_bus.dispatch(GoBackEvent())@@ -220,14 +219,14 @@ class Tools(Generic[Context]):error_msg = f'Failed to go back: {str(e)}'return ActionResult(error=error_msg)- @self.registry.action('')+ @self.registry.action('Wait for x seconds.')async def wait(seconds: int = 3):# Cap wait time at maximum 30 seconds# Reduce the wait time by 3 seconds to account for the llm call which takes at least 3 seconds# So if the model decides to wait for 5 seconds, the llm call took at least 3 seconds, so we only need to wait for 2 seconds# Note by Mert: the above doesnt make sense because we do the LLM call right after this or this could be followed by another action after which we would like to wait# so I revert this.- actual_seconds = min(max(seconds - 3, 0), 30)+ actual_seconds = min(max(seconds - 1, 0), 30)memory = f'Waited for {seconds} seconds'logger.info(f'🕒 waited for {seconds} second{"" if seconds == 1 else "s"}')await asyncio.sleep(actual_seconds)@@ -342,7 +341,7 @@ class Tools(Generic[Context]):return ActionResult(error=error_msg)@self.registry.action(- 'Click element by index or coordinates. Prefer index over coordinates when possible.',+ 'Click element by index or coordinates. Prefer index over coordinates when possible. Either provide coordinates or index.',param_model=ClickElementAction,)async def click(params: ClickElementAction, browser_session: BrowserSession):@@ -358,7 +357,7 @@ class Tools(Generic[Context]):return await _click_by_coordinate(params, browser_session)@self.registry.action(- '',+ 'Input text into element with index.',param_model=InputTextAction,)async def input(@@ -637,19 +636,18 @@ class Tools(Generic[Context]):)@self.registry.action(- """LLM extracts structured data from page markdown. Use when: on right page, know what to extract, haven't called before on same page+query. Can't get interactive elements. Set extract_links=True for URLs. Use start_from_char if truncated. If fails, use find_text instead.""",+ """LLM extracts structured data from page markdown. Use when: on right page, know what to extract, haven't called before on same page+query. Can't get interactive elements. Set extract_links=True for URLs. Use start_from_char if previous extraction was truncated to extract data further down the page.""",)async def extract(- params: ExtractAction,+ query: str,browser_session: BrowserSession,page_extraction_llm: BaseChatModel,file_system: FileSystem,+ extract_links: bool = False,+ start_from_char: int = 0,):# ConstantsMAX_CHAR_LIMIT = 30000- query = params['query'] if isinstance(params, dict) else params.query- extract_links = params['extract_links'] if isinstance(params, dict) else params.extract_links- start_from_char = params['start_from_char'] if isinstance(params, dict) else params.start_from_char# Extract clean markdown using the unified methodtry:diff --git a/browser_use/tools/views.py b/browser_use/tools/views.pyindex f3a3b1440..d90f6cc33 100644--- a/browser_use/tools/views.py+++ b/browser_use/tools/views.py@@ -4,16 +4,6 @@ from pydantic import BaseModel, ConfigDict, Field# Action Input Models-class ExtractAction(BaseModel):- query: str- extract_links: bool = Field(- default=False, description='Set True to true if the query requires links, else false to safe tokens'- )- start_from_char: int = Field(- default=0, description='Use this for long markdowns to start from a specific character (not index in browser_state)'- )--class SearchAction(BaseModel):query: strengine: str = Field(