Skip to main content

playwright_rs/protocol/
proxy.rs

1//! Network proxy settings
2//!
3//! This module defines the [`ProxySettings`] struct which encapsulates
4//! the configuration for proxies used for network requests.
5//!
6//! Proxy settings can be applied at both the browser launch level
7//! ([`LaunchOptions`](crate::api::LaunchOptions)) and the browser context level
8//! ([`BrowserContextOptions`](crate::protocol::BrowserContextOptions)).
9//!
10//! See: <https://playwright.dev/docs/api/class-browser#browser-new-context>
11
12use serde::{Deserialize, Serialize};
13
14/// Network proxy settings for browser contexts and browser launches.
15///
16/// HTTP and SOCKS proxies are supported. Example proxy URLs:
17/// - `http://myproxy.com:3128`
18/// - `socks5://myproxy.com:3128`
19///
20/// # Example
21///
22/// ```ignore
23/// use playwright_rs::protocol::ProxySettings;
24///
25/// let proxy = ProxySettings {
26///     server: "http://proxy.example.com:8080".to_string(),
27///     bypass: Some(".example.com, chromium.org".to_string()),
28///     username: Some("user".to_string()),
29///     password: Some("secret".to_string()),
30/// };
31/// ```
32///
33/// See: <https://playwright.dev/docs/api/class-browser#browser-new-context>
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(rename_all = "camelCase")]
36pub struct ProxySettings {
37    /// Proxy server URL (e.g., "http://proxy:8080" or "socks5://proxy:1080")
38    pub server: String,
39
40    /// Comma-separated domains to bypass proxy (e.g., ".example.com, chromium.org")
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub bypass: Option<String>,
43
44    /// Proxy username for HTTP proxy authentication
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub username: Option<String>,
47
48    /// Proxy password for HTTP proxy authentication
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub password: Option<String>,
51}