Skip to content

[🐛 Bug]: [py] CDP WebSocket connection timeout is too short #16260

@nxs7

Description

@nxs7

Description

The current implementation hard codes the WebSocket connection timeout for CDP to 30 seconds:

This works for most cases, but certain CDP methods can legitimately exceed this limit.

For example, HeapProfiler.takeHeapSnapshot only returns after the full snapshot has been sent via events. In my observations, on large webpages where the snapshot can exceed several hundred MBs, execution may take longer than 30 seconds. In such cases, WebSocketConnection._wait_until silently times out and returns, which in turn causes subsequent code to crash.

However, I'm not entirely sure the best way to fix the problem:

  • The most obvious solution would be to increase the timeout, but that's probably not optimal
  • Adding a parameter to the constructor WebSocketConnection would result in significant code changes, since all call sites need to be updated as well
  • Making the timeout a property could be confusing, since the constructor would still use the fixed timeout (though it likely won't hit the limit)

Reproducible Code

from selenium import webdriver
driver = webdriver.Chrome()
driver.get(<url_of_some_huge_webpage>)
devtools, connection = driver.start_devtools()
connection.on(devtools.heap_profiler.AddHeapSnapshotChunk, lambda x: print(len(x.chunk)))
connection.execute(devtools.heap_profiler.take_heap_snapshot())
driver.quit()

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-pyPython BindingsI-defectSomething is not working as intendedOS-windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions