From 4d7a0d386340cc403390075c05532ada37bdbf6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=BClker?= Date: Sat, 9 Aug 2025 20:12:20 +0200 Subject: [PATCH] script: Tell devtools whether a node is displayed or not (#38575) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Doing so makes the devtools inspector display the nodes in gray, as it is the case in firefox. The relevant node parameter already exists but is hardcoded. Before: image After: image Testing: We don't have tests for the devtools inspector. Signed-off-by: Simon Wülker --- components/devtools/actors/inspector.rs | 9 ++------- components/devtools/actors/inspector/node.rs | 10 +++++----- components/devtools/actors/inspector/walker.rs | 4 +--- components/script/dom/node.rs | 4 ++++ components/shared/devtools/lib.rs | 4 ++++ 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/components/devtools/actors/inspector.rs b/components/devtools/actors/inspector.rs index 087e6c630ca..a65ae4faa5a 100644 --- a/components/devtools/actors/inspector.rs +++ b/components/devtools/actors/inspector.rs @@ -92,13 +92,8 @@ impl Actor for InspectorActor { .clone() .unwrap_or_else(|| registry.new_name("walker")); - let root = root_info.encode( - registry, - false, - self.script_chan.clone(), - pipeline, - name.clone(), - ); + let root = + root_info.encode(registry, self.script_chan.clone(), pipeline, name.clone()); if self.walker.borrow().is_none() { let walker = WalkerActor { diff --git a/components/devtools/actors/inspector/node.rs b/components/devtools/actors/inspector/node.rs index 0ef3221ebc8..41d5447bfd0 100644 --- a/components/devtools/actors/inspector/node.rs +++ b/components/devtools/actors/inspector/node.rs @@ -59,6 +59,9 @@ pub struct NodeActorMsg { is_anonymous: bool, is_before_pseudo_element: bool, is_direct_shadow_host_child: Option, + /// Whether or not this node is displayed. + /// + /// Setting this value to `false` will cause the devtools to render the node name in gray. is_displayed: bool, #[serde(rename = "isInHTMLDocument")] is_in_html_document: Option, @@ -158,7 +161,6 @@ impl Actor for NodeActor { .ok_or(ActorError::Internal)?; let node = doc_elem_info.encode( registry, - true, self.script_chan.clone(), self.pipeline, self.walker.clone(), @@ -181,7 +183,6 @@ pub trait NodeInfoToProtocol { fn encode( self, actors: &ActorRegistry, - display: bool, script_chan: IpcSender, pipeline: PipelineId, walker: String, @@ -192,7 +193,6 @@ impl NodeInfoToProtocol for NodeInfo { fn encode( self, actors: &ActorRegistry, - display: bool, script_chan: IpcSender, pipeline: PipelineId, walker: String, @@ -239,7 +239,7 @@ impl NodeInfoToProtocol for NodeInfo { let mut children = rx.recv().ok()??; let child = children.pop()?; - let msg = child.encode(actors, true, script_chan.clone(), pipeline, walker); + let msg = child.encode(actors, script_chan.clone(), pipeline, walker); // If the node child is not a text node, do not represent it inline. if msg.node_type != TEXT_NODE { @@ -267,7 +267,7 @@ impl NodeInfoToProtocol for NodeInfo { is_anonymous: false, is_before_pseudo_element: false, is_direct_shadow_host_child: None, - is_displayed: display, + is_displayed: self.is_displayed, is_in_html_document: Some(true), is_marker_pseudo_element: false, is_native_anonymous: false, diff --git a/components/devtools/actors/inspector/walker.rs b/components/devtools/actors/inspector/walker.rs index 7b551a1dbdd..06ce25b9fec 100644 --- a/components/devtools/actors/inspector/walker.rs +++ b/components/devtools/actors/inspector/walker.rs @@ -156,7 +156,6 @@ impl Actor for WalkerActor { .map(|child| { child.encode( registry, - true, self.script_chan.clone(), self.pipeline, self.name(), @@ -182,7 +181,6 @@ impl Actor for WalkerActor { .ok_or(ActorError::Internal)?; let node = doc_elem_info.encode( registry, - true, self.script_chan.clone(), self.pipeline, self.name(), @@ -319,7 +317,7 @@ pub fn find_child( let children = rx.recv().unwrap().ok_or(vec![])?; for child in children { - let msg = child.encode(registry, true, script_chan.clone(), pipeline, name.into()); + let msg = child.encode(registry, script_chan.clone(), pipeline, name.into()); if compare_fn(&msg) { hierarchy.push(msg); return Ok(hierarchy); diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 0b291618b19..48ad31d3831 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1320,6 +1320,10 @@ impl Node { is_shadow_host, shadow_root_mode, display, + // It is not entirely clear when this should be set to false. + // Firefox considers nodes with "display: contents" to be displayed. + // The doctype node is displayed despite being `display: none`. + is_displayed: !self.is_display_none() || self.is::(), doctype_name: self .downcast::() .map(DocumentType::name) diff --git a/components/shared/devtools/lib.rs b/components/shared/devtools/lib.rs index 3a044a8f4ae..8934b43f3f7 100644 --- a/components/shared/devtools/lib.rs +++ b/components/shared/devtools/lib.rs @@ -149,6 +149,10 @@ pub struct NodeInfo { pub shadow_root_mode: Option, pub is_shadow_host: bool, pub display: Option, + /// Whether this node is currently displayed. + /// + /// For example, the node might have `display: none`. + pub is_displayed: bool, /// The `DOCTYPE` name if this is a `DocumentType` node, `None` otherwise pub doctype_name: Option,