Skip to content

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

Fix request hanging and ensure proxy authentication works across tabs

matt-greathouseeb9556a0c3e1
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index 2c4643a13..1b20af9f9 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -1108,9 +1108,62 @@ class BrowserSession(BaseModel):
if request_id:
asyncio.create_task(_default())
+ def _on_request_paused(event: dict, session_id: SessionID | None = None):
+ # Continue all paused requests to avoid stalling the network
+ request_id = event.get('requestId') or event.get('request_id')
+ if not request_id:
+ return
+
+ async def _continue():
+ try:
+ await self._cdp_client_root.send.Fetch.continueRequest(
+ params={'requestId': request_id},
+ session_id=session_id,
+ )
+ except Exception:
+ pass
+
+ asyncio.create_task(_continue())
+
# Register event handler on root client
try:
self._cdp_client_root.register.Fetch.authRequired(_on_auth_required)
+ self._cdp_client_root.register.Fetch.requestPaused(_on_request_paused)
+ if self.agent_focus:
+ self.agent_focus.cdp_client.register.Fetch.authRequired(_on_auth_required)
+ self.agent_focus.cdp_client.register.Fetch.requestPaused(_on_request_paused)
+ except Exception:
+ pass
+
+ # Auto-enable Fetch on every newly attached target to ensure auth callbacks fire
+ def _on_attached(event: dict, session_id: SessionID | None = None):
+ sid = event.get('sessionId') or event.get('session_id') or session_id
+ if not sid:
+ return
+
+ async def _enable():
+ try:
+ await self._cdp_client_root.send.Fetch.enable(
+ params={'handleAuthRequests': True, 'patterns': [{'urlPattern': '*'}]},
+ session_id=sid,
+ )
+ except Exception:
+ pass
+
+ asyncio.create_task(_enable())
+
+ try:
+ self._cdp_client_root.register.Target.attachedToTarget(_on_attached)
+ except Exception:
+ pass
+
+ # Ensure Fetch is enabled for the current focused session, too
+ try:
+ if self.agent_focus:
+ await self.agent_focus.cdp_client.send.Fetch.enable(
+ params={'handleAuthRequests': True, 'patterns': [{'urlPattern': '*'}]},
+ session_id=self.agent_focus.session_id,
+ )
except Exception:
pass