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
linter fixes
Nick Sweeting09a8ee52b55e
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex b4f0670b0..f7f824251 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -260,13 +260,13 @@ class BrowserSession(BaseModel):"""Starts the browser session by either connecting to an existing browser or launching a new one.Precedence order for launching/connecting:- 1. page=Page playwright object, will use its page.context as browser_context- 2. browser_context=PlaywrightBrowserContext object, will use its browser- 3. browser=PlaywrightBrowser object, will use its first available context- 4. browser_pid=int, will connect to a local chromium-based browser via pid- 5. wss_url=str, will connect to a remote playwright browser server via WSS- 6. cdp_url=str, will connect to a remote chromium-based browser via CDP- 7. playwright=Playwright object, will use its chromium instance to launch a new browser+ 1. page=Page playwright object, will use its page.context as browser_context+ 2. browser_context=PlaywrightBrowserContext object, will use its browser+ 3. browser=PlaywrightBrowser object, will use its first available context+ 4. browser_pid=int, will connect to a local chromium-based browser via pid+ 5. wss_url=str, will connect to a remote playwright browser server via WSS+ 6. cdp_url=str, will connect to a remote chromium-based browser via CDP+ 7. playwright=Playwright object, will use its chromium instance to launch a new browser"""# if we're already initialized and the connection is still valid, return the existing session state and start from scratch@@ -609,7 +609,7 @@ class BrowserSession(BaseModel):self.logger.warning(f'Error force-killing browser in BrowserSession.__del__: {type(e).__name__}: {e}')@staticmethod- async def _start_global_playwright_subprocess(is_stealth: bool) -> Playwright | Patchright:+ async def _start_global_playwright_subprocess(is_stealth: bool) -> PlaywrightOrPatchright:"""Create and return a new playwright or patchright node.js subprocess / API connector"""global GLOBAL_PLAYWRIGHT_API_OBJECT, GLOBAL_PATCHRIGHT_API_OBJECTglobal GLOBAL_PLAYWRIGHT_EVENT_LOOP, GLOBAL_PATCHRIGHT_EVENT_LOOP@@ -2331,9 +2331,9 @@ class BrowserSession(BaseModel):Parameters:-----------cache_clickable_elements_hashes: bool- If True, cache the clickable elements hashes for the current state.- This is used to calculate which elements are new to the LLM since the last message,- which helps reduce token usage.+ If True, cache the clickable elements hashes for the current state.+ This is used to calculate which elements are new to the LLM since the last message,+ which helps reduce token usage."""await self._wait_for_page_and_frames_load()updated_state = await self._get_updated_state()@@ -2443,7 +2443,7 @@ class BrowserSession(BaseModel):await page.wait_for_load_state(timeout=5000,) # page has already loaded by this point, this is extra for previous action animations/frame loads to settle- except Exception as e:+ except Exception:pass# 0. Attempt full-page screenshot (sometimes times out for huge pages)@@ -2602,10 +2602,10 @@ class BrowserSession(BaseModel):Creates a CSS selector for a DOM element, handling various edge cases and special characters.Args:- element: The DOM element to create a selector for+ element: The DOM element to create a selector forReturns:- A valid CSS selector string+ A valid CSS selector string"""try:# Get base selector from XPath@@ -3011,7 +3011,7 @@ class BrowserSession(BaseModel):try:assert self.browser_context is not None, 'Browser context is not set'new_page = await self.browser_context.new_page()- except Exception as e:+ except Exception:self.initialized = Falseif not self.initialized or not self.is_connected():diff --git a/pyproject.toml b/pyproject.tomlindex cf6ee15a4..269c9e028 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -87,7 +87,7 @@ build-backend = "hatchling.build"[tool.codespell]-ignore-words-list = "bu,wit,dont,cant,wont,re-use,re-used,re-using,re-usable,thats,doesnt"+ignore-words-list = "bu,wit,dont,cant,wont,re-use,re-used,re-using,re-usable,thats,doesnt,doubleclick"skip = "*.json"[tool.ruff]