Intermittent CDP WebSocket connection drops during cloud browser sessions · Issue #4688 · browser-use/browser-use · GitHub
Skip to content

Intermittent CDP WebSocket connection drops during cloud browser sessions #4688

@lavish619

Description

@lavish619

Browser Use Version

0.12.6

Description

The CDP WebSocket connection to cloud browser sessions intermittently drops mid-interaction. After
the connection breaks, any CDP commands (e.g., export_storage_state(), DOMStorage queries,
Runtime.evaluate) fail because the underlying WebSocket is no longer alive.

This makes it impossible to export cookies/storage state at the end of a session, or inject
cookies/localStorage at the start, when the drop has occurred.

Environment

  • browser-use: Cloud sessions via API (BrowserSession(use_cloud=True))
  • Usage: Embedding the interactive remote cloud browser via the liveUrl endpoint — not using
    the browser-use Agent
  • Connection method: CDP URL provided by browser_session.cdp_url after
    browser_session.start()
  • API: api.browser-use.com/api/v2/browsers/{session_id}

How We Use Cloud Sessions

  1. Create a BrowserSession(use_cloud=True, id="session-xxx", cloud_timeout=10)
  2. Call await browser_session.start() to provision the cloud browser
  3. Retrieve liveUrl from the browser-use API to embed the interactive browser in our UI
  4. Inject cookies and localStorage into the browser via CDP (e.g., Network.setCookies,
    DOMStorage, Runtime.enable)
  5. The user interacts with the website in the embedded cloud browser
  6. After interaction, we call await browser_session.export_storage_state() and use CDP
    (DOMStorage.enable, DOMStorage.getDOMStorageItems, Runtime.evaluate) to extract cookies and
    localStorage

What Happens

The CDP WebSocket connection silently drops at random points — both during user interaction (step 5)
and during programmatic CDP operations (steps 4 and 6). The liveUrl embedded browser continues to
work fine from the user's perspective, but the CDP channel is dead.

Observed Logs

CDP WebSocket drop during session (reconnect fails):

2026-04-15 20:41:21,418 - WARNING - 🔌 CDP WebSocket message handler exited unexpectedly (connection
 closed)
2026-04-15 20:41:21,419 - WARNING - 🔄 WebSocket reconnection attempt 1/3...
2026-04-15 20:41:21,419 - INFO - [SessionManager] Cleared all owned data (targets, sessions,        
mappings)
2026-04-15 20:41:21,422 - INFO - Connecting to wss://b4ef91b5-e6e6-4ff5-94d4-56373819a1fc.cdp5.brows
er-use.com/devtools/browser/472ae21b-e24b-419c-83e6-888f755527bc (max frame size: 200MB)            
2026-04-15 20:41:24,419 - ERROR - Future exception was never retrieved
future: <Future finished exception=ConnectionError('Client is stopping')>                           
ConnectionError: Client is stopping                                                                 

After this, calling browser_session.export_storage_state() results in a timeout error since
there is no CDP connection to fulfill the request.

CDP failure when injecting cookies/localStorage into the session:

Traceback (most recent call last):
  File ".../backend/services/recording/session_manager.py", line 297, in start_session              
    await self._install_recorder(session)
  File ".../backend/services/recording/session_manager.py", line 865, in _install_recorder          
    await cdp.cdp_client.send.Runtime.enable(                                                       
  File ".../site-packages/cdp_use/cdp/runtime/library.py", line 134, in enable
    await self._client.send_raw(                                                                    
  File ".../site-packages/cdp_use/client.py", line 389, in send_raw                               
    return await future                                                                             
           ^^^^^^^^^^^^
ConnectionError: WebSocket connection closed                                                        

Failure Scenarios

Scenario What fails Error
During interaction CDP WebSocket drops silently `CDP WebSocket message handler exited
unexpectedly (connection closed)→ reconnect fails withConnectionError: Client is stopping`
Exporting cookies post-session export_storage_state() hangs Timeout — no CDP connection
to respond
Injecting cookies/storage at session start Runtime.enable, Network.setCookies etc.
ConnectionError: WebSocket connection closed

Reproduction

  • Difficult to reproduce — the issue occurs randomly across different websites and at different
    points during interaction.
  • It has been happening consistently over the past ~2 days.
  • Sometimes it works perfectly for several sessions in a row, then starts failing.
  • The issue resolves on its own temporarily, then reappears.

What I've Ruled Out

  • Not a client-side issue: Our code does not close or interfere with the CDP WebSocket. We have
    an _intentional_stop flag to suppress auto-reconnect only during explicit teardown.
  • Not a timeout issue: Sessions are well within the cloud_timeout window when the drop occurs.
  • Not related to high CDP traffic: The drop happens even during periods of low/no CDP command
    activity — just user interaction on the embedded page.

Expected Behavior

The CDP WebSocket connection should remain alive and usable for the entire duration of the cloud
session (up to cloud_timeout), regardless of what websites the user navigates to or interacts with
in the cloud browser.

Actual Behavior

The CDP WebSocket connection drops silently at unpredictable times. The built-in 3-attempt reconnect
loop fails. The cloud browser itself remains functional (visible via liveUrl), but all
programmatic CDP access is lost.

Impact

This blocks any CDP-dependent operation:

  • Exporting cookies via export_storage_state() → timeout
  • Extracting localStorage via CDP DOMStorage domain → connection error
  • Injecting cookies/localStorage into the session → WebSocket connection closed
  • Health checks via Runtime.evaluate → connection error

Questions

  1. Are there any known issues with CDP WebSocket stability on the cloud infrastructure?
  2. The reconnect attempts connect to the same wss://*.cdp5.browser-use.com URL but fail — is the
    CDP proxy invalidating the connection permanently after a drop?
  3. Is there a recommended way to detect and recover a dropped CDP connection without destroying the
    cloud session?
  4. Has anything changed in the cloud browser infrastructure recently that could explain the timing
    (past ~2 days)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions