cdp-driver 0.5.0

Chrome DevTools Protocol (CDP) client for Rust: every command, event and type generated from the schema, with sessions, for browser automation and AI agents
Documentation
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! The `LayerTree` domain.
//!
//! Types, command parameters and event payloads for the `LayerTree`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].
//!
//! This domain is experimental and may change without notice.

use serde::{Deserialize, Serialize};

/// Unique Layer identifier.
pub type LayerId = String;

/// Unique snapshot identifier.
pub type SnapshotId = String;

/// Rectangle where scrolling happens on the main thread.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ScrollRect {
    /// Rectangle itself.
    pub rect: crate::protocol::dom::Rect,
    /// Reason for rectangle to force scrolling on the main thread
    pub r#type: ScrollRectType,
}

/// The values `type` accepts on `ScrollRect`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ScrollRectType {
    /// `RepaintsOnScroll`
    RepaintsOnScroll,
    /// `TouchEventHandler`
    TouchEventHandler,
    /// `WheelEventHandler`
    WheelEventHandler,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Sticky position constraints.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StickyPositionConstraint {
    /// Layout rectangle of the sticky element before being shifted
    #[serde(rename = "stickyBoxRect")]
    pub sticky_box_rect: crate::protocol::dom::Rect,
    /// Layout rectangle of the containing block of the sticky element
    #[serde(rename = "containingBlockRect")]
    pub containing_block_rect: crate::protocol::dom::Rect,
    /// The nearest sticky layer that shifts the sticky box
    #[serde(
        rename = "nearestLayerShiftingStickyBox",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub nearest_layer_shifting_sticky_box: Option<LayerId>,
    /// The nearest sticky layer that shifts the containing block
    #[serde(
        rename = "nearestLayerShiftingContainingBlock",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub nearest_layer_shifting_containing_block: Option<LayerId>,
}

/// Serialized fragment of layer picture along with its offset within the
/// layer.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PictureTile {
    /// Offset from owning layer left boundary
    pub x: f64,
    /// Offset from owning layer top boundary
    pub y: f64,
    /// Base64-encoded snapshot data. (Encoded as a base64 string when passed over
    /// JSON)
    pub picture: String,
}

/// Information about a compositing layer.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Layer {
    /// The unique id for this layer.
    #[serde(rename = "layerId")]
    pub layer_id: LayerId,
    /// The id of parent (not present for root).
    #[serde(
        rename = "parentLayerId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub parent_layer_id: Option<LayerId>,
    /// The backend id for the node associated with this layer.
    #[serde(
        rename = "backendNodeId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub backend_node_id: Option<crate::protocol::dom::BackendNodeId>,
    /// Offset from parent layer, X coordinate.
    #[serde(rename = "offsetX")]
    pub offset_x: f64,
    /// Offset from parent layer, Y coordinate.
    #[serde(rename = "offsetY")]
    pub offset_y: f64,
    /// Layer width.
    pub width: f64,
    /// Layer height.
    pub height: f64,
    /// Transformation matrix for layer, default is identity matrix
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub transform: Option<Vec<f64>>,
    /// Transform anchor point X, absent if no transform specified
    #[serde(rename = "anchorX", default, skip_serializing_if = "Option::is_none")]
    pub anchor_x: Option<f64>,
    /// Transform anchor point Y, absent if no transform specified
    #[serde(rename = "anchorY", default, skip_serializing_if = "Option::is_none")]
    pub anchor_y: Option<f64>,
    /// Transform anchor point Z, absent if no transform specified
    #[serde(rename = "anchorZ", default, skip_serializing_if = "Option::is_none")]
    pub anchor_z: Option<f64>,
    /// Indicates how many time this layer has painted.
    #[serde(rename = "paintCount")]
    pub paint_count: i64,
    /// Indicates whether this layer hosts any content, rather than being used for
    /// transform/scrolling purposes only.
    #[serde(rename = "drawsContent")]
    pub draws_content: bool,
    /// Set if layer is not visible.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub invisible: Option<bool>,
    /// Rectangles scrolling on main thread only.
    #[serde(
        rename = "scrollRects",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub scroll_rects: Option<Vec<ScrollRect>>,
    /// Sticky position constraint information
    #[serde(
        rename = "stickyPositionConstraint",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub sticky_position_constraint: Option<StickyPositionConstraint>,
}

/// Array of timings, one per paint step.
pub type PaintProfile = Vec<f64>;

/// Provides the reasons why the given layer was composited.
///
/// Parameters of `LayerTree.compositingReasons`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CompositingReasonsParams {
    /// The id of the layer for which we want to get the reasons it was
    /// composited.
    #[serde(rename = "layerId")]
    pub layer_id: LayerId,
}

/// What `LayerTree.compositingReasons` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CompositingReasonsReturns {
    /// A list of strings specifying reasons for the given layer to become
    /// composited.
    #[serde(rename = "compositingReasons")]
    pub compositing_reasons: Vec<String>,
    /// A list of strings specifying reason IDs for the given layer to become
    /// composited.
    #[serde(rename = "compositingReasonIds")]
    pub compositing_reason_ids: Vec<String>,
}

impl crate::typed::Command for CompositingReasonsParams {
    const METHOD: &'static str = "LayerTree.compositingReasons";
    type Returns = CompositingReasonsReturns;
}

/// Disables compositing tree inspection.
///
/// Parameters of `LayerTree.disable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DisableParams {}

impl crate::typed::Command for DisableParams {
    const METHOD: &'static str = "LayerTree.disable";
    type Returns = crate::typed::NoReturns;
}

/// Enables compositing tree inspection.
///
/// Parameters of `LayerTree.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {}

