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

Method cleanup_failed_session

src/cdp.rs:291–325  ·  view source on GitHub ↗

Clean up a failed persistent session: detach from Chrome, stash the new tab's state back into the map, and transition to a clean detached state.

(
        &mut self,
        session_id: &str,
        failed_target_id: &str,
        state_loaded: bool,
    )

Source from the content-addressed store, hash-verified

289 /// Clean up a failed persistent session: detach from Chrome, stash the new
290 /// tab's state back into the map, and transition to a clean detached state.
291 async fn cleanup_failed_session(
292 &mut self,
293 session_id: &str,
294 failed_target_id: &str,
295 state_loaded: bool,
296 ) {
297 if state_loaded {
298 // Stash the state of the tab we failed to initialize so it's not lost.
299 // It's currently in the active fields.
300 let failed_state = TabEmulation {
301 blocklist: std::mem::take(&mut self.blocklist),
302 viewport: self.viewport.take(),
303 geolocation: self.geolocation.take(),
304 };
305 stash_tab_emulation(
306 &mut self.emulation_saved,
307 failed_target_id.to_string(),
308 failed_state,
309 );
310 }
311
312 let _ = self
313 .send("Target.detachFromTarget", json!({"sessionId": session_id}))
314 .await;
315
316 self.persistent_session = None;
317 self.persistent_target_id = None;
318
319 // Clear events captured from the failed session during the detach call
320 // (which can read from the websocket and thus trigger push_event).
321 self.network_events.clear();
322 self.console_events.clear();
323 self.events
324 .retain(|event| event["sessionId"].as_str() != Some(session_id));
325 }
326
327 /// Drop any stored emulation state for a target (e.g. when its tab closes).
328 /// If it's the active tab, also reset the active fields and the now-invalid

Callers 1

Calls 2

stash_tab_emulationFunction · 0.85
sendMethod · 0.45

Tested by

no test coverage detected