Expand description
Value conversion for Playwright’s evaluate() method
This module handles bidirectional conversion between Rust types and Playwright’s JSON protocol format for the evaluate() expression method.
§Functions
serialize_argument<T>()- Converts Rust arguments to protocol formatserialize_null()- Serializes None/null valuesparse_value()- Deserializes protocol responsesparse_result()- Convenience wrapper for result deserialization
§Protocol Format
Playwright uses a type-tagged JSON format where each value includes type information:
{"v": "null"}- Null values{"v": "undefined"}- Undefined values{"b": true}- Boolean values{"n": 42}- Number values (int or float){"s": "hello"}- String values{"d": "2025-12-25T00:00:00.000Z"}- Date values (ISO 8601 format in UTC){"bi": "12345678901234567890"}- BigInt values (as strings){"u": "https://example.com"}- URL values (as strings){"e": {"m": "msg", "n": "name", "s": "stack"}}- Error objects{"ta": {"b": "base64...", "k": "ui8"}}- TypedArray values (base64 encoded){"a": [...], "id": 0}- Arrays (with circular reference tracking){"o": [...], "id": 1}- Objects (with circular reference tracking){"v": "Infinity"},{"v": "NaN"}- Special float values
§Example
ⓘ
use playwright_rs::protocol::{serialize_argument, parse_result};
use serde::Deserialize;
#[derive(Deserialize)]
struct Result {
sum: i32,
}
// Serialize argument for evaluate
let arg = 5;
let serialized = serialize_argument(&arg);
// After sending to Playwright and getting response back...
// Deserialize result from evaluate
let response_value = serde_json::json!({"n": 10});
let deserialized: i32 = serde_json::from_value(parse_result(&response_value))
.expect("Failed to deserialize result");§Implementation Notes
Based on playwright-python’s serialize_value and parse_value implementations: https://github.com/microsoft/playwright-python/blob/main/playwright/_impl/_js_handle.py
Functions§
- parse_
result - Parses a result from Playwright’s evaluate methods.
- parse_
value - Parses a value returned by Playwright’s evaluateExpression method.
- serialize_
argument - Serializes an argument for Playwright’s evaluateExpression method.
- serialize_
null - Convenience function to serialize None/null as an argument.