1use std::fmt;
2
3use crate::cdp::browser_protocol::fetch;
4use crate::cdp::browser_protocol::network::{self, CookieParam, DeleteCookiesParams};
5use crate::cdp::browser_protocol::target::CreateTargetParams;
6use crate::cdp::js_protocol::runtime::{
7 CallFunctionOnParams, EvaluateParams, ExceptionDetails, StackTrace,
8};
9use crate::revision::Revision;
10
11#[allow(clippy::multiple_bound_locations)]
12#[allow(clippy::derive_partial_eq_without_eq)]
13#[allow(unreachable_patterns)]
14pub mod cdp;
15pub mod revision;
16
17pub const CURRENT_REVISION: Revision = Revision(1336433);
19
20impl Default for CreateTargetParams {
22 fn default() -> Self {
23 "about:blank".into()
24 }
25}
26
27impl From<fetch::RequestId> for network::RequestId {
30 fn from(req: fetch::RequestId) -> Self {
31 let s: String = req.into();
32 s.into()
33 }
34}
35
36impl From<network::RequestId> for fetch::RequestId {
37 fn from(req: network::RequestId) -> Self {
38 let s: String = req.into();
39 s.into()
40 }
41}
42
43impl From<network::InterceptionId> for fetch::RequestId {
44 fn from(req: network::InterceptionId) -> Self {
45 let s: String = req.into();
46 s.into()
47 }
48}
49
50impl From<network::InterceptionId> for network::RequestId {
51 fn from(req: network::InterceptionId) -> Self {
52 let s: String = req.into();
53 s.into()
54 }
55}
56
57impl From<fetch::RequestId> for network::InterceptionId {
58 fn from(req: fetch::RequestId) -> Self {
59 let s: String = req.into();
60 s.into()
61 }
62}
63
64impl From<network::RequestId> for network::InterceptionId {
65 fn from(req: network::RequestId) -> Self {
66 let s: String = req.into();
67 s.into()
68 }
69}
70
71impl DeleteCookiesParams {
72 pub fn from_cookie(param: &CookieParam) -> Self {
74 DeleteCookiesParams {
75 name: param.name.clone(),
76 url: param.url.clone(),
77 domain: param.domain.clone(),
78 path: param.path.clone(),
79 partition_key: param.partition_key.clone(),
80 }
81 }
82}
83
84impl From<EvaluateParams> for CallFunctionOnParams {
85 fn from(params: EvaluateParams) -> CallFunctionOnParams {
86 CallFunctionOnParams {
87 function_declaration: params.expression,
88 object_id: None,
89 arguments: None,
90 silent: params.silent,
91 return_by_value: params.return_by_value,
92 generate_preview: params.generate_preview,
93 user_gesture: params.user_gesture,
94 await_promise: params.await_promise,
95 execution_context_id: params.context_id,
96 object_group: params.object_group,
97 throw_on_side_effect: None,
98 unique_context_id: None,
99 serialization_options: None,
100 }
101 }
102}
103
104impl fmt::Display for ExceptionDetails {
105 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
106 writeln!(
107 f,
108 "{}:{}: {}",
109 self.line_number, self.column_number, self.text
110 )?;
111
112 if let Some(stack) = self.stack_trace.as_ref() {
113 stack.fmt(f)?
114 }
115 Ok(())
116 }
117}
118
119impl std::error::Error for ExceptionDetails {}
120
121impl fmt::Display for StackTrace {
122 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123 if let Some(desc) = self.description.as_ref() {
124 writeln!(f, "{desc}")?;
125 }
126 for frame in &self.call_frames {
127 writeln!(
128 f,
129 "{}@{}:{}:{}",
130 frame.function_name, frame.url, frame.line_number, frame.column_number
131 )?;
132 }
133 Ok(())
134 }
135}