fix: suppress CDP error -32000 to prevent session corruption#22
fix: suppress CDP error -32000 to prevent session corruption#22FaisalFehad wants to merge 2 commits into
Conversation
When Browser.getWindowForTarget returns error -32000 ('Browser window not found'),
the CDP client raises RuntimeError which crashes the event handler and corrupts
the browser session. This occurs during race conditions when a target exists in
CDP but doesn't yet have an associated window (e.g., during file uploads, page
transitions, or new tab creation).
The fix returns a default window result instead of raising an exception, allowing
the session to continue normally. Other CDP errors are still raised as before.
Root cause analysis:
- _on_target_info_changed fires when a new target is discovered
- _trigger_page_target_discovered calls getWindowForTarget for the new target
- The target doesn't have a window yet, so CDP returns -32000
- The unhandled RuntimeError propagates up and corrupts the session
- All subsequent commands fail with 'Browser window not found'
Verified: file uploads, page navigation, and wait stable all work after this fix.
There was a problem hiding this comment.
1 issue found across 1 file
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
Track the CDP method name alongside each pending request future so that error -32000 suppression only applies to Browser.getWindowForTarget. Previously, any CDP method returning -32000 would receive a fabricated window-shaped result, silently corrupting downstream logic for unrelated methods. Changes: - pending_requests now stores (future, method) tuples instead of bare futures - send_raw stores the method name with the future - _handle_messages unpacks (future, request_method) and checks request_method == 'Browser.getWindowForTarget' before suppressing -32000 - Exception handlers updated to unpack (future, _) tuples
|
@cubic-dev-ai Issue addressed in commit 1e7577e. The -32000 suppression is now scoped to Changes:
No other CDP methods will receive fabricated window-shaped results. |
@FaisalFehad Looks good — the scoping change you made in commit 1e7577e cleanly addresses the concern about blanket -32000 suppression. A couple of observations on the implementation: What works well:
One minor thing worth considering: The default bounds you return ( Otherwise, this is a solid fix for a nasty race condition. The method-scoped suppression keeps it surgical while the race window stays open. Tip: get faster answers by chatting with cubic’s review copilot in the review UI |
Problem
When using browser automation tools that depend on cdp-use, file uploads and page transitions consistently cause browser sessions to become unusable with the error:
This makes all subsequent commands (
state,wait stable,screenshot, etc.) fail, rendering the browser session permanently broken.Root Cause
The error occurs during a race condition in the CDP event handler:
_on_target_info_changedfires when a new target is discovered (e.g., file upload or page navigation creates a new page context)_trigger_page_target_discoveredcallsBrowser.getWindowForTargetfor the new target-32000("Browser window not found")RuntimeErroris raised and propagates through the event handlerFix
In
CDPClient._handle_messages(), when a CDP response contains error-32000, return a default window result instead of raisingRuntimeError. This allows the session to continue normally — the target will get its window binding shortly after.Other CDP errors are still raised as
RuntimeErroras before.Testing
Verified with browser-act:
statecommand works after interactionswait stablecommand works after interactionsChanges
cdp_use/client.py: Added error suppression for CDP error code-32000in_handle_messages(), returning a default window result{"windowId": 0, "bounds": {"left": 0, "top": 0, "width": 1920, "height": 1080, "windowState": "normal"}}instead of raisingRuntimeError