Skip to main content

browser_protocol/autofill/
mod.rs

1//! Defines commands and events for Autofill.
2use serde::{Serialize, Deserialize};
3use serde_json::Value as JsonValue;
4
5
6#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct CreditCard {
9    /// 16-digit credit card number.
10
11    pub number: String,
12    /// Name of the credit card owner.
13
14    pub name: String,
15    /// 2-digit expiry month.
16
17    pub expiryMonth: String,
18    /// 4-digit expiry year.
19
20    pub expiryYear: String,
21    /// 3-digit card verification code.
22
23    pub cvc: String,
24}
25
26
27#[derive(Debug, Clone, Serialize, Deserialize, Default)]
28#[serde(rename_all = "camelCase")]
29pub struct AddressField {
30    /// address field name, for example GIVEN_NAME.
31    /// The full list of supported field names:
32    /// https://source.chromium.org/chromium/chromium/src/+/main:components/autofill/core/browser/field_types.cc;l=38
33
34    pub name: String,
35    /// address field value, for example Jon Doe.
36
37    pub value: String,
38}
39
40/// A list of address fields.
41
42#[derive(Debug, Clone, Serialize, Deserialize, Default)]
43#[serde(rename_all = "camelCase")]
44pub struct AddressFields {
45
46    pub fields: Vec<AddressField>,
47}
48
49
50#[derive(Debug, Clone, Serialize, Deserialize, Default)]
51#[serde(rename_all = "camelCase")]
52pub struct Address {
53    /// fields and values defining an address.
54
55    pub fields: Vec<AddressField>,
56}
57
58/// Defines how an address can be displayed like in chrome://settings/addresses.
59/// 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.
60/// The following address UI for instance:
61/// [[{name: "GIVE_NAME", value: "Jon"}, {name: "FAMILY_NAME", value: "Doe"}], [{name: "CITY", value: "Munich"}, {name: "ZIP", value: "81456"}]]
62/// should allow the receiver to render:
63/// Jon Doe
64/// Munich 81456
65
66#[derive(Debug, Clone, Serialize, Deserialize, Default)]
67#[serde(rename_all = "camelCase")]
68pub struct AddressUI {
69    /// A two dimension array containing the representation of values from an address profile.
70
71    pub addressFields: Vec<AddressFields>,
72}
73
74/// Specified whether a filled field was done so by using the html autocomplete attribute or autofill heuristics.
75
76#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
77pub enum FillingStrategy {
78    #[default]
79    AutocompleteAttribute,
80    AutofillInferred,
81}
82
83
84#[derive(Debug, Clone, Serialize, Deserialize, Default)]
85#[serde(rename_all = "camelCase")]
86pub struct FilledField {
87    /// The type of the field, e.g text, password etc.
88
89    pub htmlType: String,
90    /// the html id
91
92    pub id: String,
93    /// the html name
94
95    pub name: String,
96    /// the field value
97
98    pub value: String,
99    /// The actual field type, e.g FAMILY_NAME
100
101    pub autofillType: String,
102    /// The filling strategy
103
104    pub fillingStrategy: FillingStrategy,
105    /// The frame the field belongs to
106
107    pub frameId: crate::page::FrameId,
108    /// The form field's DOM node
109
110    pub fieldId: crate::dom::BackendNodeId,
111}
112
113/// Trigger autofill on a form identified by the fieldId.
114/// If the field and related form cannot be autofilled, returns an error.
115
116#[derive(Debug, Clone, Serialize, Deserialize, Default)]
117#[serde(rename_all = "camelCase")]
118pub struct TriggerParams {
119    /// Identifies a field that serves as an anchor for autofill.
120
121    pub fieldId: crate::dom::BackendNodeId,
122    /// Identifies the frame that field belongs to.
123
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub frameId: Option<crate::page::FrameId>,
126    /// Credit card information to fill out the form. Credit card data is not saved.  Mutually exclusive with 'address'.
127
128    #[serde(skip_serializing_if = "Option::is_none")]
129    pub card: Option<CreditCard>,
130    /// Address to fill out the form. Address data is not saved. Mutually exclusive with 'card'.
131
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub address: Option<Address>,
134}
135
136impl TriggerParams { pub const METHOD: &'static str = "Autofill.trigger"; }
137
138impl crate::CdpCommand for TriggerParams {
139    const METHOD: &'static str = "Autofill.trigger";
140    type Response = crate::EmptyReturns;
141}
142
143/// Set addresses so that developers can verify their forms implementation.
144
145#[derive(Debug, Clone, Serialize, Deserialize, Default)]
146#[serde(rename_all = "camelCase")]
147pub struct SetAddressesParams {
148
149    pub addresses: Vec<Address>,
150}
151
152impl SetAddressesParams { pub const METHOD: &'static str = "Autofill.setAddresses"; }
153
154impl crate::CdpCommand for SetAddressesParams {
155    const METHOD: &'static str = "Autofill.setAddresses";
156    type Response = crate::EmptyReturns;
157}
158
159#[derive(Debug, Clone, Serialize, Deserialize, Default)]
160pub struct DisableParams {}
161
162impl DisableParams { pub const METHOD: &'static str = "Autofill.disable"; }
163
164impl crate::CdpCommand for DisableParams {
165    const METHOD: &'static str = "Autofill.disable";
166    type Response = crate::EmptyReturns;
167}
168
169#[derive(Debug, Clone, Serialize, Deserialize, Default)]
170pub struct EnableParams {}
171
172impl EnableParams { pub const METHOD: &'static str = "Autofill.enable"; }
173
174impl crate::CdpCommand for EnableParams {
175    const METHOD: &'static str = "Autofill.enable";
176    type Response = crate::EmptyReturns;
177}