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