diff --git a/moli-protocol-server/src/protocol_server/tests/websocket/navigation_debugger/beforeunload.rs b/moli-protocol-server/src/protocol_server/tests/websocket/navigation_debugger/beforeunload.rs index 981fa36b778..265a95ad206 100644 --- a/moli-protocol-server/src/protocol_server/tests/websocket/navigation_debugger/beforeunload.rs +++ b/moli-protocol-server/src/protocol_server/tests/websocket/navigation_debugger/beforeunload.rs @@ -185,7 +185,11 @@ async fn check_beforeunload_while_paused(runtime_command: bool) { let _ = socket.close(None).await; abort_test_cdp_server(server).await; fixture.abort(); - assert_eq!(bindings, vec![json!("root:false"), json!("child:false")]); + assert_eq!( + bindings, + vec![json!("root:false"), json!("child:false")], + "before fetch: {messages:#?}; navigation completion: {completed:#?}" + ); assert_eq!( consoles, vec![json!("beforeunload:root"), json!("beforeunload:child")] diff --git a/moli-renderer-v8/src/runtime/page_vm/devtools.rs b/moli-renderer-v8/src/runtime/page_vm/devtools.rs index b681c901c09..2572a6b4335 100644 --- a/moli-renderer-v8/src/runtime/page_vm/devtools.rs +++ b/moli-renderer-v8/src/runtime/page_vm/devtools.rs @@ -54,9 +54,15 @@ impl PageVm { self.vm().append_live_command_output_prefix(); self.absorb_pending_dom_mutations_into_output_journal(); self.record_document_title_change_if_needed(); - let publication = self.vm_mut().settle_renderer_output_prefix()?; - let journal = self.vm().renderer_command_output_journal(); - journal.publish_resolved_prefix_and_declare_fence(publication) + if let Some(publication) = self.vm_mut().settle_renderer_output_prefix() { + let journal = self.vm().renderer_command_output_journal(); + return journal.publish_resolved_prefix_and_declare_fence(publication); + } + // Inspector callbacks can publish the prefix while the owner remains + // paused. An empty pending journal still needs a fence for that concrete + // tail before an internal reply starts navigation or replaces the Page. + let cursor = self.renderer_output_tail_cursor()?; + Some(self.declare_renderer_output_fence(cursor)) } pub(super) fn runtime_inspector_session_restore_snapshots( diff --git a/moli-renderer-v8/src/script_vm/child_frame_runtime.rs b/moli-renderer-v8/src/script_vm/child_frame_runtime.rs index d7025c4b4f8..401c874de08 100644 --- a/moli-renderer-v8/src/script_vm/child_frame_runtime.rs +++ b/moli-renderer-v8/src/script_vm/child_frame_runtime.rs @@ -542,13 +542,9 @@ impl ScriptVm { // alive without a RefCell borrow across reentrant author callbacks. let context_host = Rc::clone(&self._context_host); let host_ptr = (*context_host).as_ptr(); - let allowed = unsafe { &mut *host_ptr }.dispatch_main_document_tree_beforeunload(scope); - // A paused Runtime command may own the active recorder. Flush its - // concrete prefix just as for a modal dialog, without closing that - // recorder or completing the suspended task. The navigation reply - // fences this prefix so console/binding output precedes the fetch. - unsafe { &*host_ptr }.publish_live_turn_output_prefix(); - allowed + // The nested command boundary resolves the remaining output and fences + // the concrete stream tail without closing the paused command recorder. + unsafe { &mut *host_ptr }.dispatch_main_document_tree_beforeunload(scope) } pub(crate) fn unload_main_document_for_navigation_commit(&mut self) -> anyhow::Result<()> {