pub struct Root { /* private fields */ }Expand description
Root object for sending the initialize message to the Playwright server
This is an internal object not exposed to end users. It exists solely to
send the initialize message to the server during connection setup.
§Protocol Flow
When initialize() is called:
- Sends
initializemessage withsdkLanguage: "rust" - Server creates BrowserType objects (sends
__create__messages) - Server creates Playwright object (sends
__create__message) - Server responds with Playwright GUID:
{ "playwright": { "guid": "..." } } - All objects are now in the connection’s object registry
The Root object has an empty GUID ("") and is not registered in the
object registry. It’s discarded after initialization completes.
§Example
ⓘ
// Create root object with connection
let root = Root::new(connection.clone());
// Send initialize message to server
let response = root.initialize().await?;
// Verify Playwright GUID is returned
let playwright_guid = response["playwright"]["guid"]
.as_str()
.expect("Missing playwright.guid");
assert!(!playwright_guid.is_empty());
assert!(playwright_guid.contains("playwright"));
// Verify response contains BrowserType objects
assert!(response["playwright"].is_object());See:
Implementations§
Source§impl Root
impl Root
Sourcepub fn new(connection: Arc<dyn ConnectionLike>) -> Self
pub fn new(connection: Arc<dyn ConnectionLike>) -> Self
Sourcepub async fn initialize(&self) -> Result<Value>
pub async fn initialize(&self) -> Result<Value>
Send the initialize message to the Playwright server
This is a synchronous request that blocks until the server responds. By the time the response arrives, all protocol objects (Playwright, BrowserType, etc.) will have been created and registered.
§Returns
The server response containing the Playwright object GUID:
{
"playwright": {
"guid": "playwright"
}
}§Errors
Returns error if:
- Message send fails
- Server returns protocol error
- Connection is closed
Trait Implementations§
Source§impl ChannelOwner for Root
impl ChannelOwner for Root
Source§fn parent(&self) -> Option<Arc<dyn ChannelOwner>>
fn parent(&self) -> Option<Arc<dyn ChannelOwner>>
Returns the parent object, if any. Read more
Source§fn connection(&self) -> Arc<dyn ConnectionLike>
fn connection(&self) -> Arc<dyn ConnectionLike>
Returns the connection this object belongs to.
Source§fn initializer(&self) -> &Value
fn initializer(&self) -> &Value
Returns the raw initializer JSON from the server. Read more
Source§fn dispose(&self, reason: DisposeReason)
fn dispose(&self, reason: DisposeReason)
Disposes this object and all its children. Read more
Source§fn adopt(&self, child: Arc<dyn ChannelOwner>)
fn adopt(&self, child: Arc<dyn ChannelOwner>)
Adopts a child object (moves from old parent to this parent). Read more
Source§fn 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. Read more
Source§fn remove_child(&self, guid: &str)
fn remove_child(&self, guid: &str)
Removes a child object from this parent’s registry. Read more
Source§fn on_event(&self, method: &str, params: Value)
fn on_event(&self, method: &str, params: Value)
Handles a protocol event sent to this object. Read more
Source§fn was_collected(&self) -> bool
fn was_collected(&self) -> bool
Returns true if this object was garbage collected.
Auto Trait Implementations§
impl !Freeze for Root
impl !RefUnwindSafe for Root
impl Send for Root
impl Sync for Root
impl Unpin for Root
impl !UnwindSafe for Root
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more