impl crate::typed::Command for EnableParams {
    const METHOD: &'static str = "LayerTree.enable";
    type Returns = crate::typed::NoReturns;
}

/// Returns the snapshot identifier.
///
/// Parameters of `LayerTree.loadSnapshot`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LoadSnapshotParams {
    /// An array of tiles composing the snapshot.
    pub tiles: Vec<PictureTile>,
}

/// What `LayerTree.loadSnapshot` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LoadSnapshotReturns {
    /// The id of the snapshot.
    #[serde(rename = "snapshotId")]
    pub snapshot_id: SnapshotId,
}

impl crate::typed::Command for LoadSnapshotParams {
    const METHOD: &'static str = "LayerTree.loadSnapshot";
    type Returns = LoadSnapshotReturns;
}

/// Returns the layer snapshot identifier.
///
/// Parameters of `LayerTree.makeSnapshot`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct MakeSnapshotParams {
    /// The id of the layer.
    #[serde(rename = "layerId")]
    pub layer_id: LayerId,
}

/// What `LayerTree.makeSnapshot` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct MakeSnapshotReturns {
    /// The id of the layer snapshot.
    #[serde(rename = "snapshotId")]
    pub snapshot_id: SnapshotId,
}

impl crate::typed::Command for MakeSnapshotParams {
    const METHOD: &'static str = "LayerTree.makeSnapshot";
    type Returns = MakeSnapshotReturns;
}

/// Parameters of `LayerTree.profileSnapshot`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ProfileSnapshotParams {
    /// The id of the layer snapshot.
    #[serde(rename = "snapshotId")]
    pub snapshot_id: SnapshotId,
    /// The maximum number of times to replay the snapshot (1, if not specified).
    #[serde(
        rename = "minRepeatCount",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub min_repeat_count: Option<i64>,
    /// The minimum duration (in seconds) to replay the snapshot.
    #[serde(
        rename = "minDuration",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub min_duration: Option<f64>,
    /// The clip rectangle to apply when replaying the snapshot.
    #[serde(rename = "clipRect", default, skip_serializing_if = "Option::is_none")]
    pub clip_rect: Option<crate::protocol::dom::Rect>,
}

/// What `LayerTree.profileSnapshot` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ProfileSnapshotReturns {
    /// The array of paint profiles, one per run.
    pub timings: Vec<PaintProfile>,
}

impl crate::typed::Command for ProfileSnapshotParams {
    const METHOD: &'static str = "LayerTree.profileSnapshot";
    type Returns = ProfileSnapshotReturns;
}

/// Releases layer snapshot captured by the back-end.
///
/// Parameters of `LayerTree.releaseSnapshot`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ReleaseSnapshotParams {
    /// The id of the layer snapshot.
    #[serde(rename = "snapshotId")]
    pub snapshot_id: SnapshotId,
}

impl crate::typed::Command for ReleaseSnapshotParams {
    const METHOD: &'static str = "LayerTree.releaseSnapshot";
    type Returns = crate::typed::NoReturns;
}

/// Replays the layer snapshot and returns the resulting bitmap.
///
/// Parameters of `LayerTree.replaySnapshot`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ReplaySnapshotParams {
    /// The id of the layer snapshot.
    #[serde(rename = "snapshotId")]
    pub snapshot_id: SnapshotId,
    /// The first step to replay from (replay from the very start if not
    /// specified).
    #[serde(rename = "fromStep", default, skip_serializing_if = "Option::is_none")]
    pub from_step: Option<i64>,
    /// The last step to replay to (replay till the end if not specified).
    #[serde(rename = "toStep", default, skip_serializing_if = "Option::is_none")]
    pub to_step: Option<i64>,
    /// The scale to apply while replaying (defaults to 1).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub scale: Option<f64>,
}

/// What `LayerTree.replaySnapshot` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ReplaySnapshotReturns {
    /// A data: URL for resulting image.
    #[serde(rename = "dataURL")]
    pub data_url: String,
}

impl crate::typed::Command for ReplaySnapshotParams {
    const METHOD: &'static str = "LayerTree.replaySnapshot";
    type Returns = ReplaySnapshotReturns;
}

/// Replays the layer snapshot and returns canvas log.
///
/// Parameters of `LayerTree.snapshotCommandLog`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SnapshotCommandLogParams {
    /// The id of the layer snapshot.
    #[serde(rename = "snapshotId")]
    pub snapshot_id: SnapshotId,
}

/// What `LayerTree.snapshotCommandLog` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SnapshotCommandLogReturns {
    /// The array of canvas function calls.
    #[serde(rename = "commandLog")]
    pub command_log: Vec<serde_json::Value>,
}

impl crate::typed::Command for SnapshotCommandLogParams {
    const METHOD: &'static str = "LayerTree.snapshotCommandLog";
    type Returns = SnapshotCommandLogReturns;
}

/// Payload of the `LayerTree.layerPainted` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LayerPaintedEvent {
    /// The id of the painted layer.
    #[serde(rename = "layerId")]
    pub layer_id: LayerId,
    /// Clip rectangle.
    pub clip: crate::protocol::dom::Rect,
}

impl crate::typed::Event for LayerPaintedEvent {
    const METHOD: &'static str = "LayerTree.layerPainted";
}

/// Payload of the `LayerTree.layerTreeDidChange` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LayerTreeDidChangeEvent {
    /// Layer tree, absent if not in the compositing mode.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub layers: Option<Vec<Layer>>,
}

impl crate::typed::Event for LayerTreeDidChangeEvent {
    const METHOD: &'static str = "LayerTree.layerTreeDidChange";
}