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
//! Network proxy settings
//!
//! This module defines the [`ProxySettings`] struct which encapsulates
//! the configuration for proxies used for network requests.
//!
//! Proxy settings can be applied at both the browser launch level
//! ([`LaunchOptions`](crate::api::LaunchOptions)) and the browser context level
//! ([`BrowserContextOptions`](crate::protocol::BrowserContextOptions)).
//!
//! See: <https://playwright.dev/docs/api/class-browser#browser-new-context>
use serde::{Deserialize, Serialize};
/// Network proxy settings for browser contexts and browser launches.
///
/// HTTP and SOCKS proxies are supported. Example proxy URLs:
/// - `http://myproxy.com:3128`
/// - `socks5://myproxy.com:3128`
///
/// # Example
///
/// ```no_run
/// use playwright_rs::protocol::ProxySettings;
///
/// let proxy = ProxySettings::new("http://proxy.example.com:8080")
/// .bypass(".example.com, chromium.org")
/// .username("user")
/// .password("secret");
/// ```
///
/// See: <https://playwright.dev/docs/api/class-browser#browser-new-context>
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct ProxySettings {
/// Proxy server URL (e.g., "http://proxy:8080" or "socks5://proxy:1080")
pub server: String,
/// Comma-separated domains to bypass proxy (e.g., ".example.com, chromium.org")
#[serde(skip_serializing_if = "Option::is_none")]
pub bypass: Option<String>,
/// Proxy username for HTTP proxy authentication
#[serde(skip_serializing_if = "Option::is_none")]
pub username: Option<String>,
/// Proxy password for HTTP proxy authentication
#[serde(skip_serializing_if = "Option::is_none")]
pub password: Option<String>,
}
impl ProxySettings {
/// Proxy all traffic through the given server (e.g. "http://host:3128").
pub fn new(server: impl Into<String>) -> Self {
Self {
server: server.into(),
bypass: None,
username: None,
password: None,
}
}
/// Comma-separated domains to bypass the proxy for.
pub fn bypass(mut self, bypass: impl Into<String>) -> Self {
self.bypass = Some(bypass.into());
self
}
/// Proxy auth username.
pub fn username(mut self, username: impl Into<String>) -> Self {
self.username = Some(username.into());
self
}
/// Proxy auth password.
pub fn password(mut self, password: impl Into<String>) -> Self {
self.password = Some(password.into());
self
}
}