Manages CDP event callbacks, network logs, and dialog state. Provides ordered, non-blocking event processing via an async worker queue to keep the WebSocket read loop responsive.
class EventsManager:
"""
Manages event callbacks, processing, and network logs.
Handles event callback registration, triggering, and maintains state
for network logs and dialog information.
"""
def __init__(self) -> None:
"""Initialize events manager with empty state."""
self._event_callbacks: dict[int, dict] = {}
self._callback_id = 0
self.network_logs: deque[RequestWillBeSentEvent] = deque(maxlen=MAX_NETWORK_LOGS)
self.dialog = JavascriptDialogOpeningEvent() # type: ignore
self._event_queue: asyncio.Queue = asyncio.Queue()
self._worker_task: Optional[asyncio.Task] = None
logger.info('EventsManager initialized')
logger.debug('Initial state: callbacks=0, logs=0, dialog=empty')
def start(
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key