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 with ansdkLanguagethe driver accepts (seeRoot::initializefor why it is not"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 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.
§Why sdkLanguage is "python", not "rust"
The driver’s protocol validator accepts only
javascript, python, java, and csharp, so "rust" is rejected
outright. "python" is the closest fit: its async/await shape matches
this crate’s, and its error text (playwright install) reads correctly.
One visible consequence: the driver records this value in trace files, so the Playwright trace viewer labels traces produced by this crate as Python and renders action snippets in Python syntax. Protocol behavior is unaffected.
§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