playwright_rs/api/connect_options.rs
1use std::collections::HashMap;
2
3/// Options for `BrowserType::connect_over_cdp`.
4///
5/// Only supported for Chromium. Allows connecting to a Chrome DevTools Protocol endpoint,
6/// such as those provided by browserless, Chrome with `--remote-debugging-port`, or other
7/// CDP-compatible services.
8///
9/// See: <https://playwright.dev/docs/api/class-browsertype#browser-type-connect-over-cdp>
10#[derive(Debug, Clone, Default)]
11pub struct ConnectOverCdpOptions {
12 /// Additional HTTP headers to be sent with the connection request.
13 pub headers: Option<HashMap<String, String>>,
14 /// Slows down Playwright operations by the specified amount of milliseconds.
15 pub slow_mo: Option<f64>,
16 /// Maximum time in milliseconds to wait for the connection to be established.
17 /// Defaults to 30000 (30 seconds). Pass 0 to disable timeout.
18 pub timeout: Option<f64>,
19}
20
21impl ConnectOverCdpOptions {
22 /// Creates a new `ConnectOverCdpOptions` with default values.
23 pub fn new() -> Self {
24 Self::default()
25 }
26
27 /// Set additional HTTP headers to send with the connection request.
28 pub fn headers(mut self, headers: HashMap<String, String>) -> Self {
29 self.headers = Some(headers);
30 self
31 }
32
33 /// Set slow mo delay in milliseconds.
34 pub fn slow_mo(mut self, slow_mo: f64) -> Self {
35 self.slow_mo = Some(slow_mo);
36 self
37 }
38
39 /// Set connection timeout in milliseconds.
40 pub fn timeout(mut self, timeout: f64) -> Self {
41 self.timeout = Some(timeout);
42 self
43 }
44}
45
46/// Options for `BrowserType::connect`.
47#[derive(Debug, Clone, Default)]
48pub struct ConnectOptions {
49 /// Additional HTTP headers to send with the WebSocket handshake.
50 pub headers: Option<HashMap<String, String>>,
51 /// Slows down Playwright operations by the specified amount of milliseconds.
52 /// Useful so that you can see what is going on.
53 pub slow_mo: Option<f64>,
54 /// Maximum time in milliseconds to wait for the connection to be established.
55 /// Defaults to 30000 (30 seconds). Pass 0 to disable timeout.
56 pub timeout: Option<f64>,
57}
58
59impl ConnectOptions {
60 /// Creates a new `ConnectOptions` with default values.
61 pub fn new() -> Self {
62 Self::default()
63 }
64
65 /// Set additional HTTP headers to send with the WebSocket handshake.
66 pub fn headers(mut self, headers: HashMap<String, String>) -> Self {
67 self.headers = Some(headers);
68 self
69 }
70
71 /// Set slow mo delay in milliseconds.
72 pub fn slow_mo(mut self, slow_mo: f64) -> Self {
73 self.slow_mo = Some(slow_mo);
74 self
75 }
76
77 /// Set connection timeout in milliseconds.
78 pub fn timeout(mut self, timeout: f64) -> Self {
79 self.timeout = Some(timeout);
80 self
81 }
82}