MCPcopy Create free account
hub / github.com/aeroxy/chrome-devtools-cli / read_devtools_active_port

Function read_devtools_active_port

src/browser.rs:28–65  ·  view source on GitHub ↗

Read DevToolsActivePort file and construct the WebSocket URL.

(user_data_dir: &Path)

Source from the content-addressed store, hash-verified

26
27/// Read DevToolsActivePort file and construct the WebSocket URL.
28fn read_devtools_active_port(user_data_dir: &Path) -> Result<String> {
29 let port_path = user_data_dir.join("DevToolsActivePort");
30
31 let content = std::fs::read_to_string(&port_path).map_err(|_| {
32 anyhow!(
33 "Could not read DevToolsActivePort at {}\n\n\
34 Make sure Chrome is running with remote debugging enabled:\n\
35 1. Open Chrome\n\
36 2. Go to chrome://inspect/#remote-debugging\n\
37 3. Enable the remote debugging server",
38 port_path.display()
39 )
40 })?;
41
42 let lines: Vec<&str> = content
43 .lines()
44 .map(|l| l.trim())
45 .filter(|l| !l.is_empty())
46 .collect();
47
48 if lines.len() < 2 {
49 bail!(
50 "Invalid DevToolsActivePort content: expected port and path, got: {:?}",
51 content.trim()
52 );
53 }
54
55 let port: u16 = lines[0]
56 .parse()
57 .map_err(|_| anyhow!("Invalid port '{}' in DevToolsActivePort", lines[0]))?;
58
59 if port == 0 {
60 bail!("Port 0 in DevToolsActivePort — Chrome may not be running");
61 }
62
63 let path = lines[1];
64 Ok(format!("ws://127.0.0.1:{port}{path}"))
65}
66
67/// Get the default Chrome user data directory for the given channel.
68fn default_chrome_user_data_dir(channel: &str) -> Result<PathBuf> {

Callers 1

resolve_ws_urlFunction · 0.85

Calls 1

is_emptyMethod · 0.80

Tested by

no test coverage detected