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

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CreditCard {
    /// 16-digit credit card number.
    pub number: String,
    /// Name of the credit card owner.
    pub name: String,
    /// 2-digit expiry month.
    #[serde(rename = "expiryMonth")]
    pub expiry_month: String,
    /// 4-digit expiry year.
    #[serde(rename = "expiryYear")]
    pub expiry_year: String,
    /// 3-digit card verification code.
    pub cvc: String,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddressField {
    /// address field name, for example GIVEN_NAME. The full list of supported
    /// field names:
    /// <https://source.chromium.org/chromium/chromium/src/+/main:components/autofill/core/browser/field_types.cc;l=38>
    pub name: String,
    /// address field value, for example Jon Doe.
    pub value: String,
}

/// A list of address fields.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddressFields {
    pub fields: Vec<AddressField>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Address {
    /// fields and values defining an address.
    pub fields: Vec<AddressField>,
}

/// Defines how an address can be displayed like in
/// chrome://settings/addresses. Address UI is a two dimensional array, each
/// inner array is an "address information line", and when rendered in a UI
/// surface should be displayed as such. The following address UI for
/// instance: \[\[{name: "GIVE_NAME", value: "Jon"}, {name: "FAMILY_NAME",
/// value: "Doe"}\], \[{name: "CITY", value: "Munich"}, {name: "ZIP", value:
/// "81456"}\]\] should allow the receiver to render: Jon Doe Munich 81456
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddressUi {
    /// A two dimension array containing the representation of values from an
    /// address profile.
    #[serde(rename = "addressFields")]
    pub address_fields: Vec<AddressFields>,
}

/// Specified whether a filled field was done so by using the html
/// autocomplete attribute or autofill heuristics.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum FillingStrategy {
    /// `autocompleteAttribute`
    #[serde(rename = "autocompleteAttribute")]
    AutocompleteAttribute,
    /// `autofillInferred`
    #[serde(rename = "autofillInferred")]
    AutofillInferred,
    /// 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),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FilledField {
    /// The type of the field, e.g text, password etc.
    #[serde(rename = "htmlType")]
    pub html_type: String,
    /// the html id
    pub id: String,
    /// the html name
    pub name: String,
    /// the field value
    pub value: String,
    /// The actual field type, e.g FAMILY_NAME
    #[serde(rename = "autofillType")]
    pub autofill_type: String,
    /// The filling strategy
    #[serde(rename = "fillingStrategy")]
    pub filling_strategy: FillingStrategy,
    /// The frame the field belongs to
    #[serde(rename = "frameId")]
    pub frame_id: crate::protocol::page::FrameId,
    /// The form field's DOM node
    #[serde(rename = "fieldId")]
    pub field_id: crate::protocol::dom::BackendNodeId,
}

/// Trigger autofill on a form identified by the fieldId. If the field and
/// related form cannot be autofilled, returns an error. Returns once the
/// values have been applied to the form fields.
///
/// Parameters of `Autofill.trigger`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TriggerParams {
    /// Identifies a field that serves as an anchor for autofill.
    #[serde(rename = "fieldId")]
    pub field_id: crate::protocol::dom::BackendNodeId,
    /// Identifies the frame that field belongs to.
    #[serde(rename = "frameId", default, skip_serializing_if = "Option::is_none")]
    pub frame_id: Option<crate::protocol::page::FrameId>,
    /// Credit card information to fill out the form. Credit card data is not
    /// saved. Mutually exclusive with `address`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub card: Option<CreditCard>,
    /// Address to fill out the form. Address data is not saved. Mutually
    /// exclusive with `card`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub address: Option<Address>,
}

impl crate::typed::Command for TriggerParams {
    const METHOD: &'static str = "Autofill.trigger";
    type Returns = crate::typed::NoReturns;
}

/// Set addresses so that developers can verify their forms implementation.
///
/// Parameters of `Autofill.setAddresses`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetAddressesParams {
    pub addresses: Vec<Address>,
}

impl crate::typed::Command for SetAddressesParams {
    const METHOD: &'static str = "Autofill.setAddresses";
    type Returns = crate::typed::NoReturns;
}

/// Disables autofill domain notifications.
///
/// Parameters of `Autofill.disable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DisableParams {}

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

/// Enables autofill domain notifications.
///
/// Parameters of `Autofill.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {}

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

/// Emitted when an address form is filled.
///
/// Payload of the `Autofill.addressFormFilled` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddressFormFilledEvent {
    /// Information about the fields that were filled
    #[serde(rename = "filledFields")]
    pub filled_fields: Vec<FilledField>,
    /// An UI representation of the address used to fill the form. Consists of a
    /// 2D array where each child represents an address/profile line.
    #[serde(rename = "addressUi")]
    pub address_ui: AddressUi,
}

impl crate::typed::Event for AddressFormFilledEvent {
    const METHOD: &'static str = "Autofill.addressFormFilled";
}