ChannelOwner

Trait ChannelOwner 

Source
pub trait ChannelOwner: Send + Sync {
Show 13 methods // Required methods fn guid(&self) -> &str; fn type_name(&self) -> &str; fn parent(&self) -> Option<Arc<dyn ChannelOwner>>; fn connection(&self) -> Arc<dyn ConnectionLike>; fn initializer(&self) -> &Value; fn channel(&self) -> &Channel; fn dispose(&self, reason: DisposeReason); fn adopt(&self, child: Arc<dyn ChannelOwner>); fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>); fn remove_child(&self, guid: &str); fn on_event(&self, method: &str, params: Value); fn was_collected(&self) -> bool; fn as_any(&self) -> &dyn Any;
}
Expand description

Base trait for all Playwright protocol objects.

Every object in the Playwright protocol (Browser, Page, BrowserContext, etc.) implements this trait to enable:

  • GUID-based object identity and lookup
  • Hierarchical parent-child lifecycle management
  • Channel-based RPC communication
  • Protocol event handling

§Architecture

All official Playwright bindings (Python, Java, .NET) follow this pattern:

  1. GUID Identity: Each object has a unique GUID from the server
  2. Parent-Child Tree: Objects form a hierarchy (e.g., Browser → BrowserContext → Page)
  3. Dual Registry: Objects are registered in both connection (global) and parent (lifecycle)
  4. Channel Communication: Objects send/receive messages via their Channel
  5. Event Handling: Protocol events are dispatched to objects by GUID

§Example

// Get object identity
println!("Object GUID: {}", browser.guid());
println!("Object type: {}", browser.type_name());

// Handle lifecycle
browser.dispose(playwright_core::channel_owner::DisposeReason::Closed);

Required Methods§

Source

fn guid(&self) -> &str

Returns the unique GUID for this object.

The GUID is assigned by the Playwright server and used for:

  • Looking up objects in the connection registry
  • Routing protocol messages to the correct object
  • Parent-child relationship tracking
Source

fn type_name(&self) -> &str

Returns the protocol type name (e.g., “Browser”, “Page”).

Source

fn parent(&self) -> Option<Arc<dyn ChannelOwner>>

Returns the parent object, if any.

The root Playwright object has no parent.

Source

fn connection(&self) -> Arc<dyn ConnectionLike>

Returns the connection this object belongs to.

Source

fn initializer(&self) -> &Value

Returns the raw initializer JSON from the server.

The initializer contains the object’s initial state sent in the __create__ protocol message.

Source

fn channel(&self) -> &Channel

Returns the channel for RPC communication.

Source

fn dispose(&self, reason: DisposeReason)

Disposes this object and all its children.

Called when:

  • Server sends __dispose__ message
  • User explicitly closes the object
  • Parent is disposed (cascades to children)
§Arguments
  • reason - Why the object is being disposed
Source

fn adopt(&self, child: Arc<dyn ChannelOwner>)

Adopts a child object (moves from old parent to this parent).

Called when server sends __adopt__ message, typically when:

  • A page is moved between browser contexts
  • An object’s ownership changes
Source

fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>)

Adds a child object to this parent’s registry.

Called during object creation and adoption.

Source

fn remove_child(&self, guid: &str)

Removes a child object from this parent’s registry.

Called during disposal and adoption.

Source

fn on_event(&self, method: &str, params: Value)

Handles a protocol event sent to this object.

§Arguments
  • method - Event name (e.g., “close”, “load”)
  • params - Event parameters as JSON
Source

fn was_collected(&self) -> bool

Returns true if this object was garbage collected.

Source

fn as_any(&self) -> &dyn Any

Enables downcasting to concrete types.

Required for converting Arc<dyn ChannelOwner> to specific types like Arc<Browser> when retrieving objects from the connection.

Implementors§