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

Function execute_command

src/commands/executor.rs:126–309  ·  view source on GitHub ↗

Execute a single command from a [`DaemonRequest`]. Handles target resolution, session attachment, dialog configuration, and target ID enrichment on success.

(client: &mut CdpClient, req: &DaemonRequest)

Source from the content-addressed store, hash-verified

124/// Handles target resolution, session attachment, dialog configuration,
125/// and target ID enrichment on success.
126pub async fn execute_command(client: &mut CdpClient, req: &DaemonRequest) -> Result<CommandResult> {
127 let cmd = req.command.as_str();
128
129 // Event-collecting commands drain the buffer via read_events_for,
130 // so they can capture events that arrived between commands.
131 // All other commands clear stale events to prevent memory buildup.
132 if !matches!(cmd, "console" | "network" | "sw-logs") {
133 client.clear_events();
134 }
135
136 let args = &req.args;
137
138 validate_args(cmd, args)?;
139
140 if is_browser_level(cmd) {
141 return match cmd {
142 "list-pages" => commands::pages::list_pages(client, req.format()).await,
143 "new-page" => {
144 let url = args
145 .get("url")
146 .and_then(|v| v.as_str())
147 .ok_or(anyhow!("url required"))?;
148
149 let viewport = args.get("viewport").and_then(|v| v.as_str());
150 let geolocation = args.get("geolocation").and_then(|v| v.as_str());
151
152 let params = commands::emulation::EmulateParams {
153 viewport: viewport.map(|s| s.to_string()),
154 device_scale_factor: args.get("device_scale_factor").and_then(|v| v.as_f64()),
155 mobile: args
156 .get("mobile")
157 .and_then(|v| v.as_bool())
158 .unwrap_or(false),
159 geolocation: geolocation.map(|s| s.to_string()),
160 accuracy: args.get("accuracy").and_then(|v| v.as_f64()),
161 clear_viewport: false,
162 clear_geolocation: false,
163 clear_all: false,
164 // Apply the global --block-url/--unblock-url flags to the new
165 // tab during its initial load, matching direct mode and the
166 // viewport/geolocation flags handled above.
167 block_url: req.block_url.clone(),
168 unblock_url: req.unblock_url.clone(),
169 clear_blocks: false,
170 };
171 params.validate()?;
172
173 let params = if params.has_emulation() {
174 Some(params)
175 } else {
176 None
177 };
178
179 commands::pages::new_page(
180 client,
181 url,
182 params,
183 args.get("extra_headers").and_then(|v| v.as_str()),

Callers 1

handle_requestFunction · 0.85

Calls 15

validate_argsFunction · 0.85
is_browser_levelFunction · 0.85
list_pagesFunction · 0.85
new_pageFunction · 0.85
collect_sw_logsFunction · 0.85
close_pageFunction · 0.85
select_pageFunction · 0.85
inner_executeFunction · 0.85
to_friendlyFunction · 0.85
clear_eventsMethod · 0.80
formatMethod · 0.80
validateMethod · 0.80

Tested by

no test coverage detected