GoogleChrome / GoogleChrome/lighthouse
DevTools: node revealing is flaky
- Dominant language
- JavaScript
- Stars
- 30.8k
- Forks
- 9.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 19
Description
First a little primer on how this system works:
#### On the Lighthouse side:
* we collect a selector path, an outerHTML snippet, we generate the proprietary node path.
* we set all that on data attributes on the element for safekeeping.
#### [On the devtools side](https://github.com/ChromeDevTools/devtools-frontend/blob/8dd291f42b57c4d74fd637dbaed00e544a85606c/front_end/audits2/Audits2Panel.js#L675-L710):
1. we let Lighthouse make that renderNode element
2. lighthouse is currently reloading the page to clean things up so we need to wait for that to finish.
3. we wait for `SDK.ResourceTreeModel.Events.MainFrameNavigated` to fire once before proceeding
4. once that's done we use the `domModel.pushNodeByPathToFrontend` method to push our fancy node path to the backend and have it return a current nodeID.
1. sometimes it doesnt return any results. sometimes it does return a node, but the `nodeForId` lookup fails because the domModel isn't populated yet. one of these can happen if the node hasn't been inserted into the DOM yet. (something rather lazy).
1. if we have a working nodeID we give it to `linkifyNodeReference` which hooks up the blue highlight and click
#### notes
1. I've noticed `linkifyNodeReference` being passed nodeIds that appear to be slightly "deprecated" nodeIds for a given element. As in.. the click-to-reveal will work, but the hover will not give a blue highlight. And if you get the current nodeid of the element, it's soemthing like `243` rather than `78`.
1. there seems to be some other reasons the transition from nodePath to nodeId fail. A) race conditions with reload B) race conditions with the DOM updating and dom model being build/rebuilt. C) something about the DOM structure trips up this resolving phase.
@robdodson wrestled with this a bit tonight which has unearthed some things..
On that last point (2/C), rob noticed that on his test page, having "Any script at the end of body" will make it fail. If there are no scripts, the whole thing works.
Also if the script is in the head and async, things work.
Why a script at the end could affect this nodePath doesn't really add up.
But that's where things are at the moment!
Contributor guide
Assessment
This issue has not been assessed yet.