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.

//! Defines events for background web platform features.
//!
//! Types, command parameters and event payloads for the `BackgroundService`
//! 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};

/// The Background Service that will be associated with the commands/events.
/// Every Background Service operates independently, but they share the same
/// API.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ServiceName {
    /// `backgroundFetch`
    #[serde(rename = "backgroundFetch")]
    BackgroundFetch,
    /// `backgroundSync`
    #[serde(rename = "backgroundSync")]
    BackgroundSync,
    /// `pushMessaging`
    #[serde(rename = "pushMessaging")]
    PushMessaging,
    /// `notifications`
    #[serde(rename = "notifications")]
    Notifications,
    /// `paymentHandler`
    #[serde(rename = "paymentHandler")]
    PaymentHandler,
    /// `periodicBackgroundSync`
    #[serde(rename = "periodicBackgroundSync")]
    PeriodicBackgroundSync,
    /// 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),
}

/// A key-value pair for additional event information to pass along.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EventMetadata {
    pub key: String,
    pub value: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BackgroundServiceEvent {
    /// Timestamp of the event (in seconds).
    pub timestamp: crate::protocol::network::TimeSinceEpoch,
    /// The origin this event belongs to.
    pub origin: String,
    /// The Service Worker ID that initiated the event.
    #[serde(rename = "serviceWorkerRegistrationId")]
    pub service_worker_registration_id: crate::protocol::service_worker::RegistrationId,
    /// The Background Service this event belongs to.
    pub service: ServiceName,
    /// A description of the event.
    #[serde(rename = "eventName")]
    pub event_name: String,
    /// An identifier that groups related events together.
    #[serde(rename = "instanceId")]
    pub instance_id: String,
    /// A list of event-specific information.
    #[serde(rename = "eventMetadata")]
    pub event_metadata: Vec<EventMetadata>,
    /// Storage key this event belongs to.
    #[serde(rename = "storageKey")]
    pub storage_key: String,
}

/// Enables event updates for the service.
///
/// Parameters of `BackgroundService.startObserving`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StartObservingParams {
    pub service: ServiceName,
}

impl crate::typed::Command for StartObservingParams {
    const METHOD: &'static str = "BackgroundService.startObserving";
    type Returns = crate::typed::NoReturns;
}

/// Disables event updates for the service.
///
/// Parameters of `BackgroundService.stopObserving`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StopObservingParams {
    pub service: ServiceName,
}

impl crate::typed::Command for StopObservingParams {
    const METHOD: &'static str = "BackgroundService.stopObserving";
    type Returns = crate::typed::NoReturns;
}

/// Set the recording state for the service.
///
/// Parameters of `BackgroundService.setRecording`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SetRecordingParams {
    #[serde(rename = "shouldRecord")]
    pub should_record: bool,
    pub service: ServiceName,
}

impl crate::typed::Command for SetRecordingParams {
    const METHOD: &'static str = "BackgroundService.setRecording";
    type Returns = crate::typed::NoReturns;
}

/// Clears all stored data for the service.
///
/// Parameters of `BackgroundService.clearEvents`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ClearEventsParams {
    pub service: ServiceName,
}

impl crate::typed::Command for ClearEventsParams {
    const METHOD: &'static str = "BackgroundService.clearEvents";
    type Returns = crate::typed::NoReturns;
}

/// Called when the recording state for the service has been updated.
///
/// Payload of the `BackgroundService.recordingStateChanged` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RecordingStateChangedEvent {
    #[serde(rename = "isRecording")]
    pub is_recording: bool,
    pub service: ServiceName,
}

impl crate::typed::Event for RecordingStateChangedEvent {
    const METHOD: &'static str = "BackgroundService.recordingStateChanged";
}

/// Called with all existing backgroundServiceEvents when enabled, and all new
/// events afterwards if enabled and recording.
///
/// Payload of the `BackgroundService.backgroundServiceEventReceived` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BackgroundServiceEventReceivedEvent {
    #[serde(rename = "backgroundServiceEvent")]
    pub background_service_event: BackgroundServiceEvent,
}

impl crate::typed::Event for BackgroundServiceEventReceivedEvent {
    const METHOD: &'static str = "BackgroundService.backgroundServiceEventReceived";
}