Merged
Conversation
…rror When network.beforeRequestSent callbacks fire during a page load they run in daemon threads (via Thread.start() in _process_message). If those callbacks call continue_request() -> execute() concurrently with the main thread also inside execute(), two bugs trigger: 1. self._id was incremented without a lock, and current_id was captured *after* self._ws.send(). A context switch between send() and the capture let another thread increment self._id so current_id picked up the wrong value, causing one thread to wait for a message ID it would never receive. 2. _wait_until() returns silently on timeout, so the subsequent self._messages.pop(current_id) raised an opaque KeyError: 24 instead of a useful exception. Fix: - Add self._id_lock (threading.Lock) and atomically increment + capture current_id inside the lock, before serialising the payload. - Use current_id for payload["id"] instead of self._id. - After _wait_until(), raise WebDriverException with a clear message when the expected response never arrived. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The generated AuthRequiredParameters dataclass only has a 'response'
field, losing the 'request' field that contains the BiDi request ID
needed to call network.continueWithAuth.
_auth_callback in add_auth_handler extracts request_id via:
raw.get("request", {}).get("request")
When the event is deserialized to AuthRequiredParameters the 'request'
key is filtered out by _EventWrapper.from_json (only valid dataclass
fields are kept), so request_id is always None and continueWithAuth
is never sent. Chrome then holds the intercepted request open
indefinitely, causing browsingContext.navigate to time out after 30 s.
Fix: add 'auth_required' to extra_events in the network module's
bidi_enhancements_manifest entry with event_class='dict'. The generator
appends extra_events at the end of the EVENT_CONFIGS dict literal, so
this duplicate key overrides the CDDL-generated entry. _EventWrapper
then returns the raw params dict (camelCase keys intact) and
request_id is extracted correctly.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves reliability of the Python WebDriver BiDi transport and network event handling, targeting observed network-related failures in BiDi workflows.
Changes:
- Make BiDi command ID generation thread-safe in
WebSocketConnection.execute(). - Raise a clearer
WebDriverExceptionwhen a BiDi command response times out (instead of failing later with aKeyError). - Override the
network.authRequiredevent mapping to pass raw event params (dict) so auth handlers can access the request ID.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
py/selenium/webdriver/remote/websocket_connection.py |
Adds a lock for _id and improves timeout error handling when awaiting BiDi command responses. |
py/private/bidi_enhancements_manifest.py |
Overrides auth_required event config to use raw dict params so auth handlers receive required fields (e.g., request). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Related Issues
💥 What does this PR do?
🔧 Implementation Notes
🤖 AI assistance
💡 Additional Considerations
🔄 Types of changes