Module connection

Module connection 

Source
Expand description

JSON-RPC Connection layer for Playwright protocol

This module implements the request/response correlation layer on top of the transport. It handles:

  • Generating unique request IDs
  • Correlating responses with pending requests
  • Distinguishing events from responses
  • Dispatching events to protocol objects

§Message Flow

  1. Client calls send_message() with GUID, method, and params
  2. Connection generates unique ID and creates oneshot channel
  3. Request is serialized and sent via transport
  4. Client awaits on the oneshot receiver
  5. Message loop receives response from transport
  6. Response is correlated by ID and sent via oneshot channel
  7. Client receives result

§Example

// Create transport (after launching server)
// let (transport, message_rx) = PipeTransport::new(stdin, stdout);

// Create connection
// let connection = Connection::new(transport, message_rx);

// Spawn message loop in background
// let conn = connection.clone();
// tokio::spawn(async move {
//     conn.run().await;
// });

// Send request and await response
// let result = connection.send_message(
//     "page@abc123",
//     "goto",
//     json!({"url": "https://example.com"})
// ).await?;

§References

Based on research of official Playwright bindings:

  • Python: playwright/_impl/_connection.py
  • Java: com/microsoft/playwright/impl/Connection.java
  • .NET: Microsoft.Playwright/Core/Connection.cs

Structs§

Connection
JSON-RPC connection to Playwright server
ErrorPayload
Protocol error details
ErrorWrapper
Wrapper for protocol error payload
Event
Protocol event message from Playwright server
Location
Source code location for a protocol call
Metadata
Metadata attached to every Playwright protocol message
Request
Protocol request message sent to Playwright server
Response
Protocol response message from Playwright server

Enums§

Message
Discriminated union of protocol messages

Traits§

ConnectionLike
Trait defining the interface that ChannelOwner needs from a Connection

Functions§

deserialize_arc_str
serialize_arc_str
Serde helpers for Arc<str> serialization

Type Aliases§

RealConnection