[🐛 Bug]: [py] BiDi network events: response_started callback gets a dict, response_completed gets a dataclass

Abierto
#18,394 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
api, backend

Línea de trabajo

Start by reading py/private/bidi_enhancements_manifest.py and the generated network parameter dataclasses, then trace how driver.network.add_event_handler() dispatches callbacks and how _network_handlers.py uses raw params. Check existing BiDi network tests for callback types. Done means callbacks receive a consistent data type across the listed events, with tests covering the affected events and internal handlers still working.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

C-py D-chrome OS-windows
Description

In the Python bindings, driver.network.add_event_handler() passes different kinds of data to the callback depending on the event:

Event Callback receives
response_started dict (camelCase keys, e.g. event["isBlocked"])
response_completed ResponseCompletedParameters dataclass (snake_case, e.g. event.is_blocked)
before_request_sent BeforeRequestSentParameters dataclass
before_request (alias) dict
auth_required dict

Expected: consistent callback data for all network events.
Actual: user code has to treat events differently. For example, the docs examples need event["response"]["status"] for one event and event.response["status"] for the next one on the same page.

Cause: py/private/bidi_enhancements_manifest.py adds extra_events entries with "event_class": "dict" for auth_required, before_request and response_started. Because those entries come last in the EVENT_CONFIGS dict literal, they override the CDDL-generated typed entries. The comment explains why:

the generated ResponseStartedParameters dataclass only contains "response", losing "request", "isBlocked" and "intercepts"

That no longer seems to be true. In 4.54.0, the generated dataclasses contain all the base parameters:

ResponseStartedParameters   ['response', 'context', 'is_blocked', 'navigation', 'redirect_count', 'request', 'timestamp', 'user_context', 'intercepts']
AuthRequiredParameters      ['response', 'context', 'is_blocked', 'navigation', 'redirect_count', 'request', 'timestamp', 'user_context', 'intercepts']
BeforeRequestSentParameters ['initiator', 'context', 'is_blocked', 'navigation', 'redirect_count', 'request', 'timestamp', 'user_context', 'intercepts']

Question: should the public add_event_handler() callbacks receive the typed dataclasses for every event? The internal handler registries in _network_handlers.py could keep using raw params. If maintainers agree on a direction, I'm happy to send a PR.

Reproducible Code
import time
from selenium import webdriver

options = webdriver.ChromeOptions()
options.enable_bidi = True
driver = webdriver.Chrome(options=options)

seen = {}
driver.network.add_event_handler("response_started", lambda e: seen.setdefault("started", type(e)))
driver.network.add_event_handler("response_completed", lambda e: seen.setdefault("completed", type(e)))
driver.get("https://www.selenium.dev/selenium/web/blank.html")
time.sleep(1)
print(seen)
driver.quit()

# Output:
# {'started': <class 'dict'>, 'completed': <class 'selenium.webdriver.common.bidi.network.ResponseCompletedParameters'>}
Debugging Logs
No errors; this is about the type passed to the callback.
Lenguaje dominante
Java
Estrellas
34.6k
Forks
8.7k
Merge medio
1 d 16 h
PR fusionados (30 d)
107

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de SeleniumHQ/selenium

Todos los issues de SeleniumHQ/selenium

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.