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:
- GUID Identity: Each object has a unique GUID from the server
- Parent-Child Tree: Objects form a hierarchy (e.g., Browser → BrowserContext → Page)
- Dual Registry: Objects are registered in both connection (global) and parent (lifecycle)
- Channel Communication: Objects send/receive messages via their Channel
- 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§
Sourcefn guid(&self) -> &str
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
Sourcefn parent(&self) -> Option<Arc<dyn ChannelOwner>>
fn parent(&self) -> Option<Arc<dyn ChannelOwner>>
Returns the parent object, if any.
The root Playwright object has no parent.
Sourcefn connection(&self) -> Arc<dyn ConnectionLike>
fn connection(&self) -> Arc<dyn ConnectionLike>
Returns the connection this object belongs to.
Sourcefn initializer(&self) -> &Value
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.
Sourcefn dispose(&self, reason: DisposeReason)
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
Sourcefn adopt(&self, child: Arc<dyn ChannelOwner>)
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
Sourcefn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>)
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.
Sourcefn remove_child(&self, guid: &str)
fn remove_child(&self, guid: &str)
Removes a child object from this parent’s registry.
Called during disposal and adoption.
Sourcefn on_event(&self, method: &str, params: Value)
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
Sourcefn was_collected(&self) -> bool
fn was_collected(&self) -> bool
Returns true if this object was garbage collected.