Skip to main content

cdp_driver/protocol/
service_worker.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! The `ServiceWorker` domain.
5//!
6//! Types, command parameters and event payloads for the `ServiceWorker`
7//! domain. The method-name constants for the same domain are in
8//! [`crate::methods`].
9//!
10//! This domain is experimental and may change without notice.
11
12use serde::{Deserialize, Serialize};
13
14pub type RegistrationId = String;
15
16/// ServiceWorker registration.
17#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
18pub struct ServiceWorkerRegistration {
19    #[serde(rename = "registrationId")]
20    pub registration_id: RegistrationId,
21    #[serde(rename = "scopeURL")]
22    pub scope_url: String,
23    #[serde(rename = "isDeleted")]
24    pub is_deleted: bool,
25}
26
27#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
28pub enum ServiceWorkerVersionRunningStatus {
29    /// `stopped`
30    #[serde(rename = "stopped")]
31    Stopped,
32    /// `starting`
33    #[serde(rename = "starting")]
34    Starting,
35    /// `running`
36    #[serde(rename = "running")]
37    Running,
38    /// `stopping`
39    #[serde(rename = "stopping")]
40    Stopping,
41    /// A value this vendored schema does not list. Chrome adds values ahead of
42    /// the published protocol, so an unrecognised one is kept as it arrived
43    /// rather than failing the payload it came in.
44    #[serde(untagged)]
45    Unrecognized(String),
46}
47
48#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
49pub enum ServiceWorkerVersionStatus {
50    /// `new`
51    #[serde(rename = "new")]
52    New,
53    /// `installing`
54    #[serde(rename = "installing")]
55    Installing,
56    /// `installed`
57    #[serde(rename = "installed")]
58    Installed,
59    /// `activating`
60    #[serde(rename = "activating")]
61    Activating,
62    /// `activated`
63    #[serde(rename = "activated")]
64    Activated,
65    /// `redundant`
66    #[serde(rename = "redundant")]
67    Redundant,
68    /// A value this vendored schema does not list. Chrome adds values ahead of
69    /// the published protocol, so an unrecognised one is kept as it arrived
70    /// rather than failing the payload it came in.
71    #[serde(untagged)]
72    Unrecognized(String),
73}
74
75/// Mostly corresponds to `RouterCondition` in ServiceWorker spec
76/// (<https://www.w3.org/TR/service-workers/#dictdef-routercondition>)
77#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
78pub struct ServiceWorkerRouterCondition {
79    /// Plain text, or JSON serialization of URLPatternInit or URLPattern
80    #[serde(
81        rename = "urlPattern",
82        default,
83        skip_serializing_if = "Option::is_none"
84    )]
85    pub url_pattern: Option<String>,
86    #[serde(
87        rename = "requestMethod",
88        default,
89        skip_serializing_if = "Option::is_none"
90    )]
91    pub request_method: Option<String>,
92    #[serde(
93        rename = "requestMode",
94        default,
95        skip_serializing_if = "Option::is_none"
96    )]
97    pub request_mode: Option<String>,
98    #[serde(
99        rename = "requestDestination",
100        default,
101        skip_serializing_if = "Option::is_none"
102    )]
103    pub request_destination: Option<String>,
104    #[serde(
105        rename = "runningStatus",
106        default,
107        skip_serializing_if = "Option::is_none"
108    )]
109    pub running_status: Option<ServiceWorkerVersionRunningStatus>,
110    #[serde(default, skip_serializing_if = "Option::is_none")]
111    pub or: Option<Vec<ServiceWorkerRouterCondition>>,
112    #[serde(default, skip_serializing_if = "Option::is_none")]
113    pub not: Option<Box<ServiceWorkerRouterCondition>>,
114}
115
116#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
117pub enum ServiceWorkerRouterSourceType {
118    /// `cache`
119    #[serde(rename = "cache")]
120    Cache,
121    /// `fetchEvent`
122    #[serde(rename = "fetchEvent")]
123    FetchEvent,
124    /// `network`
125    #[serde(rename = "network")]
126    Network,
127    /// `raceNetworkAndFetchHandler`
128    #[serde(rename = "raceNetworkAndFetchHandler")]
129    RaceNetworkAndFetchHandler,
130    /// `raceNetworkAndCache`
131    #[serde(rename = "raceNetworkAndCache")]
132    RaceNetworkAndCache,
133    /// `sourceDict`
134    #[serde(rename = "sourceDict")]
135    SourceDict,
136    /// A value this vendored schema does not list. Chrome adds values ahead of
137    /// the published protocol, so an unrecognised one is kept as it arrived
138    /// rather than failing the payload it came in.
139    #[serde(untagged)]
140    Unrecognized(String),
141}
142
143/// <https://www.w3.org/TR/service-workers/#dictdef-routersourcedict>
144#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
145pub struct ServiceWorkerRouterSourceDict {
146    #[serde(rename = "cacheName")]
147    pub cache_name: String,
148}
149
150/// Corresponds to `RouterSource` in the spec while the representation is
151/// different as follows.
152/// (<https://www.w3.org/TR/service-workers/#typedefdef-routersource>) -
153/// `RouterSourceEnum`: `type` equals `cache`, `sourceDict` is null. -
154/// `RouterSourceDict`: `type` equals `sourceDict`, `sourceDict` has valid
155/// value.
156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
157pub struct ServiceWorkerRouterSource {
158    pub r#type: ServiceWorkerRouterSourceType,
159    /// Non-empty iff `type` equals "sourceDict".
160    #[serde(
161        rename = "sourceDict",
162        default,
163        skip_serializing_if = "Option::is_none"
164    )]
165    pub source_dict: Option<ServiceWorkerRouterSourceDict>,
166}
167
168#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
169pub struct ServiceWorkerRouterRule {
170    pub condition: ServiceWorkerRouterCondition,
171    pub source: ServiceWorkerRouterSource,
172    /// Rule ID assigned by the browser. Unique within each ServiceWorkerVersion.
173    pub id: i64,
174}
175
176/// ServiceWorker version.
177#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
178pub struct ServiceWorkerVersion {
179    #[serde(rename = "versionId")]
180    pub version_id: String,
181    #[serde(rename = "registrationId")]
182    pub registration_id: RegistrationId,
183    #[serde(rename = "scriptURL")]
184    pub script_url: String,
185    #[serde(rename = "runningStatus")]
186    pub running_status: ServiceWorkerVersionRunningStatus,
187    pub status: ServiceWorkerVersionStatus,
188    /// The Last-Modified header value of the main script.
189    #[serde(
190        rename = "scriptLastModified",
191        default,
192        skip_serializing_if = "Option::is_none"
193    )]
194    pub script_last_modified: Option<f64>,
195    /// The time at which the response headers of the main script were received
196    /// from the server. For cached script it is the last time the cache entry was
197    /// validated.
198    #[serde(
199        rename = "scriptResponseTime",
200        default,
201        skip_serializing_if = "Option::is_none"
202    )]
203    pub script_response_time: Option<f64>,
204    #[serde(
205        rename = "controlledClients",
206        default,
207        skip_serializing_if = "Option::is_none"
208    )]
209    pub controlled_clients: Option<Vec<crate::protocol::target::TargetId>>,
210    #[serde(rename = "targetId", default, skip_serializing_if = "Option::is_none")]
211    pub target_id: Option<crate::protocol::target::TargetId>,
212    /// Migration to `typedRouterRules` is in progress. The browser sends either
213    /// `routerRules` or `typedRouterRules`. TODO(crbug.com/540469610): Remove
214    /// `routerRules` after the migration.
215    #[serde(
216        rename = "routerRules",
217        default,
218        skip_serializing_if = "Option::is_none"
219    )]
220    pub router_rules: Option<String>,
221    #[serde(
222        rename = "typedRouterRules",
223        default,
224        skip_serializing_if = "Option::is_none"
225    )]
226    pub typed_router_rules: Option<Vec<ServiceWorkerRouterRule>>,
227}
228
229/// ServiceWorker error message.
230#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
231pub struct ServiceWorkerErrorMessage {
232    #[serde(rename = "errorMessage")]
233    pub error_message: String,
234    #[serde(rename = "registrationId")]
235    pub registration_id: RegistrationId,
236    #[serde(rename = "versionId")]
237    pub version_id: String,
238    #[serde(rename = "sourceURL")]
239    pub source_url: String,
240    #[serde(rename = "lineNumber")]
241    pub line_number: i64,
242    #[serde(rename = "columnNumber")]
243    pub column_number: i64,
244}
245
246/// Parameters of `ServiceWorker.deliverPushMessage`.
247#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
248pub struct DeliverPushMessageParams {
249    pub origin: String,
250    #[serde(rename = "registrationId")]
251    pub registration_id: RegistrationId,
252    pub data: String,
253}
254
255impl crate::typed::Command for DeliverPushMessageParams {
256    const METHOD: &'static str = "ServiceWorker.deliverPushMessage";
257    type Returns = crate::typed::NoReturns;
258}
259
260/// Parameters of `ServiceWorker.disable`.
261#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
262pub struct DisableParams {}
263
264impl crate::typed::Command for DisableParams {
265    const METHOD: &'static str = "ServiceWorker.disable";
266    type Returns = crate::typed::NoReturns;
267}
268
269/// Parameters of `ServiceWorker.dispatchSyncEvent`.
270#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
271pub struct DispatchSyncEventParams {
272    pub origin: String,
273    #[serde(rename = "registrationId")]
274    pub registration_id: RegistrationId,
275    pub tag: String,
276    #[serde(rename = "lastChance")]
277    pub last_chance: bool,
278}
279
280impl crate::typed::Command for DispatchSyncEventParams {
281    const METHOD: &'static str = "ServiceWorker.dispatchSyncEvent";
282    type Returns = crate::typed::NoReturns;
283}
284
285/// Parameters of `ServiceWorker.dispatchPeriodicSyncEvent`.
286#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
287pub struct DispatchPeriodicSyncEventParams {
288    pub origin: String,
289    #[serde(rename = "registrationId")]
290    pub registration_id: RegistrationId,
291    pub tag: String,
292}
293
294impl crate::typed::Command for DispatchPeriodicSyncEventParams {
295    const METHOD: &'static str = "ServiceWorker.dispatchPeriodicSyncEvent";
296    type Returns = crate::typed::NoReturns;
297}
298
299/// Parameters of `ServiceWorker.enable`.
300#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
301pub struct EnableParams {}
302
303impl crate::typed::Command for EnableParams {
304    const METHOD: &'static str = "ServiceWorker.enable";
305    type Returns = crate::typed::NoReturns;
306}
307
308/// Parameters of `ServiceWorker.setForceUpdateOnPageLoad`.
309#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
310pub struct SetForceUpdateOnPageLoadParams {
311    #[serde(rename = "forceUpdateOnPageLoad")]
312    pub force_update_on_page_load: bool,
313}
314
315impl crate::typed::Command for SetForceUpdateOnPageLoadParams {
316    const METHOD: &'static str = "ServiceWorker.setForceUpdateOnPageLoad";
317    type Returns = crate::typed::NoReturns;
318}
319
320/// Parameters of `ServiceWorker.skipWaiting`.
321#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
322pub struct SkipWaitingParams {
323    #[serde(rename = "scopeURL")]
324    pub scope_url: String,
325}
326
327impl crate::typed::Command for SkipWaitingParams {
328    const METHOD: &'static str = "ServiceWorker.skipWaiting";
329    type Returns = crate::typed::NoReturns;
330}
331
332/// Parameters of `ServiceWorker.startWorker`.
333#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
334pub struct StartWorkerParams {
335    #[serde(rename = "scopeURL")]
336    pub scope_url: String,
337}
338
339impl crate::typed::Command for StartWorkerParams {
340    const METHOD: &'static str = "ServiceWorker.startWorker";
341    type Returns = crate::typed::NoReturns;
342}
343
344/// Parameters of `ServiceWorker.stopAllWorkers`.
345#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
346pub struct StopAllWorkersParams {}
347
348impl crate::typed::Command for StopAllWorkersParams {
349    const METHOD: &'static str = "ServiceWorker.stopAllWorkers";
350    type Returns = crate::typed::NoReturns;
351}
352
353/// Parameters of `ServiceWorker.stopWorker`.
354#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
355pub struct StopWorkerParams {
356    #[serde(rename = "versionId")]
357    pub version_id: String,
358}
359
360impl crate::typed::Command for StopWorkerParams {
361    const METHOD: &'static str = "ServiceWorker.stopWorker";
362    type Returns = crate::typed::NoReturns;
363}
364
365/// Parameters of `ServiceWorker.unregister`.
366#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
367pub struct UnregisterParams {
368    #[serde(rename = "scopeURL")]
369    pub scope_url: String,
370}
371
372impl crate::typed::Command for UnregisterParams {
373    const METHOD: &'static str = "ServiceWorker.unregister";
374    type Returns = crate::typed::NoReturns;
375}
376
377/// Parameters of `ServiceWorker.updateRegistration`.
378#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
379pub struct UpdateRegistrationParams {
380    #[serde(rename = "scopeURL")]
381    pub scope_url: String,
382}
383
384impl crate::typed::Command for UpdateRegistrationParams {
385    const METHOD: &'static str = "ServiceWorker.updateRegistration";
386    type Returns = crate::typed::NoReturns;
387}
388
389/// Payload of the `ServiceWorker.workerErrorReported` event.
390#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
391pub struct WorkerErrorReportedEvent {
392    #[serde(rename = "errorMessage")]
393    pub error_message: ServiceWorkerErrorMessage,
394}
395
396impl crate::typed::Event for WorkerErrorReportedEvent {
397    const METHOD: &'static str = "ServiceWorker.workerErrorReported";
398}
399
400/// Payload of the `ServiceWorker.workerRegistrationUpdated` event.
401#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
402pub struct WorkerRegistrationUpdatedEvent {
403    pub registrations: Vec<ServiceWorkerRegistration>,
404}
405
406impl crate::typed::Event for WorkerRegistrationUpdatedEvent {
407    const METHOD: &'static str = "ServiceWorker.workerRegistrationUpdated";
408}
409
410/// Payload of the `ServiceWorker.workerVersionUpdated` event.
411#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
412pub struct WorkerVersionUpdatedEvent {
413    pub versions: Vec<ServiceWorkerVersion>,
414}
415
416impl crate::typed::Event for WorkerVersionUpdatedEvent {
417    const METHOD: &'static str = "ServiceWorker.workerVersionUpdated";
418}