-
Notifications
You must be signed in to change notification settings - Fork 82
/
lib.rs
149 lines (131 loc) · 4.36 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use std::fmt;
use crate::cdp::browser_protocol::fetch;
use crate::cdp::browser_protocol::network::{self, CookieParam, DeleteCookiesParams};
use crate::cdp::browser_protocol::target::CreateTargetParams;
use crate::cdp::js_protocol::runtime::{
CallFunctionOnParams, EvaluateParams, ExceptionDetails, StackTrace,
};
use crate::revision::Revision;
#[allow(clippy::multiple_bound_locations)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[allow(unreachable_patterns)]
pub mod cdp;
pub mod revision;
// The CDP is not a stable API, it changes from time to time and sometimes
// in backward incompatible ways.
//
// When the CDP changes, the chromium team pushes a commit to the repository
// https://github.com/ChromeDevTools/devtools-protocol. There you can find
// valid CDP revisions. That number corresponds to a chromium revision.
// It is a monotonic version number referring to the chromium master commit position.
//
// To map a revision to a chromium version you can use the site
// https://chromiumdash.appspot.com/commits. We should not necessarily
// always use the latest revision, as this will mean only the newest chromium
// browser can be used. Apart from breaking changes, using an older CDP
// is generally a good idea.
/// Currently built CDP revision
pub const CURRENT_REVISION: Revision = Revision(1354347);
/// convenience fixups
impl Default for CreateTargetParams {
fn default() -> Self {
"about:blank".into()
}
}
/// RequestId conversion
impl From<fetch::RequestId> for network::RequestId {
fn from(req: fetch::RequestId) -> Self {
let s: String = req.into();
s.into()
}
}
impl From<network::RequestId> for fetch::RequestId {
fn from(req: network::RequestId) -> Self {
let s: String = req.into();
s.into()
}
}
impl From<network::InterceptionId> for fetch::RequestId {
fn from(req: network::InterceptionId) -> Self {
let s: String = req.into();
s.into()
}
}
impl From<network::InterceptionId> for network::RequestId {
fn from(req: network::InterceptionId) -> Self {
let s: String = req.into();
s.into()
}
}
impl From<fetch::RequestId> for network::InterceptionId {
fn from(req: fetch::RequestId) -> Self {
let s: String = req.into();
s.into()
}
}
impl From<network::RequestId> for network::InterceptionId {
fn from(req: network::RequestId) -> Self {
let s: String = req.into();
s.into()
}
}
impl DeleteCookiesParams {
/// Create a new instance from a `CookieParam`
pub fn from_cookie(param: &CookieParam) -> Self {
DeleteCookiesParams {
name: param.name.clone(),
url: param.url.clone(),
domain: param.domain.clone(),
path: param.path.clone(),
partition_key: param.partition_key.clone(),
}
}
}
impl From<EvaluateParams> for CallFunctionOnParams {
fn from(params: EvaluateParams) -> CallFunctionOnParams {
CallFunctionOnParams {
function_declaration: params.expression,
object_id: None,
arguments: None,
silent: params.silent,
return_by_value: params.return_by_value,
generate_preview: params.generate_preview,
user_gesture: params.user_gesture,
await_promise: params.await_promise,
execution_context_id: params.context_id,
object_group: params.object_group,
throw_on_side_effect: None,
unique_context_id: None,
serialization_options: None,
}
}
}
impl fmt::Display for ExceptionDetails {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(
f,
"{}:{}: {}",
self.line_number, self.column_number, self.text
)?;
if let Some(stack) = self.stack_trace.as_ref() {
stack.fmt(f)?
}
Ok(())
}
}
impl std::error::Error for ExceptionDetails {}
impl fmt::Display for StackTrace {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(desc) = self.description.as_ref() {
writeln!(f, "{desc}")?;
}
for frame in &self.call_frames {
writeln!(
f,
"{}@{}:{}:{}",
frame.function_name, frame.url, frame.line_number, frame.column_number
)?;
}
Ok(())
}
}