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
more switches to snake_case
Gregor Žunič101d4d1c36b8
diff --git a/browser_use/actor/playground/flights.py b/browser_use/actor/playground/flights.pyindex 2a7d95f35..941a41283 100644--- a/browser_use/actor/playground/flights.py+++ b/browser_use/actor/playground/flights.py@@ -1,5 +1,7 @@import asyncio+from pydantic import BaseModel+from browser_use import Browser, ChatOpenAIllm = ChatOpenAI('gpt-4.1-mini')@@ -14,22 +16,41 @@ async def main():browser = Browser(keep_alive=True)await browser.start()- target = await browser.get_current_target() or await browser.newTarget()+ target = await browser.get_current_target() or await browser.new_target()++ await target.navigate('https://www.nseindia.com/companies-listing/corporate-filings-financial-results-comparision')++ company_name_input = await target.must_get_element_by_prompt('company name input', llm)+ await company_name_input.fill('Tata Consultancy Services Limited')++ await asyncio.sleep(1)++ confirm_button = await target.must_get_element_by_prompt('confirm Tata Consultancy Services Limited selection button', llm)+ await confirm_button.click()++ await asyncio.sleep(0.1)++ search_button = await target.must_get_element_by_prompt('search button', llm)+ await search_button.click()++ await asyncio.sleep(2) # wait for the table to load- # Go to apple wikipedia page- await target.goto('https://www.google.com/travel/flights')+ class Quarter(BaseModel):+ quarter: str+ year: str+ net_profit: str- await asyncio.sleep(2)+ class TableData(BaseModel):+ qurters: list[Quarter]- round_trip_button = await target.must_get_element_by_prompt('round trip button', llm)- await round_trip_button.click()+ extracted_table = await target.extract_content('extract the table', TableData, llm)+ print(extracted_table)- one_way_button = await target.must_get_element_by_prompt('one way button', llm)- await one_way_button.click()+ await asyncio.sleep(10)- await asyncio.sleep(0.5)+ input('Press Enter to continue...')- await browser.stop()+ # await browser.stop()if __name__ == '__main__':diff --git a/browser_use/actor/playground/mixed_automation.py b/browser_use/actor/playground/mixed_automation.pyindex 86f63f758..3683c9661 100644--- a/browser_use/actor/playground/mixed_automation.py+++ b/browser_use/actor/playground/mixed_automation.py@@ -31,7 +31,7 @@ async def main():browser = Browser(keep_alive=True)await browser.start()- target = await browser.get_current_target() or await browser.newTarget()+ target = await browser.get_current_target() or await browser.new_target()# Go to apple wikipedia pageawait target.goto('https://browser-use.github.io/stress-tests/challenges/angularjs-form.html')diff --git a/browser_use/actor/playground/playground.py b/browser_use/actor/playground/playground.pyindex 551df560e..1a234e665 100755--- a/browser_use/actor/playground/playground.py+++ b/browser_use/actor/playground/playground.py@@ -34,7 +34,7 @@ async def main():# Navigate to Wikipedia using integrated methodslogger.info('📖 Navigating to Wikipedia...')- target = await browser.newTarget('https://en.wikipedia.org')+ target = await browser.new_target('https://en.wikipedia.org')# Get basic page infourl = await target.get_url()@@ -181,12 +181,12 @@ async def main():# Test creating new targetlogger.info('🆕 Creating new blank target...')- new_target = await browser.newTarget()+ new_target = await browser.new_target()new_target_url = await new_target.get_url()logger.info(f'🆕 New target created with URL: {new_target_url}')# Get all targets- all_targets = await browser.getTargets()+ all_targets = await browser.get_targets()logger.info(f'📑 Total targets: {len(all_targets)}')# Test form interaction if we can find a form@@ -213,7 +213,7 @@ async def main():logger.info('🕒 Waiting 2 seconds before closing the new target...')await asyncio.sleep(2)logger.info('🗑️ Closing new target...')- await browser.closeTarget(new_target)+ await browser.close_target(new_target)logger.info('✅ Playground completed successfully!')diff --git a/browser_use/actor/target.py b/browser_use/actor/target.pyindex 0186d9f4c..3e295ba00 100644--- a/browser_use/actor/target.py+++ b/browser_use/actor/target.py@@ -281,6 +281,10 @@ class Target:params: 'NavigateParameters' = {'url': url}await self._client.send.Page.navigate(params, session_id=session_id)+ async def navigate(self, url: str) -> None:+ """Alias for goto."""+ await self.goto(url)+async def go_back(self) -> None:"""Navigate back in history."""session_id = await self._ensure_session()@@ -433,9 +437,9 @@ Before you return the element index, reason about the state and elements for a selement = serialized_dom_state.selector_map[element_highlight_index]- from .element import Element+ from .element import Element as Element_- return Element(self._browser_session, element.backend_node_id, self._session_id)+ return Element_(self._browser_session, element.backend_node_id, self._session_id)async def must_get_element_by_prompt(self, prompt: str, llm: 'BaseChatModel | None' = None) -> 'Element':"""Get an element by a prompt.diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 0a1d8a79a..e8c9fb1eb 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -844,7 +844,7 @@ class BrowserSession(BaseModel):assert self._cdp_client_root is not None, 'CDP client not initialized - browser may not be connected yet'return self._cdp_client_root- async def newTarget(self, url: str | None = None) -> 'Target':+ async def new_target(self, url: str | None = None) -> 'Target':"""Create a new target (tab)."""from cdp_use.cdp.target.commands import CreateTargetParameters@@ -869,7 +869,7 @@ class BrowserSession(BaseModel):return Target(self, target_info['targetId'])- async def getTargets(self) -> list['Target']:+ async def get_targets(self) -> list['Target']:"""Get all available targets."""result = await self.cdp_client.send.Target.getTargets()@@ -883,7 +883,7 @@ class BrowserSession(BaseModel):return targets- async def closeTarget(self, target: 'Union[Target, str]') -> None:+ async def close_target(self, target: 'Union[Target, str]') -> None:"""Close a target by Target object or target ID."""from cdp_use.cdp.target.commands import CloseTargetParameters@@ -909,7 +909,7 @@ class BrowserSession(BaseModel):result = await self.cdp_client.send.Network.getCookies(params)return result['cookies']- async def clearCookies(self) -> None:+ async def clear_cookies(self) -> None:"""Clear all cookies."""await self.cdp_client.send.Network.clearBrowserCookies()