Bug 197091 - Web Inspector: REGRESSION: Elements: "Inspect Element" context menu often doesn't select that element
Summary: Web Inspector: REGRESSION: Elements: "Inspect Element" context menu often doe...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-04-18 22:08 PDT by Devin Rousso
Modified: 2019-04-19 17:30 PDT (History)
6 users (show)

See Also:


Attachments
Patch (2.47 KB, patch)
2019-04-18 22:16 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (3.24 KB, patch)
2019-04-19 08:50 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2019-04-18 22:08:16 PDT
# STEPS TO REPRODUCE:
1. go to any large-ish page
2. right click on a nested/specific element (e.g. not the background or the <body>)
 => inspector opens, sometimes on the Elements tab with a different node selected and sometimes not even on the Elements tab
Comment 1 Devin Rousso 2019-04-18 22:08:25 PDT
<rdar://problem/49953728>
Comment 2 Devin Rousso 2019-04-18 22:16:55 PDT
Created attachment 367786 [details]
Patch
Comment 3 Joseph Pecoraro 2019-04-18 23:03:06 PDT
Comment on attachment 367786 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=367786&action=review

> Source/WebCore/ChangeLog:9
> +        Delay the `inspect` event fron firing with the focued node until the frontend has had a

Typo: "fron"

> Source/WebCore/ChangeLog:11
> +        node-to-id, so the focused node's id would no longer be valid.

Interesting, so why is this happening now? Is it related to lazy initialization!?

> Source/WebCore/inspector/agents/InspectorDOMAgent.cpp:509
> +        if (m_nodeToFocus->document().page() == &m_inspectedPage)

This check feels like it came after some kind of experimentation. It might deserve a comment since it is very non-obvious.

Should we have cleared `m_nodeToFocus` when the page changed?

The reason I ask is that `m_nodeToFocus` is a `RefPtr<Node>`, so if it is non-null it is holding a node which in turn is keeping that entire node's Document and Page alive. If that page is not the inspected page, then it sounds like Web Inspector might somehow be keeping an entire page alive.
Comment 4 Devin Rousso 2019-04-19 08:28:40 PDT
Comment on attachment 367786 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=367786&action=review

>> Source/WebCore/ChangeLog:11
>> +        node-to-id, so the focused node's id would no longer be valid.
> 
> Interesting, so why is this happening now? Is it related to lazy initialization!?

That's my guess, but I'm not entirely sure why 🤔

>> Source/WebCore/inspector/agents/InspectorDOMAgent.cpp:509
>> +        if (m_nodeToFocus->document().page() == &m_inspectedPage)
> 
> This check feels like it came after some kind of experimentation. It might deserve a comment since it is very non-obvious.
> 
> Should we have cleared `m_nodeToFocus` when the page changed?
> 
> The reason I ask is that `m_nodeToFocus` is a `RefPtr<Node>`, so if it is non-null it is holding a node which in turn is keeping that entire node's Document and Page alive. If that page is not the inspected page, then it sounds like Web Inspector might somehow be keeping an entire page alive.

I think I had this backwards in my mind.  We should be clearing `m_nodeToFocus` if the owner frame becomes detached from the main frame (or the owner is the main frame and it's about to navigate/deallocate).  This check can then be removed.
Comment 5 Devin Rousso 2019-04-19 08:50:05 PDT
Created attachment 367801 [details]
Patch

This could be designed much better, but I think it would be better to tackle that in <https://webkit.org/b/197025>.
Comment 6 Joseph Pecoraro 2019-04-19 16:34:05 PDT
Comment on attachment 367801 [details]
Patch

r=me! Nice, I like this much better.
Comment 7 WebKit Commit Bot 2019-04-19 17:30:40 PDT
Comment on attachment 367801 [details]
Patch

Clearing flags on attachment: 367801

Committed r244476: <https://trac.webkit.org/changeset/244476>
Comment 8 WebKit Commit Bot 2019-04-19 17:30:42 PDT
All reviewed patches have been landed.  Closing bug.