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
When closing tabs, first check if we need to open a new one
Magnus Müllerbabe510c30bd
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex e8c24acad..527992530 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -698,8 +698,8 @@ class BrowserSession(BaseModel):"""Handle tab closure - update focus if needed."""cdp_session = await self.get_or_create_cdp_session(target_id=None, focus=False)+ event = await self.event_bus.dispatch(TabClosedEvent(target_id=event.target_id))await cdp_session.cdp_client.send.Target.closeTarget(params={'targetId': event.target_id})- await self.event_bus.dispatch(TabClosedEvent(target_id=event.target_id))async def on_TabClosedEvent(self, event: TabClosedEvent) -> None:"""Handle tab closure - update focus if needed."""