Close Servo live sessions for removed tabs

This commit is contained in:
2026-05-13 02:41:54 -04:00
parent 74731d4faa
commit ac84a80d9e
11 changed files with 133 additions and 5 deletions
@@ -99,6 +99,10 @@ impl ServoLiveClient {
self.request(LiveRequest::Poll { tab_id })
}
pub fn close(&mut self, tab_id: String) -> Result<(), ServoLiveError> {
self.request(LiveRequest::Close { tab_id }).map(|_| ())
}
fn request(&mut self, request: LiveRequest) -> Result<Option<ServoLiveFrame>, ServoLiveError> {
serde_json::to_writer(&mut self.stdin, &request)?;
self.stdin.write_all(b"\n").map_err(ServoLiveError::Command)?;
@@ -27,6 +27,9 @@ pub(super) enum LiveRequest {
Poll {
tab_id: String,
},
Close {
tab_id: String,
},
}
#[derive(Deserialize)]
@@ -156,3 +159,19 @@ pub(super) fn log_frame_perf(summary: &LiveFramePerfSummary) {
"frame_perf",
);
}
#[cfg(test)]
mod tests {
use serde_json::json;
use super::*;
#[test]
fn close_request_serializes_to_wire() -> Result<(), serde_json::Error> {
let value =
serde_json::to_value(LiveRequest::Close { tab_id: "tab-live-close".to_string() })?;
assert_eq!(value, json!({"type": "close", "tab_id": "tab-live-close"}));
Ok(())
}
}