Skip to main content

browser_protocol/extensions/
mod.rs

1//! Defines commands and events for browser extensions.
2use serde::{Serialize, Deserialize};
3use serde_json::Value as JsonValue;
4
5/// Storage areas.
6
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
8pub enum StorageArea {
9    #[default]
10    Session,
11    Local,
12    Sync,
13    Managed,
14}
15
16/// Detailed information about an extension.
17
18#[derive(Debug, Clone, Serialize, Deserialize, Default)]
19#[serde(rename_all = "camelCase")]
20pub struct ExtensionInfo {
21    /// Extension id.
22
23    pub id: String,
24    /// Extension name.
25
26    pub name: String,
27    /// Extension version.
28
29    pub version: String,
30    /// The path from which the extension was loaded.
31
32    pub path: String,
33    /// Extension enabled status.
34
35    pub enabled: bool,
36}
37
38/// Runs an extension default action.
39/// Available if the client is connected using the --remote-debugging-pipe
40/// flag and the --enable-unsafe-extension-debugging flag is set.
41
42#[derive(Debug, Clone, Serialize, Deserialize, Default)]
43#[serde(rename_all = "camelCase")]
44pub struct TriggerActionParams {
45    /// Extension id.
46
47    pub id: String,
48    /// A tab target ID to trigger the default extension action on.
49
50    pub targetId: String,
51}
52
53impl TriggerActionParams { pub const METHOD: &'static str = "Extensions.triggerAction"; }
54
55impl crate::CdpCommand for TriggerActionParams {
56    const METHOD: &'static str = "Extensions.triggerAction";
57    type Response = crate::EmptyReturns;
58}
59
60/// Installs an unpacked extension from the filesystem similar to
61/// --load-extension CLI flags. Returns extension ID once the extension
62/// has been installed. Available if the client is connected using the
63/// --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging
64/// flag is set.
65
66#[derive(Debug, Clone, Serialize, Deserialize, Default)]
67#[serde(rename_all = "camelCase")]
68pub struct LoadUnpackedParams {
69    /// Absolute file path.
70
71    pub path: String,
72    /// Enable the extension in incognito
73
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub enableInIncognito: Option<bool>,
76}
77
78/// Installs an unpacked extension from the filesystem similar to
79/// --load-extension CLI flags. Returns extension ID once the extension
80/// has been installed. Available if the client is connected using the
81/// --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging
82/// flag is set.
83
84#[derive(Debug, Clone, Serialize, Deserialize, Default)]
85#[serde(rename_all = "camelCase")]
86pub struct LoadUnpackedReturns {
87    /// Extension id.
88
89    pub id: String,
90}
91
92impl LoadUnpackedParams { pub const METHOD: &'static str = "Extensions.loadUnpacked"; }
93
94impl crate::CdpCommand for LoadUnpackedParams {
95    const METHOD: &'static str = "Extensions.loadUnpacked";
96    type Response = LoadUnpackedReturns;
97}
98
99/// Gets a list of all unpacked extensions.
100/// Available if the client is connected using the --remote-debugging-pipe flag
101/// and the --enable-unsafe-extension-debugging flag is set.
102
103#[derive(Debug, Clone, Serialize, Deserialize, Default)]
104#[serde(rename_all = "camelCase")]
105pub struct GetExtensionsReturns {
106
107    pub extensions: Vec<ExtensionInfo>,
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize, Default)]
111pub struct GetExtensionsParams {}
112
113impl GetExtensionsParams { pub const METHOD: &'static str = "Extensions.getExtensions"; }
114
115impl crate::CdpCommand for GetExtensionsParams {
116    const METHOD: &'static str = "Extensions.getExtensions";
117    type Response = GetExtensionsReturns;
118}
119
120/// Uninstalls an unpacked extension (others not supported) from the profile.
121/// Available if the client is connected using the --remote-debugging-pipe flag
122/// and the --enable-unsafe-extension-debugging.
123
124#[derive(Debug, Clone, Serialize, Deserialize, Default)]
125#[serde(rename_all = "camelCase")]
126pub struct UninstallParams {
127    /// Extension id.
128
129    pub id: String,
130}
131
132impl UninstallParams { pub const METHOD: &'static str = "Extensions.uninstall"; }
133
134impl crate::CdpCommand for UninstallParams {
135    const METHOD: &'static str = "Extensions.uninstall";
136    type Response = crate::EmptyReturns;
137}
138
139/// Gets data from extension storage in the given 'storageArea'. If 'keys' is
140/// specified, these are used to filter the result.
141
142#[derive(Debug, Clone, Serialize, Deserialize, Default)]
143#[serde(rename_all = "camelCase")]
144pub struct GetStorageItemsParams {
145    /// ID of extension.
146
147    pub id: String,
148    /// StorageArea to retrieve data from.
149
150    pub storageArea: StorageArea,
151    /// Keys to retrieve.
152
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub keys: Option<Vec<String>>,
155}
156
157/// Gets data from extension storage in the given 'storageArea'. If 'keys' is
158/// specified, these are used to filter the result.
159
160#[derive(Debug, Clone, Serialize, Deserialize, Default)]
161#[serde(rename_all = "camelCase")]
162pub struct GetStorageItemsReturns {
163
164    pub data: serde_json::Map<String, JsonValue>,
165}
166
167impl GetStorageItemsParams { pub const METHOD: &'static str = "Extensions.getStorageItems"; }
168
169impl crate::CdpCommand for GetStorageItemsParams {
170    const METHOD: &'static str = "Extensions.getStorageItems";
171    type Response = GetStorageItemsReturns;
172}
173
174/// Removes 'keys' from extension storage in the given 'storageArea'.
175
176#[derive(Debug, Clone, Serialize, Deserialize, Default)]
177#[serde(rename_all = "camelCase")]
178pub struct RemoveStorageItemsParams {
179    /// ID of extension.
180
181    pub id: String,
182    /// StorageArea to remove data from.
183
184    pub storageArea: StorageArea,
185    /// Keys to remove.
186
187    pub keys: Vec<String>,
188}
189
190impl RemoveStorageItemsParams { pub const METHOD: &'static str = "Extensions.removeStorageItems"; }
191
192impl crate::CdpCommand for RemoveStorageItemsParams {
193    const METHOD: &'static str = "Extensions.removeStorageItems";
194    type Response = crate::EmptyReturns;
195}
196
197/// Clears extension storage in the given 'storageArea'.
198
199#[derive(Debug, Clone, Serialize, Deserialize, Default)]
200#[serde(rename_all = "camelCase")]
201pub struct ClearStorageItemsParams {
202    /// ID of extension.
203
204    pub id: String,
205    /// StorageArea to remove data from.
206
207    pub storageArea: StorageArea,
208}
209
210impl ClearStorageItemsParams { pub const METHOD: &'static str = "Extensions.clearStorageItems"; }
211
212impl crate::CdpCommand for ClearStorageItemsParams {
213    const METHOD: &'static str = "Extensions.clearStorageItems";
214    type Response = crate::EmptyReturns;
215}
216
217/// Sets 'values' in extension storage in the given 'storageArea'. The provided 'values'
218/// will be merged with existing values in the storage area.
219
220#[derive(Debug, Clone, Serialize, Deserialize, Default)]
221#[serde(rename_all = "camelCase")]
222pub struct SetStorageItemsParams {
223    /// ID of extension.
224
225    pub id: String,
226    /// StorageArea to set data in.
227
228    pub storageArea: StorageArea,
229    /// Values to set.
230
231    pub values: serde_json::Map<String, JsonValue>,
232}
233
234impl SetStorageItemsParams { pub const METHOD: &'static str = "Extensions.setStorageItems"; }
235
236impl crate::CdpCommand for SetStorageItemsParams {
237    const METHOD: &'static str = "Extensions.setStorageItems";
238    type Response = crate::EmptyReturns;
239}