1mod device;
2#[cfg(feature = "emulation-rand")]
3mod rand;
4
5use device::{chrome::*, firefox::*, okhttp::*, opera::*, safari::*};
6#[cfg(feature = "emulation-serde")]
7use serde::{Deserialize, Serialize};
8#[cfg(feature = "emulation-rand")]
9use strum_macros::VariantArray;
10use typed_builder::TypedBuilder;
11
12macro_rules! define_enum {
13 (
14 $(#[$meta:meta])*
15 with_dispatch,
16 $name:ident, $default_variant:ident,
17 $(
18 $variant:ident => ($rename:expr, $emulation_fn:path)
19 ),* $(,)?
20 ) => {
21 $(#[$meta])*
22 #[non_exhaustive]
23 #[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
24 #[cfg_attr(feature = "emulation-rand", derive(VariantArray))]
25 #[cfg_attr(feature = "emulation-serde", derive(Deserialize, Serialize))]
26 pub enum $name {
27 $(
28 #[cfg_attr(feature = "emulation-serde", serde(rename = $rename))]
29 $variant,
30 )*
31 }
32
33 impl Default for $name {
34 fn default() -> Self {
35 $name::$default_variant
36 }
37 }
38
39 impl $name {
40 pub fn into_emulation(self, opt: EmulationOption) -> wreq::Emulation {
41 match self {
42 $(
43 $name::$variant => $emulation_fn(opt),
44 )*
45 }
46 }
47 }
48 };
49
50 (
51 $(#[$meta:meta])*
52 plain,
53 $name:ident, $default_variant:ident,
54 $(
55 $variant:ident => $rename:expr
56 ),* $(,)?
57 ) => {
58 $(#[$meta])*
59 #[non_exhaustive]
60 #[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
61 #[cfg_attr(feature = "emulation-rand", derive(VariantArray))]
62 #[cfg_attr(feature = "emulation-serde", derive(Deserialize, Serialize))]
63 pub enum $name {
64 $(
65 #[cfg_attr(feature = "emulation-serde", serde(rename = $rename))]
66 $variant,
67 )*
68 }
69
70 impl Default for $name {
71 fn default() -> Self {
72 $name::$default_variant
73 }
74 }
75 };
76}
77
78define_enum!(
79 with_dispatch,
94 Emulation, Chrome100,
95
96 Chrome100 => ("chrome_100", v100::emulation),
98 Chrome101 => ("chrome_101", v101::emulation),
99 Chrome104 => ("chrome_104", v104::emulation),
100 Chrome105 => ("chrome_105", v105::emulation),
101 Chrome106 => ("chrome_106", v106::emulation),
102 Chrome107 => ("chrome_107", v107::emulation),
103 Chrome108 => ("chrome_108", v108::emulation),
104 Chrome109 => ("chrome_109", v109::emulation),
105 Chrome110 => ("chrome_110", v110::emulation),
106 Chrome114 => ("chrome_114", v114::emulation),
107 Chrome116 => ("chrome_116", v116::emulation),
108 Chrome117 => ("chrome_117", v117::emulation),
109 Chrome118 => ("chrome_118", v118::emulation),
110 Chrome119 => ("chrome_119", v119::emulation),
111 Chrome120 => ("chrome_120", v120::emulation),
112 Chrome123 => ("chrome_123", v123::emulation),
113 Chrome124 => ("chrome_124", v124::emulation),
114 Chrome126 => ("chrome_126", v126::emulation),
115 Chrome127 => ("chrome_127", v127::emulation),
116 Chrome128 => ("chrome_128", v128::emulation),
117 Chrome129 => ("chrome_129", v129::emulation),
118 Chrome130 => ("chrome_130", v130::emulation),
119 Chrome131 => ("chrome_131", v131::emulation),
120 Chrome132 => ("chrome_132", v132::emulation),
121 Chrome133 => ("chrome_133", v133::emulation),
122 Chrome134 => ("chrome_134", v134::emulation),
123 Chrome135 => ("chrome_135", v135::emulation),
124 Chrome136 => ("chrome_136", v136::emulation),
125 Chrome137 => ("chrome_137", v137::emulation),
126 Chrome138 => ("chrome_138", v138::emulation),
127 Chrome139 => ("chrome_139", v139::emulation),
128 Chrome140 => ("chrome_140", v140::emulation),
129 Chrome141 => ("chrome_141", v141::emulation),
130 Chrome142 => ("chrome_142", v142::emulation),
131 Chrome143 => ("chrome_143", v143::emulation),
132 Chrome144 => ("chrome_144", v144::emulation),
133 Chrome145 => ("chrome_145", v145::emulation),
134
135 Edge101 => ("edge_101", edge101::emulation),
137 Edge122 => ("edge_122", edge122::emulation),
138 Edge127 => ("edge_127", edge127::emulation),
139 Edge131 => ("edge_131", edge131::emulation),
140 Edge134 => ("edge_134", edge134::emulation),
141 Edge135 => ("edge_135", edge135::emulation),
142 Edge136 => ("edge_136", edge136::emulation),
143 Edge137 => ("edge_137", edge137::emulation),
144 Edge138 => ("edge_138", edge138::emulation),
145 Edge139 => ("edge_139", edge139::emulation),
146 Edge140 => ("edge_140", edge140::emulation),
147 Edge141 => ("edge_141", edge141::emulation),
148 Edge142 => ("edge_142", edge142::emulation),
149 Edge143 => ("edge_143", edge143::emulation),
150 Edge144 => ("edge_144", edge144::emulation),
151 Edge145 => ("edge_145", edge145::emulation),
152
153 Opera116 => ("opera_116", opera116::emulation),
155 Opera117 => ("opera_117", opera117::emulation),
156 Opera118 => ("opera_118", opera118::emulation),
157 Opera119 => ("opera_119", opera119::emulation),
158
159 Firefox109 => ("firefox_109", ff109::emulation),
161 Firefox117 => ("firefox_117", ff117::emulation),
162 Firefox128 => ("firefox_128", ff128::emulation),
163 Firefox133 => ("firefox_133", ff133::emulation),
164 Firefox135 => ("firefox_135", ff135::emulation),
165 FirefoxPrivate135 => ("firefox_private_135", ff_private_135::emulation),
166 FirefoxAndroid135 => ("firefox_android_135", ff_android_135::emulation),
167 Firefox136 => ("firefox_136", ff136::emulation),
168 FirefoxPrivate136 => ("firefox_private_136", ff_private_136::emulation),
169 Firefox139 => ("firefox_139", ff139::emulation),
170 Firefox142 => ("firefox_142", ff142::emulation),
171 Firefox143 => ("firefox_143", ff143::emulation),
172 Firefox144 => ("firefox_144", ff144::emulation),
173 Firefox145 => ("firefox_145", ff145::emulation),
174 Firefox146 => ("firefox_146", ff146::emulation),
175 Firefox147 => ("firefox_147", ff147::emulation),
176
177 SafariIos17_2 => ("safari_ios_17.2", safari_ios_17_2::emulation),
179 SafariIos17_4_1 => ("safari_ios_17.4.1", safari_ios_17_4_1::emulation),
180 SafariIos16_5 => ("safari_ios_16.5", safari_ios_16_5::emulation),
181 Safari15_3 => ("safari_15.3", safari15_3::emulation),
182 Safari15_5 => ("safari_15.5", safari15_5::emulation),
183 Safari15_6_1 => ("safari_15.6.1", safari15_6_1::emulation),
184 Safari16 => ("safari_16", safari16::emulation),
185 Safari16_5 => ("safari_16.5", safari16_5::emulation),
186 Safari17_0 => ("safari_17.0", safari17_0::emulation),
187 Safari17_2_1 => ("safari_17.2.1", safari17_2_1::emulation),
188 Safari17_4_1 => ("safari_17.4.1", safari17_4_1::emulation),
189 Safari17_5 => ("safari_17.5", safari17_5::emulation),
190 Safari17_6 => ("safari_17.6", safari17_6::emulation),
191 Safari18 => ("safari_18", safari18::emulation),
192 SafariIPad18 => ("safari_ipad_18", safari_ipad_18::emulation),
193 Safari18_2 => ("safari_18.2", safari18_2::emulation),
194 SafariIos18_1_1 => ("safari_ios_18.1.1", safari_ios_18_1_1::emulation),
195 Safari18_3 => ("safari_18.3", safari18_3::emulation),
196 Safari18_3_1 => ("safari_18.3.1", safari18_3_1::emulation),
197 Safari18_5 => ("safari_18.5", safari18_5::emulation),
198 Safari26 => ("safari_26", safari26::emulation),
199 Safari26_1 => ("safari_26.1", safari26_1::emulation),
200 Safari26_2 => ("safari_26.2", safari26_2::emulation),
201 SafariIPad26 => ("safari_ipad_26", safari_ipad_26::emulation),
202 SafariIpad26_2 => ("safari_ipad_26.2", safari_ipad_26_2::emulation),
203 SafariIos26 => ("safari_ios_26", safari_ios_26::emulation),
204 SafariIos26_2 => ("safari_ios_26.2", safari_ios_26_2::emulation),
205
206 OkHttp3_9 => ("okhttp_3.9", okhttp3_9::emulation),
208 OkHttp3_11 => ("okhttp_3.11", okhttp3_11::emulation),
209 OkHttp3_13 => ("okhttp_3.13", okhttp3_13::emulation),
210 OkHttp3_14 => ("okhttp_3.14", okhttp3_14::emulation),
211 OkHttp4_9 => ("okhttp_4.9", okhttp4_9::emulation),
212 OkHttp4_10 => ("okhttp_4.10", okhttp4_10::emulation),
213 OkHttp4_12 => ("okhttp_4.12", okhttp4_12::emulation),
214 OkHttp5 => ("okhttp_5", okhttp5::emulation)
215
216);
217
218impl wreq::EmulationFactory for Emulation {
220 #[inline]
221 fn emulation(self) -> wreq::Emulation {
222 EmulationOption::builder()
223 .emulation(self)
224 .build()
225 .emulation()
226 }
227}
228
229define_enum!(
230 plain,
243 EmulationOS, MacOS,
244 Windows => "windows",
245 MacOS => "macos",
246 Linux => "linux",
247 Android => "android",
248 IOS => "ios"
249);
250
251impl EmulationOS {
253 #[inline]
254 const fn platform(&self) -> &'static str {
255 match self {
256 EmulationOS::MacOS => "\"macOS\"",
257 EmulationOS::Linux => "\"Linux\"",
258 EmulationOS::Windows => "\"Windows\"",
259 EmulationOS::Android => "\"Android\"",
260 EmulationOS::IOS => "\"iOS\"",
261 }
262 }
263
264 #[inline]
265 const fn is_mobile(&self) -> bool {
266 matches!(self, EmulationOS::Android | EmulationOS::IOS)
267 }
268}
269
270#[derive(Default, Clone, TypedBuilder)]
286pub struct EmulationOption {
287 #[builder(default)]
289 emulation: Emulation,
290
291 #[builder(default)]
293 emulation_os: EmulationOS,
294
295 #[builder(default = false)]
297 skip_http2: bool,
298
299 #[builder(default = false)]
301 skip_headers: bool,
302}
303
304impl wreq::EmulationFactory for EmulationOption {
306 #[inline]
307 fn emulation(self) -> wreq::Emulation {
308 self.emulation.into_emulation(self)
309 }
310}