Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(devtools): make Page crash terminal IO control

ldm0f63a5640abaa
diff --git a/moli-core/src/page/mod.rs b/moli-core/src/page/mod.rs
index 8963c348d..42fda63e0 100644
--- a/moli-core/src/page/mod.rs
+++ b/moli-core/src/page/mod.rs
@@ -247,6 +247,16 @@ impl Page {
self.handle.devtools_agent_token()
}
+ /// Seals this target's Main/IO DevTools ingress and interrupts active V8.
+ ///
+ /// `Page.crash` is a terminal renderer IO control in Chromium, not an
+ /// ordinary V8 Inspector command. Protocol integrations use this boundary
+ /// to retire the Page without waiting behind a session lane.
+ #[doc(hidden)]
+ pub fn crash_devtools_target_from_io(&self) {
+ self.handle.crash_devtools_target_from_io();
+ }
+
#[doc(hidden)]
pub fn set_renderer_devtools_command_session_id(&mut self, session_id: Option<String>) {
self.renderer_devtools_command_session_id = session_id;
diff --git a/moli-protocol/src/domains/page/termination.rs b/moli-protocol/src/domains/page/termination.rs
index a90f82a7b..ce1a0102b 100644
--- a/moli-protocol/src/domains/page/termination.rs
+++ b/moli-protocol/src/domains/page/termination.rs
@@ -474,15 +474,12 @@ pub(super) async fn complete_crash_command_dispatch(
pending_subresource_responses,
) = take_pending_fetch_state(conn, session_id);
- // Page.crash is an IO-agent command in Chromium. Capture protocol-owned
- // request residences first, then cooperatively terminate active V8 before
- // retiring the Page so teardown cannot wait behind the JavaScript stack it
- // is meant to destroy.
- if let Ok(termination) = conn.start_runtime_io_protocol_message_for_session_owner(
- session_id,
- r#"{"id":0,"method":"Runtime.terminateExecution"}"#.to_owned(),
- ) {
- let _ = termination.wait().await;
+ // Chromium handles Page.crash directly at the renderer IO-agent boundary;
+ // it never enters a V8InspectorSession or an ordinary per-session IO lane.
+ // Seal both DevTools receivers and interrupt active V8 synchronously so
+ // target retirement cannot wait behind earlier JavaScript or IO work.
+ if let Ok(page) = conn.loaded_page_mut_for_interruptible_protocol_access(session_id) {
+ page.crash_devtools_target_from_io();
}
// Page.crash retires the target, not merely the DevTools session which
diff --git a/moli-renderer-v8/src/devtools/target.rs b/moli-renderer-v8/src/devtools/target.rs
index a09247c51..ce69cdadb 100644
--- a/moli-renderer-v8/src/devtools/target.rs
+++ b/moli-renderer-v8/src/devtools/target.rs
@@ -68,6 +68,15 @@ impl RendererDevToolsTargetHandle {
self.io.terminate_execution_for_target_close()
}
+ /// Executes Chromium's terminal `Page.crash` IO control boundary.
+ ///
+ /// Unlike ordinary IO-agent commands, a crash must not wait for or occupy
+ /// a per-session first-dispatch lane. Seal both command receivers first,
+ /// then interrupt any active JavaScript so the owner can retire the Page.
+ pub(crate) fn crash_from_io(&self) {
+ let _ = self.close("Inspector target crashed through Page.crash");
+ }
+
pub(crate) fn detach_page(&self, page_id: PageId, message: &str) {
if self.pause.detach_page(page_id) {
self.main.cancel_all_queued(message);
@@ -86,3 +95,93 @@ impl std::fmt::Debug for RendererDevToolsTargetHandle {
.finish()
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::{
+ devtools::{
+ command::{
+ RendererDevToolsIoCommandEnvelope, RendererInspectorCommandEnvelope,
+ RendererInspectorCommandRoute, RendererInspectorIngressTicket,
+ },
+ ingress::{
+ io::{RendererInspectorIoIngress, RendererRuntimeInspectorIoCommandClaim},
+ main::{
+ RendererInspectorMainIngress, RendererRuntimeInspectorMainCommandCompletion,
+ },
+ },
+ route::RendererInspectorSessionExecutorRouteId,
+ },
+ runtime::{
+ PageId, RendererPageToken, RendererRuntimeInspectorAsyncCompletion,
+ RendererRuntimeInspectorResponseSender,
+ },
+ };
+
+ #[tokio::test]
+ async fn page_crash_is_terminal_and_bypasses_main_and_io_lanes() {
+ let pause = RendererInspectorPauseBridge::default();
+ let main = RendererInspectorMainIngress::new(
+ RendererInspectorSessionExecutorRouteId::new(1),
+ pause.pause_loop_wake(),
+ );
+ let io = RendererInspectorIoIngress::new(pause.pause_loop_wake(), None);
+ let target = RendererDevToolsTargetHandle::new(pause, main.clone(), io.clone());
+ let agent = RendererDevToolsAgentToken::allocate();
+ let session_id = Some("session-a".to_owned());
+
+ let io_route = io.enqueue_command(
+ agent,
+ RendererDevToolsIoCommandEnvelope::performance_get_metrics(
+ RendererInspectorIngressTicket::new(
+ None,
+ session_id.clone(),
+ RendererInspectorCommandRoute::Io,
+ ),
+ ),
+ );
+ let (response_tx, _response_rx) =
+ tokio::sync::oneshot::channel::<RendererRuntimeInspectorAsyncCompletion>();
+ let main_route = main.enqueue_command(
+ RendererPageToken::new_for_testing(PageId::new_for_testing(1)),
+ agent,
+ RendererInspectorCommandEnvelope::new_main_protocol(
+ RendererInspectorIngressTicket::new(
+ None,
+ session_id,
+ RendererInspectorCommandRoute::MainThread,
+ ),
+ None,
+ r#"{"id":1,"method":"Runtime.evaluate"}"#.to_owned(),
+ RendererRuntimeInspectorResponseSender::new(1, response_tx),
+ ),
+ );
+
+ target.crash_from_io();
+ assert_eq!(
+ io_route.wait_for_first_dispatch().await,
+ Ok(RendererRuntimeInspectorIoCommandClaim::Canceled)
+ );
+ assert!(matches!(
+ main_route.wait_for_completion().await,
+ Ok(RendererRuntimeInspectorMainCommandCompletion::Canceled)
+ ));
+
+ let late = io.enqueue_command(
+ agent,
+ RendererDevToolsIoCommandEnvelope::performance_get_metrics(
+ RendererInspectorIngressTicket::new(
+ None,
+ Some("session-late".to_owned()),
+ RendererInspectorCommandRoute::Io,
+ ),
+ ),
+ );
+ assert_eq!(
+ late.wait_for_first_dispatch().await,
+ Ok(RendererRuntimeInspectorIoCommandClaim::Canceled),
+ "terminal Page.crash must reject late ordinary IO work"
+ );
+ }
+}
diff --git a/moli-renderer-v8/src/runtime/owner_local.rs b/moli-renderer-v8/src/runtime/owner_local.rs
index 1c8c40b1d..d5eea0960 100644
--- a/moli-renderer-v8/src/runtime/owner_local.rs
+++ b/moli-renderer-v8/src/runtime/owner_local.rs
@@ -158,6 +158,13 @@ impl RendererPageHandle {
self.devtools_agent_token
}
+ /// Applies the terminal `Page.crash` IO control without entering either
+ /// ordinary DevTools command lane.
+ #[doc(hidden)]
+ pub fn crash_devtools_target_from_io(&self) {
+ self.devtools_target.crash_from_io();
+ }
+
#[doc(hidden)]
pub fn take_committed_document_post_response_continuation(
&mut self,