1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

Browser: Fix crash if clicking on non-visible nodes in the inspector

If you attempt to inspect a non-visible dom node it will hit
various assertions as things like style have not been computed.

With this change attempting to inspect these nodes will simply
clear the style and box model tabs.
This commit is contained in:
MacDue 2022-07-03 16:56:26 +01:00 committed by Linus Groh
parent 445c3050d4
commit 95e6e3be74
2 changed files with 16 additions and 0 deletions

View file

@ -61,6 +61,13 @@ 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();
@ -203,6 +210,14 @@ void InspectorWidget::update_node_box_model(Optional<String> node_box_sizing_jso
m_element_size_view->set_box_model(m_node_box_sizing);
}
void InspectorWidget::clear_node_box_model()
{
m_node_box_sizing = Web::Layout::BoxModelMetrics {};
m_element_size_view->set_node_content_width(0);
m_element_size_view->set_node_content_height(0);
m_element_size_view->set_box_model(m_node_box_sizing);
}
void InspectorWidget::clear_style_json()
{
m_selection_specified_values_json.clear();