Skip to content

Commit

Permalink
Browser+WebContent: Fix inspecting non-visible nodes
Browse files Browse the repository at this point in the history
I already fixed the crash from this in #14470, but didn't fully fix
the issue. Currently the browser just avoids sending the
inspect_dom_node() IPC call for non-visible nodes.

The main problem with this is it means the browser keeps displaying
the overlay for the previously selected node. This commit fixes
the crash in the WebContent side, so the IPC call can still be made
and the selection correctly updated.
  • Loading branch information
MacDue authored and linusg committed Jul 5, 2022
1 parent 753844e commit 3294753
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
8 changes: 1 addition & 7 deletions Userland/Applications/Browser/InspectorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,14 @@ void InspectorWidget::set_selection(GUI::ModelIndex const index)
return;
m_selection = move(selection);

// Note: Non-visible nodes don't have style data and such, and will hit assertions if inspection is attempted.
if (!json->get("visible").to_bool(true)) {
clear_style_json();
clear_node_box_model();
return;
}

auto maybe_inspected_node_properties = m_web_view->inspect_dom_node(m_selection.dom_node_id, m_selection.pseudo_element);
if (maybe_inspected_node_properties.has_value()) {
auto inspected_node_properties = maybe_inspected_node_properties.value();
load_style_json(inspected_node_properties.specified_values_json, inspected_node_properties.computed_values_json, inspected_node_properties.custom_properties_json);
update_node_box_model(inspected_node_properties.node_box_sizing_json);
} else {
clear_style_json();
clear_node_box_model();
}
}

Expand Down
3 changes: 2 additions & 1 deletion Userland/Services/WebContent/ConnectionFromClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect
});

Web::DOM::Node* node = Web::DOM::Node::from_id(node_id);
if (!node) {
// Note: Nodes without layout (aka non-visible nodes, don't have style computed)
if (!node || !node->layout_node()) {
return { false, "", "", "", "" };
}

Expand Down

0 comments on commit 3294753

Please sign in to comment.