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
add BrowserSession.kill method to get around keep_alive=False
Nick Sweeting771ec25aded2
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 9d9196b0f..53aa97e28 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -292,7 +292,7 @@ class BrowserSession(BaseModel):return selfasync def stop(self) -> None:- """Shuts down the BrowserSession, killing the browser process if keep_alive=False"""+ """Shuts down the BrowserSession, killing the browser process (only works if keep_alive=False)"""self.initialized = False@@ -321,11 +321,17 @@ class BrowserSession(BaseModel):logger.debug(f'❌ Error terminating subprocess with browser_pid={self.browser_pid}: {type(e).__name__}: {e}')async def close(self) -> None:- """Deprecated: Provides backwards-compatibility with old class method Browser().close()"""+ """Deprecated: Provides backwards-compatibility with old method Browser().close() and playwright BrowserContext.close()"""+ await self.stop()++ async def kill(self) -> None:+ """Stop the BrowserSession even if keep_alive=True"""+ self.keep_alive = Falseawait self.stop()async def new_context(self, **kwargs):- """Deprecated: Provides backwards-compatibility with old class method Browser().new_context()"""+ """Deprecated: Provides backwards-compatibility with old class method Browser().new_context()."""+ # TODO: remove this after >=0.3.0return selfasync def __aenter__(self) -> BrowserSession: