browser_protocol/pwa/mod.rs
1//! This domain allows interacting with the browser to control PWAs.
2use serde::{Serialize, Deserialize};
3use serde_json::Value as JsonValue;
4
5/// The following types are the replica of
6/// https://crsrc.org/c/chrome/browser/web_applications/proto/web_app_os_integration_state.proto;drc=9910d3be894c8f142c977ba1023f30a656bc13fc;l=67
7
8#[derive(Debug, Clone, Serialize, Deserialize, Default)]
9#[serde(rename_all = "camelCase")]
10pub struct FileHandlerAccept {
11 /// New name of the mimetype according to
12 /// https://www.iana.org/assignments/media-types/media-types.xhtml
13
14 pub mediaType: String,
15
16 pub fileExtensions: Vec<String>,
17}
18
19
20#[derive(Debug, Clone, Serialize, Deserialize, Default)]
21#[serde(rename_all = "camelCase")]
22pub struct FileHandler {
23
24 pub action: String,
25
26 pub accepts: Vec<FileHandlerAccept>,
27
28 pub displayName: String,
29}
30
31/// If user prefers opening the app in browser or an app window.
32
33#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
34pub enum DisplayMode {
35 #[default]
36 Standalone,
37 Browser,
38}
39
40/// Returns the following OS state for the given manifest id.
41
42#[derive(Debug, Clone, Serialize, Deserialize, Default)]
43#[serde(rename_all = "camelCase")]
44pub struct GetOsAppStateParams {
45 /// The id from the webapp's manifest file, commonly it's the url of the
46 /// site installing the webapp. See
47 /// https://web.dev/learn/pwa/web-app-manifest.
48
49 pub manifestId: String,
50}
51
52/// Returns the following OS state for the given manifest id.
53
54#[derive(Debug, Clone, Serialize, Deserialize, Default)]
55#[serde(rename_all = "camelCase")]
56pub struct GetOsAppStateReturns {
57
58 pub badgeCount: u64,
59
60 pub fileHandlers: Vec<FileHandler>,
61}
62
63impl GetOsAppStateParams { pub const METHOD: &'static str = "PWA.getOsAppState"; }
64
65impl crate::CdpCommand for GetOsAppStateParams {
66 const METHOD: &'static str = "PWA.getOsAppState";
67 type Response = GetOsAppStateReturns;
68}
69
70/// Installs the given manifest identity, optionally using the given installUrlOrBundleUrl
71///
72/// IWA-specific install description:
73/// manifestId corresponds to isolated-app:// + web_package::SignedWebBundleId
74///
75/// File installation mode:
76/// The installUrlOrBundleUrl can be either file:// or http(s):// pointing
77/// to a signed web bundle (.swbn). In this case SignedWebBundleId must correspond to
78/// The .swbn file's signing key.
79///
80/// Dev proxy installation mode:
81/// installUrlOrBundleUrl must be http(s):// that serves dev mode IWA.
82/// web_package::SignedWebBundleId must be of type dev proxy.
83///
84/// The advantage of dev proxy mode is that all changes to IWA
85/// automatically will be reflected in the running app without
86/// reinstallation.
87///
88/// To generate bundle id for proxy mode:
89/// 1. Generate 32 random bytes.
90/// 2. Add a specific suffix at the end following the documentation
91/// https://github.com/WICG/isolated-web-apps/blob/main/Scheme.md#suffix
92/// 3. Encode the entire sequence using Base32 without padding.
93///
94/// If Chrome is not in IWA dev
95/// mode, the installation will fail, regardless of the state of the allowlist.
96
97#[derive(Debug, Clone, Serialize, Deserialize, Default)]
98#[serde(rename_all = "camelCase")]
99pub struct InstallParams {
100
101 pub manifestId: String,
102 /// The location of the app or bundle overriding the one derived from the
103 /// manifestId.
104
105 #[serde(skip_serializing_if = "Option::is_none")]
106 pub installUrlOrBundleUrl: Option<String>,
107}
108
109impl InstallParams { pub const METHOD: &'static str = "PWA.install"; }
110
111impl crate::CdpCommand for InstallParams {
112 const METHOD: &'static str = "PWA.install";
113 type Response = crate::EmptyReturns;
114}
115
116/// Uninstalls the given manifest_id and closes any opened app windows.
117
118#[derive(Debug, Clone, Serialize, Deserialize, Default)]
119#[serde(rename_all = "camelCase")]
120pub struct UninstallParams {
121
122 pub manifestId: String,
123}
124
125impl UninstallParams { pub const METHOD: &'static str = "PWA.uninstall"; }
126
127impl crate::CdpCommand for UninstallParams {
128 const METHOD: &'static str = "PWA.uninstall";
129 type Response = crate::EmptyReturns;
130}
131
132/// Launches the installed web app, or an url in the same web app instead of the
133/// default start url if it is provided. Returns a page Target.TargetID which
134/// can be used to attach to via Target.attachToTarget or similar APIs.
135
136#[derive(Debug, Clone, Serialize, Deserialize, Default)]
137#[serde(rename_all = "camelCase")]
138pub struct LaunchParams {
139
140 pub manifestId: String,
141
142 #[serde(skip_serializing_if = "Option::is_none")]
143 pub url: Option<String>,
144}
145
146/// Launches the installed web app, or an url in the same web app instead of the
147/// default start url if it is provided. Returns a page Target.TargetID which
148/// can be used to attach to via Target.attachToTarget or similar APIs.
149
150#[derive(Debug, Clone, Serialize, Deserialize, Default)]
151#[serde(rename_all = "camelCase")]
152pub struct LaunchReturns {
153 /// ID of the tab target created as a result.
154
155 pub targetId: crate::target::TargetID,
156}
157
158impl LaunchParams { pub const METHOD: &'static str = "PWA.launch"; }
159
160impl crate::CdpCommand for LaunchParams {
161 const METHOD: &'static str = "PWA.launch";
162 type Response = LaunchReturns;
163}
164
165/// Opens one or more local files from an installed web app identified by its
166/// manifestId. The web app needs to have file handlers registered to process
167/// the files. The API returns one or more page Target.TargetIDs which can be
168/// used to attach to via Target.attachToTarget or similar APIs.
169/// If some files in the parameters cannot be handled by the web app, they will
170/// be ignored. If none of the files can be handled, this API returns an error.
171/// If no files are provided as the parameter, this API also returns an error.
172///
173/// According to the definition of the file handlers in the manifest file, one
174/// Target.TargetID may represent a page handling one or more files. The order
175/// of the returned Target.TargetIDs is not guaranteed.
176///
177/// TODO(crbug.com/339454034): Check the existences of the input files.
178
179#[derive(Debug, Clone, Serialize, Deserialize, Default)]
180#[serde(rename_all = "camelCase")]
181pub struct LaunchFilesInAppParams {
182
183 pub manifestId: String,
184
185 pub files: Vec<String>,
186}
187
188/// Opens one or more local files from an installed web app identified by its
189/// manifestId. The web app needs to have file handlers registered to process
190/// the files. The API returns one or more page Target.TargetIDs which can be
191/// used to attach to via Target.attachToTarget or similar APIs.
192/// If some files in the parameters cannot be handled by the web app, they will
193/// be ignored. If none of the files can be handled, this API returns an error.
194/// If no files are provided as the parameter, this API also returns an error.
195///
196/// According to the definition of the file handlers in the manifest file, one
197/// Target.TargetID may represent a page handling one or more files. The order
198/// of the returned Target.TargetIDs is not guaranteed.
199///
200/// TODO(crbug.com/339454034): Check the existences of the input files.
201
202#[derive(Debug, Clone, Serialize, Deserialize, Default)]
203#[serde(rename_all = "camelCase")]
204pub struct LaunchFilesInAppReturns {
205 /// IDs of the tab targets created as the result.
206
207 pub targetIds: Vec<crate::target::TargetID>,
208}
209
210impl LaunchFilesInAppParams { pub const METHOD: &'static str = "PWA.launchFilesInApp"; }
211
212impl crate::CdpCommand for LaunchFilesInAppParams {
213 const METHOD: &'static str = "PWA.launchFilesInApp";
214 type Response = LaunchFilesInAppReturns;
215}
216
217/// Opens the current page in its web app identified by the manifest id, needs
218/// to be called on a page target. This function returns immediately without
219/// waiting for the app to finish loading.
220
221#[derive(Debug, Clone, Serialize, Deserialize, Default)]
222#[serde(rename_all = "camelCase")]
223pub struct OpenCurrentPageInAppParams {
224
225 pub manifestId: String,
226}
227
228impl OpenCurrentPageInAppParams { pub const METHOD: &'static str = "PWA.openCurrentPageInApp"; }
229
230impl crate::CdpCommand for OpenCurrentPageInAppParams {
231 const METHOD: &'static str = "PWA.openCurrentPageInApp";
232 type Response = crate::EmptyReturns;
233}
234
235/// Changes user settings of the web app identified by its manifestId. If the
236/// app was not installed, this command returns an error. Unset parameters will
237/// be ignored; unrecognized values will cause an error.
238///
239/// Unlike the ones defined in the manifest files of the web apps, these
240/// settings are provided by the browser and controlled by the users, they
241/// impact the way the browser handling the web apps.
242///
243/// See the comment of each parameter.
244
245#[derive(Debug, Clone, Serialize, Deserialize, Default)]
246#[serde(rename_all = "camelCase")]
247pub struct ChangeAppUserSettingsParams {
248
249 pub manifestId: String,
250 /// If user allows the links clicked on by the user in the app's scope, or
251 /// extended scope if the manifest has scope extensions and the flags
252 /// 'DesktopPWAsLinkCapturingWithScopeExtensions' and
253 /// 'WebAppEnableScopeExtensions' are enabled.
254 ///
255 /// Note, the API does not support resetting the linkCapturing to the
256 /// initial value, uninstalling and installing the web app again will reset
257 /// it.
258 ///
259 /// TODO(crbug.com/339453269): Setting this value on ChromeOS is not
260 /// supported yet.
261
262 #[serde(skip_serializing_if = "Option::is_none")]
263 pub linkCapturing: Option<bool>,
264
265 #[serde(skip_serializing_if = "Option::is_none")]
266 pub displayMode: Option<DisplayMode>,
267}
268
269impl ChangeAppUserSettingsParams { pub const METHOD: &'static str = "PWA.changeAppUserSettings"; }
270
271impl crate::CdpCommand for ChangeAppUserSettingsParams {
272 const METHOD: &'static str = "PWA.changeAppUserSettings";
273 type Response = crate::EmptyReturns;
274}