mirror of
https://github.com/lexmount/moli.git
synced 2026-11-24 16:02:53 +00:00
fix(cdp): run overlay commands and captures during debugger pauses
This commit is contained in:
@@ -457,3 +457,162 @@ async fn websocket_cdp_capture_screenshot_preserves_default_mock_boundary() {
|
||||
.await;
|
||||
abort_test_cdp_server(protocol_server).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn websocket_cdp_highlights_and_following_queries_complete_while_paused() {
|
||||
let (addr, server) = spawn_test_protocol_server().await;
|
||||
let (mut socket, _) = connect_async(discover_browser_websocket_url(addr).await.unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
let html = "<!doctype html><style>body{margin:0;background:white} #target{position:absolute;left:8px;top:8px;width:12px;height:12px}</style><div id=target></div>";
|
||||
let url = format!(
|
||||
"data:text/html,{}",
|
||||
percent_encoding::utf8_percent_encode(html, percent_encoding::NON_ALPHANUMERIC),
|
||||
);
|
||||
let target = open_screenshot_target(&mut socket, &url).await;
|
||||
let session = target.session_id.as_str();
|
||||
for (id, method) in [
|
||||
(7, "Runtime.enable"),
|
||||
(8, "Debugger.enable"),
|
||||
(9, "DOM.enable"),
|
||||
(10, "Overlay.enable"),
|
||||
] {
|
||||
assert_cdp_success(
|
||||
&send_cdp_command(&mut socket, id, method, Some(session), json!({})).await,
|
||||
id,
|
||||
);
|
||||
}
|
||||
let evaluated = send_cdp_command(
|
||||
&mut socket,
|
||||
11,
|
||||
"Runtime.evaluate",
|
||||
Some(session),
|
||||
json!({"expression":"document.getElementById('target')"}),
|
||||
)
|
||||
.await;
|
||||
let object_id = response_by_id(&evaluated, 11)["result"]["result"]["objectId"]
|
||||
.as_str()
|
||||
.expect("Runtime object id");
|
||||
let described = send_cdp_command(
|
||||
&mut socket,
|
||||
12,
|
||||
"DOM.describeNode",
|
||||
Some(session),
|
||||
json!({"objectId":object_id}),
|
||||
)
|
||||
.await;
|
||||
let backend_node_id = response_by_id(&described, 12)["result"]["node"]["backendNodeId"]
|
||||
.as_u64()
|
||||
.expect("backend node id");
|
||||
send_cdp_command_without_wait(
|
||||
&mut socket,
|
||||
13,
|
||||
"Runtime.evaluate",
|
||||
Some(session),
|
||||
json!({"expression":"debugger; 42","returnByValue":true}),
|
||||
)
|
||||
.await;
|
||||
recv_until_match(&mut socket, |message| {
|
||||
message["sessionId"] == session && message["method"] == "Debugger.paused"
|
||||
})
|
||||
.await;
|
||||
|
||||
let clip = json!({"clip":{"x":0,"y":0,"width":32,"height":32,"scale":1}});
|
||||
let node_colors = json!({"contentColor":{"r":0,"g":0,"b":255}});
|
||||
let commands = [
|
||||
(
|
||||
14,
|
||||
"Overlay.highlightRect",
|
||||
json!({"x":2,"y":2,"width":4,"height":4,"color":{"r":255,"g":0,"b":0}}),
|
||||
),
|
||||
(
|
||||
15,
|
||||
"DOM.getBoxModel",
|
||||
json!({"backendNodeId":backend_node_id}),
|
||||
),
|
||||
(
|
||||
16,
|
||||
"Overlay.highlightNode",
|
||||
json!({"backendNodeId":backend_node_id,"highlightConfig":node_colors}),
|
||||
),
|
||||
(
|
||||
17,
|
||||
"Overlay.highlightNode",
|
||||
json!({"objectId":object_id,"highlightConfig":node_colors}),
|
||||
),
|
||||
(
|
||||
18,
|
||||
"Overlay.highlightNode",
|
||||
json!({"objectId":"invalid","highlightConfig":node_colors}),
|
||||
),
|
||||
(19, "Page.captureScreenshot", clip.clone()),
|
||||
(
|
||||
20,
|
||||
"Runtime.getProperties",
|
||||
json!({"objectId":object_id,"ownProperties":true}),
|
||||
),
|
||||
(21, "Overlay.hideHighlight", json!({})),
|
||||
(22, "Page.captureScreenshot", clip),
|
||||
(23, "Overlay.disable", json!({})),
|
||||
(
|
||||
24,
|
||||
"DOM.getBoxModel",
|
||||
json!({"backendNodeId":backend_node_id}),
|
||||
),
|
||||
];
|
||||
let paused = timeout(Duration::from_secs(10), async {
|
||||
let mut remaining = commands
|
||||
.iter()
|
||||
.map(|(id, _, _)| *id)
|
||||
.collect::<std::collections::BTreeSet<_>>();
|
||||
// Pipeline the requests to exercise the same-session Main queue.
|
||||
for (id, method, params) in commands {
|
||||
send_cdp_command_without_wait(&mut socket, id, method, Some(session), params).await;
|
||||
}
|
||||
recv_until_match(&mut socket, |message| {
|
||||
if message["sessionId"] == session
|
||||
&& let Some(id) = message["id"].as_u64()
|
||||
{
|
||||
remaining.remove(&id);
|
||||
}
|
||||
remaining.is_empty()
|
||||
})
|
||||
.await
|
||||
})
|
||||
.await;
|
||||
|
||||
let mut resumed =
|
||||
send_cdp_command(&mut socket, 25, "Debugger.resume", Some(session), json!({})).await;
|
||||
if !resumed.iter().any(|message| message["id"] == 13) {
|
||||
resumed.extend(recv_until_id(&mut socket, 13).await);
|
||||
}
|
||||
let _ = socket.close(None).await;
|
||||
abort_test_cdp_server(server).await;
|
||||
|
||||
let paused = paused.expect("Overlay commands and queries must finish before resuming");
|
||||
assert!(
|
||||
!paused
|
||||
.iter()
|
||||
.any(|message| message["id"] == 13 || message["method"] == "Debugger.resumed")
|
||||
);
|
||||
for id in (14..=24).filter(|id| *id != 18) {
|
||||
assert_cdp_success(&paused, id);
|
||||
}
|
||||
assert_eq!(response_by_id(&paused, 18)["error"]["code"], -32000);
|
||||
assert_eq!(response_by_id(&paused, 15)["result"]["model"]["width"], 12);
|
||||
assert_eq!(response_by_id(&paused, 24)["result"]["model"]["width"], 12);
|
||||
assert!(response_by_id(&paused, 20)["result"]["result"].is_array());
|
||||
for (id, color) in [(19, [0, 0, 255, 255]), (22, [255; 4])] {
|
||||
let result = response_by_id(&paused, id);
|
||||
let bytes = BASE64_STANDARD
|
||||
.decode(result["result"]["data"].as_str().unwrap())
|
||||
.unwrap();
|
||||
let (width, _, pixels) = decode_png(&bytes);
|
||||
assert_eq!(pixel(&pixels, width, 10, 10), color);
|
||||
}
|
||||
assert_cdp_success(&resumed, 25);
|
||||
assert_eq!(
|
||||
response_by_id(&resumed, 13)["result"]["result"]["value"],
|
||||
42
|
||||
);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ fn start(conn: &mut CdpConnection, cmd: &Cmd<'_>, action: OverlayAction) -> Nati
|
||||
RendererNativeOperation::new(
|
||||
RendererPageCommand::DevTools(RendererDevToolsPageCommand::SetOverlayHighlight {
|
||||
inspector_session_id,
|
||||
highlight,
|
||||
highlight: Ok(highlight),
|
||||
}),
|
||||
native::unit_response,
|
||||
),
|
||||
|
||||
@@ -121,6 +121,10 @@ impl RendererDevToolsPageCommand {
|
||||
}
|
||||
Self::Inspector(envelope) if envelope.is_runtime_binding_removal_commit() => PageAgent,
|
||||
Self::Inspector(_) => OwnerOnly,
|
||||
Self::SetOverlayHighlight {
|
||||
highlight: Ok(Some(highlight)),
|
||||
..
|
||||
} if highlight.runtime_object_id().is_some() => OwnerOnly,
|
||||
Self::DomDebuggerConfigureEventListenerBreakpoint { .. }
|
||||
| Self::DomDebuggerConfigureXhrBreakpoint { .. }
|
||||
| Self::DomDebuggerConfigureDomBreakpoint { .. }
|
||||
@@ -168,9 +172,9 @@ impl RendererDevToolsPageCommand {
|
||||
| Self::DocumentFrontendNodeIdsForBackendNodeIds { .. }
|
||||
| Self::ChildFrameOwnerNodeReference { .. }
|
||||
| Self::ChildFrameDocumentRootNodeReference { .. }
|
||||
| Self::SetFetchSubresourceInterception { .. } => PageAgent,
|
||||
| Self::SetFetchSubresourceInterception { .. }
|
||||
| Self::SetOverlayHighlight { .. } => PageAgent,
|
||||
Self::WebMcp { .. }
|
||||
| Self::SetOverlayHighlight { .. }
|
||||
| Self::DispatchPreparedElementClick(..)
|
||||
| Self::DispatchMouseEventAtPoint { .. }
|
||||
| Self::DispatchTouchEvent { .. }
|
||||
|
||||
@@ -2537,7 +2537,7 @@ impl PageScriptHost {
|
||||
}
|
||||
|
||||
pub(crate) fn renderer_backend_node_id_for_live_handle(
|
||||
&mut self,
|
||||
&self,
|
||||
handle: DomHandle,
|
||||
) -> Option<u32> {
|
||||
let identity_handle = self.dom_host().document_identity_handle(handle)?;
|
||||
|
||||
@@ -481,6 +481,8 @@ use self::phase_one::PendingPhaseOneResidence;
|
||||
pub(in crate::runtime) use self::phase_one::{
|
||||
PhaseOneResidenceAdmission, PhaseOneRestoreRequirement,
|
||||
};
|
||||
#[cfg(feature = "devtools")]
|
||||
pub(crate) use self::protocol_output::NestedNativeInspectorRequest;
|
||||
pub(crate) use self::protocol_output::{PendingRendererOutputRecord, RendererTurnOutputJournal};
|
||||
#[cfg(feature = "devtools")]
|
||||
pub use self::protocol_output::{
|
||||
|
||||
@@ -140,7 +140,7 @@ pub enum RendererDevToolsPageCommand {
|
||||
},
|
||||
SetOverlayHighlight {
|
||||
inspector_session_id: Option<String>,
|
||||
highlight: Option<RendererOverlayHighlight>,
|
||||
highlight: Result<Option<RendererOverlayHighlight>, String>,
|
||||
},
|
||||
DocumentHitTest {
|
||||
inspector_session_id: Option<String>,
|
||||
|
||||
@@ -361,7 +361,10 @@ impl PageVm {
|
||||
)),
|
||||
),
|
||||
RendererDevToolsPageCommand::SetOverlayHighlight { inspector_session_id, highlight } => {
|
||||
self.set_overlay_highlight(inspector_session_id.as_deref(), highlight)?;
|
||||
self.set_overlay_highlight(
|
||||
inspector_session_id.as_deref(),
|
||||
highlight.map_err(anyhow::Error::msg)?,
|
||||
)?;
|
||||
Ok(RendererPageReply::Unit)
|
||||
}
|
||||
RendererDevToolsPageCommand::DocumentHitTest {
|
||||
|
||||
@@ -242,7 +242,9 @@ impl PageVm {
|
||||
RendererScreenshotPurpose::Screenshot => moli_action_window::ActionBarrier::Screenshot,
|
||||
RendererScreenshotPurpose::Print { .. } => moli_action_window::ActionBarrier::Explicit,
|
||||
};
|
||||
self.flush_page_action_window(barrier)?;
|
||||
if !self.vm().is_debugger_paused() {
|
||||
self.flush_page_action_window(barrier)?;
|
||||
}
|
||||
let paint_capture = request
|
||||
.paint_capture_request(self.document_settings.viewport_surface.unwrap_or_default())?;
|
||||
self.capture_image(
|
||||
@@ -292,7 +294,9 @@ impl PageVm {
|
||||
request: RendererCaptureScreencastFrameRequest,
|
||||
before_layout: impl FnOnce(),
|
||||
) -> anyhow::Result<RendererCaptureScreencastFrameReply> {
|
||||
self.flush_page_action_window(moli_action_window::ActionBarrier::Screencast)?;
|
||||
if !self.vm().is_debugger_paused() {
|
||||
self.flush_page_action_window(moli_action_window::ActionBarrier::Screencast)?;
|
||||
}
|
||||
if self.layout_configuration.policy == LayoutPolicy::Mock {
|
||||
return Ok(RendererCaptureScreencastFrameReply::LayoutDisabled);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,18 @@ pub enum RendererOverlayHighlight {
|
||||
},
|
||||
}
|
||||
|
||||
impl RendererOverlayHighlight {
|
||||
pub(crate) fn runtime_object_id(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::Node {
|
||||
target: RendererOverlayNode::RuntimeObject(object_id),
|
||||
..
|
||||
} => Some(object_id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(in crate::runtime) struct OverlayState {
|
||||
highlight: Option<(DevToolsSessionKey, RendererOverlayHighlight)>,
|
||||
|
||||
@@ -24,6 +24,8 @@ pub use item::{
|
||||
RendererProtocolObservation,
|
||||
};
|
||||
#[cfg(feature = "devtools")]
|
||||
pub(crate) use native_response::NestedNativeInspectorRequest;
|
||||
#[cfg(feature = "devtools")]
|
||||
pub use native_response::{
|
||||
RendererCdpCall, RendererNativeCommandAdmission, RendererNativeCommandReadyResponse,
|
||||
RendererNativeCommandResponseGuard, RendererNativeCommandTerminal, RendererNativeOperation,
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
//! metadata here. Internal queries continue to return their typed values to
|
||||
//! their continuation; they never acquire this frontend publication capability.
|
||||
|
||||
use crate::runtime::RendererDevToolsPageCommand;
|
||||
use crate::runtime::{
|
||||
RendererDevToolsPageCommand, RendererDomNodeReference, RendererOverlayHighlight,
|
||||
RendererOverlayNode,
|
||||
};
|
||||
use std::convert::Infallible;
|
||||
|
||||
use moli_page_types::{DevToolsSessionKey, FrontendCommandId, RendererAgentAttachmentId};
|
||||
@@ -240,16 +243,12 @@ impl RendererNativeOperation {
|
||||
+ Send
|
||||
+ 'static,
|
||||
) -> Self {
|
||||
let nested_dispatch = match &command {
|
||||
RendererPageCommand::DevTools(RendererDevToolsPageCommand::Inspector(envelope))
|
||||
if envelope.runtime_binding_removal_name().is_some() =>
|
||||
{
|
||||
RendererDevToolsMainNestedDispatch::NativeInspectorSession
|
||||
}
|
||||
_ if command.nested_dispatch() == RendererDevToolsMainNestedDispatch::PageAgent => {
|
||||
RendererDevToolsMainNestedDispatch::PageAgent
|
||||
}
|
||||
_ => RendererDevToolsMainNestedDispatch::OwnerOnly,
|
||||
let nested_dispatch = if NestedNativeInspectorRequest::for_command(&command).is_some() {
|
||||
RendererDevToolsMainNestedDispatch::NativeInspectorSession
|
||||
} else if command.nested_dispatch() == RendererDevToolsMainNestedDispatch::PageAgent {
|
||||
RendererDevToolsMainNestedDispatch::PageAgent
|
||||
} else {
|
||||
RendererDevToolsMainNestedDispatch::OwnerOnly
|
||||
};
|
||||
Self {
|
||||
nested_dispatch,
|
||||
@@ -313,16 +312,32 @@ enum NativeReadyReply {
|
||||
},
|
||||
}
|
||||
|
||||
pub(crate) enum NestedNativeInspectorRequest<'a> {
|
||||
RemoveRuntimeBinding(&'a str),
|
||||
ResolveOverlayNode(&'a str),
|
||||
}
|
||||
|
||||
impl<'a> NestedNativeInspectorRequest<'a> {
|
||||
fn for_command(command: &'a RendererPageCommand) -> Option<Self> {
|
||||
match command {
|
||||
RendererPageCommand::DevTools(RendererDevToolsPageCommand::Inspector(envelope)) => {
|
||||
envelope
|
||||
.runtime_binding_removal_name()
|
||||
.map(Self::RemoveRuntimeBinding)
|
||||
}
|
||||
RendererPageCommand::DevTools(RendererDevToolsPageCommand::SetOverlayHighlight {
|
||||
highlight: Ok(Some(highlight)),
|
||||
..
|
||||
}) => highlight.runtime_object_id().map(Self::ResolveOverlayNode),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RendererCdpCall {
|
||||
pub(crate) fn runtime_binding_removal_name(&self) -> &str {
|
||||
let RendererPageCommand::DevTools(RendererDevToolsPageCommand::Inspector(envelope)) =
|
||||
self.operation.command.as_ref()
|
||||
else {
|
||||
unreachable!("nested native Inspector dispatch requires an Inspector payload")
|
||||
};
|
||||
envelope
|
||||
.runtime_binding_removal_name()
|
||||
.expect("only removeBinding supports nested native Inspector dispatch")
|
||||
pub(crate) fn nested_inspector_request(&self) -> NestedNativeInspectorRequest<'_> {
|
||||
NestedNativeInspectorRequest::for_command(&self.operation.command)
|
||||
.expect("nested native Inspector dispatch requires a session request")
|
||||
}
|
||||
|
||||
pub(crate) fn into_runtime_binding_removal_commit(
|
||||
@@ -339,9 +354,35 @@ impl RendererCdpCall {
|
||||
envelope.into_runtime_binding_removal_commit(output),
|
||||
),
|
||||
));
|
||||
self.into_nested_page_commit()
|
||||
}
|
||||
|
||||
pub(crate) fn into_overlay_node_commit(
|
||||
mut self,
|
||||
result: Result<u32, String>,
|
||||
) -> RendererPageCommand {
|
||||
let RendererPageCommand::DevTools(RendererDevToolsPageCommand::SetOverlayHighlight {
|
||||
highlight,
|
||||
..
|
||||
}) = self.operation.command.as_mut()
|
||||
else {
|
||||
unreachable!("overlay resolution requires an overlay command")
|
||||
};
|
||||
match result {
|
||||
Ok(id) => {
|
||||
let Ok(Some(RendererOverlayHighlight::Node { target, .. })) = highlight else {
|
||||
unreachable!("overlay resolution requires a node highlight")
|
||||
};
|
||||
*target = RendererOverlayNode::Node(RendererDomNodeReference::BackendNodeId(id));
|
||||
}
|
||||
Err(error) => *highlight = Err(error),
|
||||
}
|
||||
self.into_nested_page_commit()
|
||||
}
|
||||
|
||||
fn into_nested_page_commit(mut self) -> RendererPageCommand {
|
||||
self.operation.nested_dispatch = RendererDevToolsMainNestedDispatch::PageAgent;
|
||||
// Keep the original response lease and terminal projection. Neither
|
||||
// the V8 response capture nor the adapter can publish another reply.
|
||||
// The native terminal retains its original response lease.
|
||||
RendererPageCommand::DevTools(RendererDevToolsPageCommand::Native(self))
|
||||
}
|
||||
|
||||
|
||||
@@ -1097,6 +1097,23 @@ pub(super) struct ScriptVmRendererDocumentIsolateOps<'a> {
|
||||
vm: &'a mut ScriptVm,
|
||||
}
|
||||
|
||||
#[cfg(feature = "devtools")]
|
||||
fn unwrap_live_inspector_node(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
session: &v8::inspector::V8InspectorSession,
|
||||
object_id: &str,
|
||||
) -> Option<(*mut PageScriptHost, DomHandle)> {
|
||||
let (value, context, _) = session
|
||||
.unwrap_object(scope, v8::inspector::StringView::from(object_id.as_bytes()))
|
||||
.ok()?;
|
||||
let expected_runtime = crate::util::context_host_ptr_from_context_slot(context)?;
|
||||
let object = v8::Local::<v8::Object>::try_from(value).ok()?;
|
||||
let scope = &mut v8::ContextScope::new(scope, context);
|
||||
let (runtime, handle) = node_runtime_and_handle_from_object(scope, object).ok()?;
|
||||
(runtime == expected_runtime && unsafe { &*runtime }.dom_host().node(handle).is_some())
|
||||
.then_some((runtime, handle))
|
||||
}
|
||||
|
||||
impl ScriptVm {
|
||||
pub(crate) fn page_window_identity(&self) -> crate::runtime::RendererPageWindowIdentity {
|
||||
self._context_host.borrow().window_identity().clone()
|
||||
@@ -1110,6 +1127,10 @@ impl ScriptVm {
|
||||
self.page_inspector.devtools_target()
|
||||
}
|
||||
|
||||
pub(crate) fn is_debugger_paused(&self) -> bool {
|
||||
self.devtools_target().pause_ref().is_pause_active()
|
||||
}
|
||||
|
||||
pub(super) fn set_root_document_lifecycle(
|
||||
&mut self,
|
||||
lifecycle: crate::runtime::RendererDocumentLifecycleJournalHandle,
|
||||
@@ -1321,27 +1342,9 @@ impl ScriptVm {
|
||||
inspector,
|
||||
PageInspectorSessionTarget::Frontend(inspector_session_id),
|
||||
|session, _, _| -> Result<Option<DomHandle>> {
|
||||
let Ok((value, context, _object_group)) = session.unwrap_object(
|
||||
scope,
|
||||
v8::inspector::StringView::from(object_id.as_bytes()),
|
||||
) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Ok(object) = v8::Local::<v8::Object>::try_from(value) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let scope = &mut v8::ContextScope::new(scope, context);
|
||||
let Ok((runtime_ptr, handle)) =
|
||||
node_runtime_and_handle_from_object(scope, object)
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
if runtime_ptr != expected_runtime_ptr
|
||||
|| unsafe { &*runtime_ptr }.dom_host().node(handle).is_none()
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(Some(handle))
|
||||
Ok(unwrap_live_inspector_node(scope, session, object_id)
|
||||
.filter(|(runtime, _)| *runtime == expected_runtime_ptr)
|
||||
.map(|(_, handle)| handle))
|
||||
},
|
||||
)
|
||||
},
|
||||
|
||||
@@ -31,13 +31,14 @@ use crate::inspector_session::InspectorSessionOutput;
|
||||
use crate::runtime::dispatch_nested_main_page_command;
|
||||
#[cfg(feature = "devtools")]
|
||||
use crate::runtime::{
|
||||
RendererDevToolsIoCommandKind, RendererDevToolsIoCommandPayload,
|
||||
RendererDevToolsMainNestedDispatch,
|
||||
NestedNativeInspectorRequest, RendererOwnerReply, RendererPageCommand,
|
||||
RendererRuntimeCommandOutput, RendererRuntimeInspectorMessage,
|
||||
RendererRuntimeInspectorResponseSender,
|
||||
};
|
||||
#[cfg(feature = "devtools")]
|
||||
use crate::runtime::{
|
||||
RendererOwnerReply, RendererPageCommand, RendererRuntimeCommandOutput,
|
||||
RendererRuntimeInspectorMessage, RendererRuntimeInspectorResponseSender,
|
||||
RendererDevToolsIoCommandKind, RendererDevToolsIoCommandPayload,
|
||||
RendererDevToolsMainNestedDispatch,
|
||||
};
|
||||
pub(crate) use interrupt::dispatch_inspector_io_owner_wake;
|
||||
#[cfg(feature = "devtools")]
|
||||
@@ -375,49 +376,85 @@ impl RendererInspectorSessionExecutorLocal {
|
||||
unreachable!("native Inspector dispatch must retain its native terminal")
|
||||
};
|
||||
first_dispatch.release();
|
||||
let output = (|| {
|
||||
const INTERNAL_REMOVE_BINDING_ID: i32 = 900_006;
|
||||
let session = session.ok_or("Inspector session is not available")?;
|
||||
let v8_session = session
|
||||
.session
|
||||
.upgrade()
|
||||
.ok_or("Inspector session has been detached")?;
|
||||
let raw_json = json!({
|
||||
"id": INTERNAL_REMOVE_BINDING_ID,
|
||||
"method": "Runtime.removeBinding",
|
||||
"params": {"name": call.runtime_binding_removal_name()},
|
||||
})
|
||||
.to_string();
|
||||
// Enter the already live V8 Inspector session, just like ordinary
|
||||
// nested protocol dispatch. Do not borrow the suspended Page's
|
||||
// isolate or report this V8 handler as a native Page agent.
|
||||
let response = session
|
||||
.outbound
|
||||
.capture_internal_response(INTERNAL_REMOVE_BINDING_ID, || {
|
||||
v8_session.dispatch_protocol_message(v8::inspector::StringView::from(
|
||||
raw_json.as_bytes(),
|
||||
));
|
||||
})
|
||||
.ok_or("Runtime binding command did not complete")?;
|
||||
let messages = if response.get("error").is_some() {
|
||||
vec![RendererRuntimeInspectorMessage::protocol(response)]
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
let mut output = RendererRuntimeCommandOutput::from_messages(messages);
|
||||
output.set_v8_state_update(V8InspectorSessionState::from_bytes(v8_session.state()));
|
||||
Ok(output)
|
||||
})()
|
||||
.map_err(str::to_owned);
|
||||
// Only the remaining Rust metadata mutation uses the Page-agent
|
||||
// boundary. Its original NativeTerminal still commits state and the
|
||||
// single frontend response through ordered journal ingress.
|
||||
let command = call.into_runtime_binding_removal_commit(output);
|
||||
let session = session
|
||||
.as_ref()
|
||||
.ok_or("Inspector session is not available")
|
||||
.and_then(|route| {
|
||||
route
|
||||
.session
|
||||
.upgrade()
|
||||
.map(|session| (route, session))
|
||||
.ok_or("Inspector session has been detached")
|
||||
});
|
||||
let command = match call.nested_inspector_request() {
|
||||
NestedNativeInspectorRequest::RemoveRuntimeBinding(name) => {
|
||||
let output = session
|
||||
.and_then(|(route, v8_session)| {
|
||||
const INTERNAL_REMOVE_BINDING_ID: i32 = 900_006;
|
||||
let raw_json = json!({
|
||||
"id": INTERNAL_REMOVE_BINDING_ID,
|
||||
"method": "Runtime.removeBinding",
|
||||
"params": {"name": name},
|
||||
})
|
||||
.to_string();
|
||||
let response = route
|
||||
.outbound
|
||||
.capture_internal_response(INTERNAL_REMOVE_BINDING_ID, || {
|
||||
v8_session.dispatch_protocol_message(
|
||||
v8::inspector::StringView::from(raw_json.as_bytes()),
|
||||
)
|
||||
})
|
||||
.ok_or("Runtime binding command did not complete")?;
|
||||
let messages = if response.get("error").is_some() {
|
||||
vec![RendererRuntimeInspectorMessage::protocol(response)]
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
let mut output = RendererRuntimeCommandOutput::from_messages(messages);
|
||||
output.set_v8_state_update(V8InspectorSessionState::from_bytes(
|
||||
v8_session.state(),
|
||||
));
|
||||
Ok(output)
|
||||
})
|
||||
.map_err(str::to_owned);
|
||||
call.into_runtime_binding_removal_commit(output)
|
||||
}
|
||||
NestedNativeInspectorRequest::ResolveOverlayNode(object_id) => {
|
||||
let node = session
|
||||
.and_then(|(_, v8_session)| {
|
||||
self.overlay_node_for_runtime_object(&v8_session, object_id)
|
||||
.ok_or("Could not find node with given id")
|
||||
})
|
||||
.map_err(str::to_owned);
|
||||
call.into_overlay_node_commit(node)
|
||||
}
|
||||
};
|
||||
// The Inspector stage uses the live session. Only the resolved command
|
||||
// and its original terminal cross back to the native Page agent.
|
||||
let result = dispatch_nested_main_page_command(command, first_dispatch)
|
||||
.map(|output| RendererOwnerReply::AsyncPageCommandRan(Box::new(output)));
|
||||
let _ = reply_tx.send(result);
|
||||
}
|
||||
|
||||
#[cfg(feature = "devtools")]
|
||||
fn overlay_node_for_runtime_object(
|
||||
&self,
|
||||
session: &v8::inspector::V8InspectorSession,
|
||||
object_id: &str,
|
||||
) -> Option<u32> {
|
||||
// The pause callback already runs inside this isolate on its owner thread.
|
||||
let isolate =
|
||||
unsafe { v8::Isolate::ref_from_raw_isolate_ptr_mut(&mut *self.isolate.get()) };
|
||||
let scope = std::pin::pin!(v8::HandleScope::new(isolate));
|
||||
let scope = &mut scope.init();
|
||||
let context = v8::Global::new(&*scope, scope.try_get_entered_or_microtask_context()?);
|
||||
let context = v8::Local::new(scope, &context);
|
||||
let scope = &mut v8::ContextScope::new(scope, context);
|
||||
let (runtime, handle) =
|
||||
super::super::unwrap_live_inspector_node(scope, session, object_id)?;
|
||||
unsafe { &*runtime }.renderer_backend_node_id_for_live_handle(handle)
|
||||
}
|
||||
|
||||
#[cfg(feature = "devtools")]
|
||||
fn dispatch_next_io_command_from_interrupt(&self) {
|
||||
let Some(command) = self.target.io_ref().claim_for_interrupt() else {
|
||||
|
||||
@@ -322,7 +322,8 @@ impl ScriptVm {
|
||||
}
|
||||
// Font resources are reconciled by the document resource lifecycle.
|
||||
// Layout consumes registered data and performs no font loading work.
|
||||
let requests_paint = request.requests_paint();
|
||||
let paused = self.is_debugger_paused();
|
||||
let discovers_css_images = request.requests_paint() && !paused;
|
||||
let (document, publishes_layout, result) = {
|
||||
let context_host = self._context_host.borrow();
|
||||
let document = context_host.document_handle();
|
||||
@@ -348,7 +349,7 @@ impl ScriptVm {
|
||||
let Some(mut pass) = pass else {
|
||||
return Ok(None);
|
||||
};
|
||||
let css_images = match (requests_paint, request.includes_backgrounds()) {
|
||||
let css_images = match (discovers_css_images, request.includes_backgrounds()) {
|
||||
(false, _) => Vec::new(),
|
||||
(true, true) => pass.css_image_references().to_vec(),
|
||||
(true, false) => pass
|
||||
@@ -371,6 +372,11 @@ impl ScriptVm {
|
||||
Ok(None) => (Ok(None), Vec::new()),
|
||||
Err(error) => (Err(error), Vec::new()),
|
||||
};
|
||||
// Nested Page-agent reads can paint while the owner is suspended in
|
||||
// V8. Resource admission and observer delivery belong to regular turns.
|
||||
if paused {
|
||||
return result;
|
||||
}
|
||||
self.start_css_images_discovered_by_layout(css_images);
|
||||
if publishes_layout
|
||||
&& matches!(&result, Ok(Some(_)))
|
||||
|
||||
Reference in New Issue
Block a user