Resolve the WebSocket URL for connecting to Chrome. Priority: 1. Explicit --ws-endpoint 2. Auto-connect via DevToolsActivePort (default)
(
ws_endpoint: Option<&str>,
user_data_dir: Option<&str>,
channel: &str,
)
| 7 | /// 1. Explicit --ws-endpoint |
| 8 | /// 2. Auto-connect via DevToolsActivePort (default) |
| 9 | pub fn resolve_ws_url( |
| 10 | ws_endpoint: Option<&str>, |
| 11 | user_data_dir: Option<&str>, |
| 12 | channel: &str, |
| 13 | ) -> Result<String> { |
| 14 | if let Some(ws) = ws_endpoint { |
| 15 | return Ok(ws.to_string()); |
| 16 | } |
| 17 | |
| 18 | // Auto-connect: read DevToolsActivePort from Chrome's user data directory |
| 19 | let data_dir = match user_data_dir { |
| 20 | Some(dir) => PathBuf::from(dir), |
| 21 | None => default_chrome_user_data_dir(channel)?, |
| 22 | }; |
| 23 | |
| 24 | read_devtools_active_port(&data_dir) |
| 25 | } |
| 26 | |
| 27 | /// Read DevToolsActivePort file and construct the WebSocket URL. |
| 28 | fn read_devtools_active_port(user_data_dir: &Path) -> Result<String> { |
no test coverage detected