Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

don't explicitly pass newWindow: false to CDP createTarget

Laith Weinbergerb051fe2a7a64
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index 6ceb2d253..d7aca4f24 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -3205,16 +3205,16 @@ class BrowserSession(BaseModel):
async def _cdp_create_new_page(self, url: str = 'about:blank', background: bool = False, new_window: bool = False) -> str:
"""Create a new page/tab using CDP Target.createTarget. Returns target ID."""
+ # Only include newWindow when True, letting Chrome auto-create window as needed
+ params: dict[str, Any] = {'url': url, 'background': background}
+ if new_window:
+ params['newWindow'] = True
# Use the root CDP client to create tabs at the browser level
if self._cdp_client_root:
- result = await self._cdp_client_root.send.Target.createTarget(
- params={'url': url, 'newWindow': new_window, 'background': background}
- )
+ result = await self._cdp_client_root.send.Target.createTarget(params=params)
else:
# Fallback to using cdp_client if root is not available
- result = await self.cdp_client.send.Target.createTarget(
- params={'url': url, 'newWindow': new_window, 'background': background}
- )
+ result = await self.cdp_client.send.Target.createTarget(params=params)
return result['targetId']
async def _cdp_close_page(self, target_id: TargetID) -> None: