Skip to main content

browser_protocol/log/
mod.rs

1//! Provides access to log entries.
2
3
4use serde::{Serialize, Deserialize};
5use serde_json::Value as JsonValue;
6use std::borrow::Cow;
7
8/// Log entry.
9
10#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11#[serde(rename_all = "camelCase")]
12pub struct LogEntry<'a> {
13    /// Log entry source.
14    source: Cow<'a, str>,
15    /// Log entry severity.
16    level: Cow<'a, str>,
17    /// Logged text.
18    text: Cow<'a, str>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    category: Option<Cow<'a, str>>,
21    /// Timestamp when this entry was added.
22    timestamp: crate::runtime::Timestamp,
23    /// URL of the resource if known.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    url: Option<Cow<'a, str>>,
26    /// Line number in the resource.
27    #[serde(skip_serializing_if = "Option::is_none", rename = "lineNumber")]
28    line_number: Option<i64>,
29    /// JavaScript stack trace.
30    #[serde(skip_serializing_if = "Option::is_none", rename = "stackTrace")]
31    stack_trace: Option<crate::runtime::StackTrace>,
32    /// Identifier of the network request associated with this entry.
33    #[serde(skip_serializing_if = "Option::is_none", rename = "networkRequestId")]
34    network_request_id: Option<crate::network::RequestId<'a>>,
35    /// Identifier of the worker associated with this entry.
36    #[serde(skip_serializing_if = "Option::is_none", rename = "workerId")]
37    worker_id: Option<Cow<'a, str>>,
38    /// Call arguments.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    args: Option<Vec<crate::runtime::RemoteObject>>,
41}
42
43impl<'a> LogEntry<'a> {
44    /// Creates a builder for this type with the required parameters:
45    /// * `source`: Log entry source.
46    /// * `level`: Log entry severity.
47    /// * `text`: Logged text.
48    /// * `timestamp`: Timestamp when this entry was added.
49    pub fn builder(source: impl Into<Cow<'a, str>>, level: impl Into<Cow<'a, str>>, text: impl Into<Cow<'a, str>>, timestamp: crate::runtime::Timestamp) -> LogEntryBuilder<'a> {
50        LogEntryBuilder {
51            source: source.into(),
52            level: level.into(),
53            text: text.into(),
54            category: None,
55            timestamp: timestamp,
56            url: None,
57            line_number: None,
58            stack_trace: None,
59            network_request_id: None,
60            worker_id: None,
61            args: None,
62        }
63    }
64    /// Log entry source.
65    pub fn source(&self) -> &str { self.source.as_ref() }
66    /// Log entry severity.
67    pub fn level(&self) -> &str { self.level.as_ref() }
68    /// Logged text.
69    pub fn text(&self) -> &str { self.text.as_ref() }
70    pub fn category(&self) -> Option<&str> { self.category.as_deref() }
71    /// Timestamp when this entry was added.
72    pub fn timestamp(&self) -> &crate::runtime::Timestamp { &self.timestamp }
73    /// URL of the resource if known.
74    pub fn url(&self) -> Option<&str> { self.url.as_deref() }
75    /// Line number in the resource.
76    pub fn line_number(&self) -> Option<i64> { self.line_number }
77    /// JavaScript stack trace.
78    pub fn stack_trace(&self) -> Option<&crate::runtime::StackTrace> { self.stack_trace.as_ref() }
79    /// Identifier of the network request associated with this entry.
80    pub fn network_request_id(&self) -> Option<&crate::network::RequestId<'a>> { self.network_request_id.as_ref() }
81    /// Identifier of the worker associated with this entry.
82    pub fn worker_id(&self) -> Option<&str> { self.worker_id.as_deref() }
83    /// Call arguments.
84    pub fn args(&self) -> Option<&[crate::runtime::RemoteObject]> { self.args.as_deref() }
85}
86
87
88pub struct LogEntryBuilder<'a> {
89    source: Cow<'a, str>,
90    level: Cow<'a, str>,
91    text: Cow<'a, str>,
92    category: Option<Cow<'a, str>>,
93    timestamp: crate::runtime::Timestamp,
94    url: Option<Cow<'a, str>>,
95    line_number: Option<i64>,
96    stack_trace: Option<crate::runtime::StackTrace>,
97    network_request_id: Option<crate::network::RequestId<'a>>,
98    worker_id: Option<Cow<'a, str>>,
99    args: Option<Vec<crate::runtime::RemoteObject>>,
100}
101
102impl<'a> LogEntryBuilder<'a> {
103    pub fn category(mut self, category: impl Into<Cow<'a, str>>) -> Self { self.category = Some(category.into()); self }
104    /// URL of the resource if known.
105    pub fn url(mut self, url: impl Into<Cow<'a, str>>) -> Self { self.url = Some(url.into()); self }
106    /// Line number in the resource.
107    pub fn line_number(mut self, line_number: i64) -> Self { self.line_number = Some(line_number); self }
108    /// JavaScript stack trace.
109    pub fn stack_trace(mut self, stack_trace: crate::runtime::StackTrace) -> Self { self.stack_trace = Some(stack_trace); self }
110    /// Identifier of the network request associated with this entry.
111    pub fn network_request_id(mut self, network_request_id: crate::network::RequestId<'a>) -> Self { self.network_request_id = Some(network_request_id); self }
112    /// Identifier of the worker associated with this entry.
113    pub fn worker_id(mut self, worker_id: impl Into<Cow<'a, str>>) -> Self { self.worker_id = Some(worker_id.into()); self }
114    /// Call arguments.
115    pub fn args(mut self, args: Vec<crate::runtime::RemoteObject>) -> Self { self.args = Some(args); self }
116    pub fn build(self) -> LogEntry<'a> {
117        LogEntry {
118            source: self.source,
119            level: self.level,
120            text: self.text,
121            category: self.category,
122            timestamp: self.timestamp,
123            url: self.url,
124            line_number: self.line_number,
125            stack_trace: self.stack_trace,
126            network_request_id: self.network_request_id,
127            worker_id: self.worker_id,
128            args: self.args,
129        }
130    }
131}
132
133/// Violation configuration setting.
134
135#[derive(Debug, Clone, Serialize, Deserialize, Default)]
136#[serde(rename_all = "camelCase")]
137pub struct ViolationSetting<'a> {
138    /// Violation type.
139    name: Cow<'a, str>,
140    /// Time threshold to trigger upon.
141    threshold: f64,
142}
143
144impl<'a> ViolationSetting<'a> {
145    /// Creates a builder for this type with the required parameters:
146    /// * `name`: Violation type.
147    /// * `threshold`: Time threshold to trigger upon.
148    pub fn builder(name: impl Into<Cow<'a, str>>, threshold: f64) -> ViolationSettingBuilder<'a> {
149        ViolationSettingBuilder {
150            name: name.into(),
151            threshold: threshold,
152        }
153    }
154    /// Violation type.
155    pub fn name(&self) -> &str { self.name.as_ref() }
156    /// Time threshold to trigger upon.
157    pub fn threshold(&self) -> f64 { self.threshold }
158}
159
160
161pub struct ViolationSettingBuilder<'a> {
162    name: Cow<'a, str>,
163    threshold: f64,
164}
165
166impl<'a> ViolationSettingBuilder<'a> {
167    pub fn build(self) -> ViolationSetting<'a> {
168        ViolationSetting {
169            name: self.name,
170            threshold: self.threshold,
171        }
172    }
173}
174
175#[derive(Debug, Clone, Serialize, Deserialize, Default)]
176pub struct ClearParams {}
177
178impl ClearParams { pub const METHOD: &'static str = "Log.clear"; }
179
180impl<'a> crate::CdpCommand<'a> for ClearParams {
181    const METHOD: &'static str = "Log.clear";
182    type Response = crate::EmptyReturns;
183}
184
185#[derive(Debug, Clone, Serialize, Deserialize, Default)]
186pub struct DisableParams {}
187
188impl DisableParams { pub const METHOD: &'static str = "Log.disable"; }
189
190impl<'a> crate::CdpCommand<'a> for DisableParams {
191    const METHOD: &'static str = "Log.disable";
192    type Response = crate::EmptyReturns;
193}
194
195#[derive(Debug, Clone, Serialize, Deserialize, Default)]
196pub struct EnableParams {}
197
198impl EnableParams { pub const METHOD: &'static str = "Log.enable"; }
199
200impl<'a> crate::CdpCommand<'a> for EnableParams {
201    const METHOD: &'static str = "Log.enable";
202    type Response = crate::EmptyReturns;
203}
204
205/// start violation reporting.
206
207#[derive(Debug, Clone, Serialize, Deserialize, Default)]
208#[serde(rename_all = "camelCase")]
209pub struct StartViolationsReportParams<'a> {
210    /// Configuration for violations.
211    config: Vec<ViolationSetting<'a>>,
212}
213
214impl<'a> StartViolationsReportParams<'a> {
215    /// Creates a builder for this type with the required parameters:
216    /// * `config`: Configuration for violations.
217    pub fn builder(config: Vec<ViolationSetting<'a>>) -> StartViolationsReportParamsBuilder<'a> {
218        StartViolationsReportParamsBuilder {
219            config: config,
220        }
221    }
222    /// Configuration for violations.
223    pub fn config(&self) -> &[ViolationSetting<'a>] { &self.config }
224}
225
226
227pub struct StartViolationsReportParamsBuilder<'a> {
228    config: Vec<ViolationSetting<'a>>,
229}
230
231impl<'a> StartViolationsReportParamsBuilder<'a> {
232    pub fn build(self) -> StartViolationsReportParams<'a> {
233        StartViolationsReportParams {
234            config: self.config,
235        }
236    }
237}
238
239impl<'a> StartViolationsReportParams<'a> { pub const METHOD: &'static str = "Log.startViolationsReport"; }
240
241impl<'a> crate::CdpCommand<'a> for StartViolationsReportParams<'a> {
242    const METHOD: &'static str = "Log.startViolationsReport";
243    type Response = crate::EmptyReturns;
244}
245
246#[derive(Debug, Clone, Serialize, Deserialize, Default)]
247pub struct StopViolationsReportParams {}
248
249impl StopViolationsReportParams { pub const METHOD: &'static str = "Log.stopViolationsReport"; }
250
251impl<'a> crate::CdpCommand<'a> for StopViolationsReportParams {
252    const METHOD: &'static str = "Log.stopViolationsReport";
253    type Response = crate::EmptyReturns;
254}