diff --git a/py/private/bidi_enhancements_manifest.py b/py/private/bidi_enhancements_manifest.py index f8f033bcbc0fd..18db77aa67f10 100644 --- a/py/private/bidi_enhancements_manifest.py +++ b/py/private/bidi_enhancements_manifest.py @@ -1048,8 +1048,20 @@ def continue_request(self, **kwargs): params.update(kwargs) self._conn.execute(_cb("network.continueRequest", params))''', ], + # Override auth_required to use raw dict so _auth_callback receives all + # fields (including "request") from the BiDi event params. The + # generated AuthRequiredParameters dataclass only contains "response", + # losing the "request" field that holds the request ID required to call + # network.continueWithAuth. extra_events entries appear last in the + # EVENT_CONFIGS dict literal, so this duplicate key overrides the + # CDDL-generated entry. # Add before_request event (maps to network.beforeRequestSent) "extra_events": [ + { + "event_key": "auth_required", + "bidi_event": "network.authRequired", + "event_class": "dict", + }, { "event_key": "before_request", "bidi_event": "network.beforeRequestSent", diff --git a/py/selenium/webdriver/remote/websocket_connection.py b/py/selenium/webdriver/remote/websocket_connection.py index cd34c35db3696..4119776ce39aa 100644 --- a/py/selenium/webdriver/remote/websocket_connection.py +++ b/py/selenium/webdriver/remote/websocket_connection.py @@ -18,6 +18,7 @@ import dataclasses import json import logging +import threading from ssl import CERT_NONE from threading import Thread from time import sleep @@ -93,6 +94,7 @@ def __init__(self, url, timeout, interval): self.callbacks = {} self.session_id = None self._id = 0 + self._id_lock = threading.Lock() self._messages = {} self._started = False @@ -106,9 +108,11 @@ def close(self): self._ws = None def execute(self, command): - self._id += 1 + with self._id_lock: + self._id += 1 + current_id = self._id payload = self._serialize_command(command) - payload["id"] = self._id + payload["id"] = current_id if self.session_id: payload["sessionId"] = self.session_id @@ -116,8 +120,9 @@ def execute(self, command): logger.debug(f"-> {data}"[: self._max_log_message_size]) self._ws.send(data) - current_id = self._id self._wait_until(lambda: current_id in self._messages) + if current_id not in self._messages: + raise WebDriverException(f"Timed out waiting for response to BiDi command {current_id}") response = self._messages.pop(current_id) if "error" in response: