playwright: [Bug]: connect_over_cdp getting stuck

Version

1.52.0

Steps to reproduce

Steps:

  1. Launch Microsoft Edge in debugging mode with custom user profile:
msedge.exe --user-data-dir="C:\Users\{user}\tmp" --remote-debugging-port=1234
  1. Run minimal code example:
from playwright.sync_api import sync_playwright
pw = sync_playwright().start()
browser = pw.chromium.connect_over_cdp("http://localhost:1234", timeout=30000)
print("connected")

Expected behavior

  1. connect_over_cdp to finish
  2. “connected” to print

Actual behavior

  1. connect_over_cdp times out
  2. Code never completes

connect_over_cdp times out even though the websocket connected:

playwright._impl._errors.TimeoutError: BrowserType.connect_over_cdp: Timeout 30000ms exceeded.
Call log:
  - <ws connecting> ws://localhost:1234/devtools/browser/9bf56b42-3a66-484b-a76e-9b8ce783555b
  - <ws connected> ws://localhost:1234/devtools/browser/9bf56b42-3a66-484b-a76e-9b8ce783555b

Additional context

This behavior still occurs with longer timeout windows (e.g., 5 minutes, 1 hour) or if you provide the websocket from localhost:{port}/json/version instead of just localhost.

The error traces back to the _sync function within SyncBase:

...
task.add_done_callback(lambda _: g_self.switch())
while not task.done():
    self._dispatcher_fiber.switch()
asyncio._set_running_loop(self._loop)
return task.result()

The timeout is happening during the self._dispatcher_fiber.switch() call

Environment

- Operating System: Windows 11
- CPU: Intel Ultra 7 165U
- Browser: Microsoft Edge
- Python Version: 3.13
- Other info:

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

@Skn0tt Yes, it’s caused by that change. now the command of starting chrome should add -user-data-dir.

If it’s related to upgrading Chrome, then it’s probably this: https://developer.chrome.com/blog/remote-debugging-port