Skip to content

Truly independent web browser

LibWeb: Resolve a DevTools hit test on text to its element

sideshowbarker8b6221340a32
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp
index f5404ee9258..2b2779df35a 100644
--- a/Libraries/LibWeb/Page/Page.cpp
+++ b/Libraries/LibWeb/Page/Page.cpp
@@ -525,7 +525,11 @@ bool Page::select_word_for_dictionary_lookup(DevicePixelPoint position)
UniqueNodeID Page::node_id_at_position(DevicePixelPoint position)
{
- auto node = local_traversable()->event_handler().target_node_for_mouse_position(device_to_css_point(position));
+ // DevTools selects only elements, and its DOM tree leaves out whitespace-only text, so a hit on text resolves to
+ // the element around it here.
+ GC::Ptr<DOM::Node> node = local_traversable()->event_handler().target_node_for_mouse_position(device_to_css_point(position));
+ while (node && !is<DOM::Element>(*node))
+ node = node->parent_or_shadow_host();
if (!node)
return 0;