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 `Memory` domain.
//!
//! Types, command parameters and event payloads for the `Memory`
//! 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};

/// Memory pressure level.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum PressureLevel {
    /// `moderate`
    #[serde(rename = "moderate")]
    Moderate,
    /// `critical`
    #[serde(rename = "critical")]
    Critical,
    /// 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),
}

/// Heap profile sample.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SamplingProfileNode {
    /// Size of the sampled allocation.
    pub size: f64,
    /// Total bytes attributed to this sample.
    pub total: f64,
    /// Execution stack at the point of allocation.
    pub stack: Vec<String>,
}

/// Array of heap profile samples.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SamplingProfile {
    pub samples: Vec<SamplingProfileNode>,
    pub modules: Vec<Module>,
}

/// Executable module information
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Module {
    /// Name of the module.
    pub name: String,
    /// UUID of the module.
    pub uuid: String,
    /// Base address where the module is loaded into memory. Encoded as a decimal
    /// or hexadecimal (0x prefixed) string.
    #[serde(rename = "baseAddress")]
    pub base_address: String,
    /// Size of the module in bytes.
    pub size: f64,
}

/// DOM object counter data.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DomCounter {
    /// Object name. Note: object names should be presumed volatile and clients
    /// should not expect the returned names to be consistent across runs.
    pub name: String,
    /// Object count.
    pub count: i64,
}

/// Retruns current DOM object counters.
///
/// Parameters of `Memory.getDOMCounters`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetDomCountersParams {}

/// What `Memory.getDOMCounters` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetDomCountersReturns {
    pub documents: i64,
    pub nodes: i64,
    #[serde(rename = "jsEventListeners")]
    pub js_event_listeners: i64,
}

impl crate::typed::Command for GetDomCountersParams {
    const METHOD: &'static str = "Memory.getDOMCounters";
    type Returns = GetDomCountersReturns;
}

/// Retruns DOM object counters after preparing renderer for leak detection.
///
/// Parameters of `Memory.getDOMCountersForLeakDetection`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetDomCountersForLeakDetectionParams {}

/// What `Memory.getDOMCountersForLeakDetection` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetDomCountersForLeakDetectionReturns {
    /// DOM object counters.
    pub counters: Vec<DomCounter>,
}

impl crate::typed::Command for GetDomCountersForLeakDetectionParams {
    const METHOD: &'static str = "Memory.getDOMCountersForLeakDetection";
    type Returns = GetDomCountersForLeakDetectionReturns;
}

/// Prepares for leak detection by terminating workers, stopping
/// spellcheckers, dropping non-essential internal caches, running garbage
/// collections, etc.
///
/// Parameters of `Memory.prepareForLeakDetection`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PrepareForLeakDetectionParams {}

impl crate::typed::Command for PrepareForLeakDetectionParams {
    const METHOD: &'static str = "Memory.prepareForLeakDetection";
    type Returns = crate::typed::NoReturns;
}

/// Simulate OomIntervention by purging V8 memory.
///
/// Parameters of `Memory.forciblyPurgeJavaScriptMemory`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ForciblyPurgeJavaScriptMemoryParams {}

impl crate::typed::Command for ForciblyPurgeJavaScriptMemoryParams {
    const METHOD: &'static str = "Memory.forciblyPurgeJavaScriptMemory";
    type Returns = crate::typed::NoReturns;
}

/// Enable/disable suppressing memory pressure notifications in all processes.
///
/// Parameters of `Memory.setPressureNotificationsSuppressed`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetPressureNotificationsSuppressedParams {
    /// If true, memory pressure notifications will be suppressed.
    pub suppressed: bool,
}

impl crate::typed::Command for SetPressureNotificationsSuppressedParams {
    const METHOD: &'static str = "Memory.setPressureNotificationsSuppressed";
    type Returns = crate::typed::NoReturns;
}

/// Simulate a memory pressure notification in all processes.
///
/// Parameters of `Memory.simulatePressureNotification`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SimulatePressureNotificationParams {
    /// Memory pressure level of the notification.
    pub level: PressureLevel,
}

impl crate::typed::Command for SimulatePressureNotificationParams {
    const METHOD: &'static str = "Memory.simulatePressureNotification";
    type Returns = crate::typed::NoReturns;
}

/// Start collecting native memory profile.
///
/// Parameters of `Memory.startSampling`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StartSamplingParams {
    /// Average number of bytes between samples.
    #[serde(
        rename = "samplingInterval",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub sampling_interval: Option<i64>,
    /// Do not randomize intervals between samples.
    #[serde(
        rename = "suppressRandomness",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub suppress_randomness: Option<bool>,
}

impl crate::typed::Command for StartSamplingParams {
    const METHOD: &'static str = "Memory.startSampling";
    type Returns = crate::typed::NoReturns;
}

/// Stop collecting native memory profile.
///
/// Parameters of `Memory.stopSampling`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StopSamplingParams {}

impl crate::typed::Command for StopSamplingParams {
    const METHOD: &'static str = "Memory.stopSampling";
    type Returns = crate::typed::NoReturns;
}

/// Retrieve native memory allocations profile collected since renderer
/// process startup.
///
/// Parameters of `Memory.getAllTimeSamplingProfile`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetAllTimeSamplingProfileParams {}

/// What `Memory.getAllTimeSamplingProfile` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetAllTimeSamplingProfileReturns {
    pub profile: SamplingProfile,
}

impl crate::typed::Command for GetAllTimeSamplingProfileParams {
    const METHOD: &'static str = "Memory.getAllTimeSamplingProfile";
    type Returns = GetAllTimeSamplingProfileReturns;
}

/// Retrieve native memory allocations profile collected since browser process
/// startup.
///
/// Parameters of `Memory.getBrowserSamplingProfile`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetBrowserSamplingProfileParams {}

/// What `Memory.getBrowserSamplingProfile` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetBrowserSamplingProfileReturns {
    pub profile: SamplingProfile,
}

impl crate::typed::Command for GetBrowserSamplingProfileParams {
    const METHOD: &'static str = "Memory.getBrowserSamplingProfile";
    type Returns = GetBrowserSamplingProfileReturns;
}

/// Retrieve native memory allocations profile collected since last
/// `startSampling` call.
///
/// Parameters of `Memory.getSamplingProfile`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetSamplingProfileParams {}

/// What `Memory.getSamplingProfile` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetSamplingProfileReturns {
    pub profile: SamplingProfile,
}

impl crate::typed::Command for GetSamplingProfileParams {
    const METHOD: &'static str = "Memory.getSamplingProfile";
    type Returns = GetSamplingProfileReturns;
}