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
- Client calls
send_message()with GUID, method, and params - Connection generates unique ID and creates oneshot channel
- Request is serialized and sent via transport
- Client awaits on the oneshot receiver
- Message loop receives response from transport
- Response is correlated by ID and sent via oneshot channel
- 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
- Error
Payload - Protocol error details
- Error
Wrapper - 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§
- Connection
Like - Trait defining the interface that ChannelOwner needs from a Connection
Functions§
- deserialize_
arc_ str - serialize_
arc_ str - Serde helpers for
Arc<str>serialization