diff options
author | MacDue <macdue@dueutil.tech> | 2022-07-03 16:56:26 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-03 20:45:11 +0200 |
commit | 95e6e3be74b80d93a01430de5ed790c2cfe37e04 (patch) | |
tree | 9b5720262c925753337b6918315c5ee11d00c580 /Userland/Applications | |
parent | 445c3050d44dcf355cc868708f4c74bd33ce5607 (diff) | |
download | serenity-95e6e3be74b80d93a01430de5ed790c2cfe37e04.zip |
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.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/Browser/InspectorWidget.cpp | 15 | ||||
-rw-r--r-- | Userland/Applications/Browser/InspectorWidget.h | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Applications/Browser/InspectorWidget.cpp b/Userland/Applications/Browser/InspectorWidget.cpp index 0779097600..5142f171d8 100644 --- a/Userland/Applications/Browser/InspectorWidget.cpp +++ b/Userland/Applications/Browser/InspectorWidget.cpp @@ -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(); diff --git a/Userland/Applications/Browser/InspectorWidget.h b/Userland/Applications/Browser/InspectorWidget.h index 4ea84703b7..bff3d1ed30 100644 --- a/Userland/Applications/Browser/InspectorWidget.h +++ b/Userland/Applications/Browser/InspectorWidget.h @@ -54,6 +54,7 @@ private: void load_style_json(String specified_values_json, String computed_values_json, String custom_properties_json); void update_node_box_model(Optional<String> node_box_sizing_json); void clear_style_json(); + void clear_node_box_model(); RefPtr<WebView::OutOfProcessWebView> m_web_view; |