Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevTools: node revealing is flaky #2289

Open
paulirish opened this issue May 17, 2017 · 37 comments
Open

DevTools: node revealing is flaky #2289

paulirish opened this issue May 17, 2017 · 37 comments

Comments

@paulirish
Copy link
Member

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:

  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.
  5. 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).
  6. 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.
  2. 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!

@kaycebasques
Copy link
Contributor

Can repro on theverge.com

screen shot 2017-06-28 at 2 45 31 pm

@carmacleod
Copy link

Same problem here: http://www.carbondesignsystem.com/
Yes, there are scripts at end of body.

@carmacleod
Copy link

  1. lighthouse is currently reloading the page to clean things up so we need to wait for that to finish.

This is problematic for an accessibility audit, because you want to be able to drop down menus, open dialogs, etc and then rerun the audit to see if there are errors in those components.

@carmacleod
Copy link

Any chance element linking will be in Chrome 65? I am planning to demo the new devtools Accessibility Tree and Color Picker to about 50 people on March 14. A natural segue would be to demo a lighthouse accessibility audit, but if element linking is still broken, then I will leave that part of the demo out. (because without element linking it feels like a step backwards from the previous accessibility devtools, which I have demoed before).

@paulirish
Copy link
Member Author

Hi Carolyn, thanks for the detail on this issue. We'll work on this bug soon.

It won't be fixed in Chrome 65 or 66. I'm sorry for the delay.

@carmacleod
Copy link

Ok. Thanks for the time frame info. Much appreciated.

@robdodson
Copy link
Contributor

I think/hope I was able to land a fix for this here https://chromium-review.googlesource.com/c/chromium/src/+/1006116

@carmacleod
Copy link

Woo-hoo, @robdodson ! When can I try it? :)

@robdodson
Copy link
Contributor

@paulirish can correct me but I think it usually takes about a day for something to make it into Canary.

@paulirish
Copy link
Member Author

paulirish commented Apr 12, 2018 via email

@carmacleod
Copy link

Very sorry, but this still doesn't work for me.
I can't reopen this issue - please let me know if you want me to open a new one.

Version 68.0.3397.0 (Official Build) canary (64-bit)

  • Tried it in my own product first, but I couldn't reveal the failing element:

image

  • So then I tried it on a google search page, and it works ok, i.e. I can click on failing elements to reveal them in the elements panel (can't focus failed elements, but click is a start).

image

  • So I tried it on the Wikipedia main page, and it doesn't work there either, i.e. I cannot reveal a failed element by clicking, right-clicking, or attempting to focus.

image

The only difference that I can see is the number of attributes (if there's only id, it works), and the color (clickable ones are purple. ;)

@robdodson
Copy link
Contributor

I think this does work but there's a quirk which I discussed with the team before.

Lighthouse has a dropdown that lets you switch between auditing the page with mobile emulation on or off.

screen shot 2018-04-16 at 1 17 40 pm

If you're viewing a desktop site, and you set this dropdown to 'desktop', then I think it should work.

Similarly, if you are viewing the site with mobile emulation turned on, and you set the dropdown to 'mobile', I think it will also work.

screen shot 2018-04-16 at 1 19 56 pm

But, by default, Lighthouse is set to audit on 'mobile' while you are viewing the site in desktop mode. This may mean (depending on how the site is built) that the structure of the DOM is different between those two states. As a result, the node path doesn't match what is currently in the devtools.

Personally I would prefer if Lighthouse did not have this dropdown, and instead audited the page based on whatever mode I was currently viewing it in. I.e. if I have mobile emulation enabled, it does a mobile audit. And if I am in desktop, it does a desktop audit. I realize the reason it doesn't work this way is because we really want to encourage folks to think about their slow-connection mobile web experience—but the side effect is the issue we're encountering here.

@robdodson
Copy link
Contributor

Sorry I forgot to mention, I was able to confirm this bug (and the fix) using Canary and wikipedia. If the audit is on 'mobile' but I'm viewing desktop, I get a non-selectable node path. But if both the audit and my view match, then the path seems to work.

@patrickhulce
Copy link
Collaborator

We might want to explore a different visual treatment of elements we can't find. I'm sure we'll never be able to solve all the cases of finding the proper element to highlight, especially given the emulation situation @robdodson described. Grayed out or some other treatment to reflect that it doesn't seem to be there anymore might be nice.

@robdodson
Copy link
Contributor

@patrickhulce Since the current default setup in Lighthouse almost guarantees that these paths will be broken I'd like to include an instruction of some kind to explain that to the user.

@carmacleod
Copy link

OOOOOHHHHH. Got it. Sorry for the noob-swirl, but @robdodson is correct - this is not intuitive.

For my part, I thought it was odd that Lighthouse seemed to be doing a mobile audit for my desktop app, but I figured it was probably to make sure it caught performance issues. I unchecked all but accessibility audit, and found it even odder that it was still focusing on mobile when I wasn't even doing a performance audit, but I figured "whatever", and moved on. Didn't guess that it meant that the node paths would be broken.

Suggestion:

  • Put the Lighthouse emulation switch with the "Audits to perform" checkboxes.
    This gives you a one-line place to say something like: "Does this page do well on mobile (recommended)".
  • Detect whether there's an emulation mode mismatch, and warn the user that node paths (i.e. reveal in elements panel) may only work in matching mode.

FWIW, having the audit settings in 2 places is potentially confusing, resulting in questions (these are just examples; I don't need answers) like: Why are the emulation, throttling and storage settings special? Do they apply to every type of audit? Does Lighthouse throttle an Accessibility audit? For accessibility, I don't want storage cleared, and I don't even want the page refreshed - can I make the UI stay in the state I put it in before the audit?

Perhaps if the settings were all together in one place, they could be more intuitively arranged. For example, emulation and storage settings, followed by audits to perform, with the throttling setting under the performance audit checkbox.

@patrickhulce
Copy link
Collaborator

cc @paulirish on setting placement ideas :)

@carmacleod
Copy link

Having re-read @robdodson's comment, above, I realize that I vastly prefer his solution, which is:

if I have mobile emulation enabled, it does a mobile audit. And if I am in desktop, it does a desktop audit.

i.e. remove the Lighthouse emulation switch entirely.

If you want to encourage folks to test and improve their slow-connection mobile web experience, add a "Note" below the Lighthouse image, something like (disclaimer: I'm not a designer...):

image

That way, there's no magic. Everything is out in the open.

@carmacleod
Copy link

Really, really sorry, but the original issue is still a problem for me, even in Desktop mode with Lighthouse Desktop emulation.

The Wikipedia page shows the issue fairly well because it has 2 similar, but not identical, failures for invalid lang:

  1. The span element in the page footer works (reveal, hover both work as expected):
<a class="external text" href="https://simple.wikipedia.org/wiki/">
   <span class="autonym" title="Simple English (simple:)" lang="simple" xml:lang="simple">
         English (simple form)
   </span>
</a>

image

  1. The anchor element in the page sidebar does not work (no reveal, no hover, nothing):
<a href="https://simple.wikipedia.org/wiki/" title="Simple English" lang="simple" hreflang="simple"
   class="interlanguage-link-target">
      Simple English
</a>

image

In case it's helpful, the element in my code that is failing is:

<div class="split splitLayout" style="left: 327.25px; position: absolute; right: auto; visibility: visible;"
   role="separator" aria-valuenow="25" aria-orientation="vertical">
   ...
</div>

(which shouldn't be failing, because aria-valuenow and aria-orientation are both valid attributes for separator role in ARIA 1.1... but that's a different issue :)

@robdodson
Copy link
Contributor

I'll have to look more at the Wikipedia issue. It may be that they are populating that list after the browser fires its load event. If so, we may need to wait a bit longer before trying to build the node path.

Regarding your site, it looks like aria-valuemin and aria-valuemax are also required attributes on role=separator. What's the error that Lighthouse is reporting for you?

@robdodson robdodson reopened this Apr 17, 2018
@carmacleod
Copy link

It may be that they are populating that list after the browser fires its load event. If so, we may need to wait a bit longer before trying to build the node path.

Maybe. I know our stuff can take a horribly long time. If that's the problem, then it would be best for our case if Lighthouse had a "don't refresh" option, so I could press "Start" whenever I'm ready. :)

What's the error that Lighthouse is reporting for you?

[aria-*] attributes do not match their roles.
(the full text is in the first screen snap in this comment, above)

it looks like aria-valuemin and aria-valuemax are also required attributes on role=separator.

I think (?) they should be ok, because their values are 0 and 100, and the ARIA 1.1 spec for separator says:

Authors SHOULD also provide the value of aria-valuemin if it is not 0 and the value of aria-valuemax if it is not 100.

@robdodson
Copy link
Contributor

@carmacleod do you have the axe extension installed? Under the hood that's what we're using to come up with these errors.

@robdodson
Copy link
Contributor

sorry, i meant to add, can you test with axe to see if it also gives you that error?

@carmacleod
Copy link

Good idea. So, the aXe extension has a lot more info (and a working reveal ;) plus it found a lot more violations (probably because our page is only a skeleton on refresh until it populates. Lighthouse does that unwanted initial refresh, but aXe just runs on the current page content).

Here's the Chrome A11y Audit:
image

Here's the aXe audit:
image

Since aXe has a more detailed error message, I was able to check the aXe issues and see that the reason they are flagging it is because there's no screen reader support yet.

@bethwhitmer
Copy link

I'm still having this issue in Lighthouse 3.0.0-beta.0 in Chrome Version 68.0.3440.106 (Official Build) (64-bit). I've tested several public pages over the last few days in preparation for some training I'll be doing and haven't found any Failing Elements that contain a selectable node path. :( That was so nice in prior versions of Lighthouse! I know that I could tell my colleagues to download axe for the "Inspect Node" feature but the goal of the training was to show "what accessibility testing you can do in Chrome without downloading a single thing."

Some of the sites I tested include:
www.worldmarket.com
www.ikea.com
www.potterybarn.com

I ran all of my tests on a desktop machine with Device set to "Desktop".

@robdodson
Copy link
Contributor

Hm, yeah it seems to have cropped up again...

@paulirish any idea on a longer duration event we could wait on?

@mattzeunert
Copy link
Contributor

DevTools is passing its own category renderer into the ReportRenderer, but that constructor parameter was removed. I stepped through the Chrome Stable audit panel rendering code and and the DevTools-specific rendering logic never runs.

@paulirish
Copy link
Member Author

paulirish commented Oct 25, 2018

youch. nice find @mattzeunert.

@hoten let's get you set up to fix this one (specifically the egregious bug Matt points out) and roll to DevTools.

@connorjclark connorjclark self-assigned this Oct 25, 2018
@connorjclark
Copy link
Collaborator

connorjclark commented Dec 12, 2018

Pushed some changes, now In Chrome Canary. If a node has the same node path (of the form 1,HTML,1,BODY,10,DIV,0,IFRAME, "index,node name" pairs), then the node link should work.

On the examples in this thread and on cnn.com, all nodes without links that I examined were because of a different DOM shape between loads (expected for complex sites).

Besides changing how we reload the page (or rather, instead of not reloading the page), we could have a secondary identifier that we use only in the case that the node path fails. For example, we could find the first parent node with a unique id, and then build the node path out from that. That would resolve cases (most? but not all) where an additional element was placed somewhere in the path, but it would obviously do nothing for the cases where the element simply doesn't exist on the new page load.

@mattzeunert
Copy link
Contributor

Should this work in Canary now? For me the code after await resourceTreeModel.once(SDK.ResourceTreeModel.Events.Load); never runs.

@connorjclark
Copy link
Collaborator

@mattzeunert Can you confirm if any node links work in the report for cnn.com?

image

At the very least, I see a functioning link for a#logo.nav__logo on cnn.com every time (although i notice it takes a second to convert into a link). Others are random due to the nature of cnn.com and my previous comment.

It is possible that the load event doesn't always fire after the report is generated. i can't seem to replicate it though.

@mattzeunert
Copy link
Contributor

Thanks for checking. I think it was just bad luck with what I was looking at, works fine now.

screenshot 2019-01-07 at 21 10 20

@robdodson
Copy link
Contributor

Hey @hoten @paulirish given how flaky this feature is, do y'all think we should maybe consider disabling it? For instance, if the shape of the DOM is just different in mobile emulation, vs. desktop then we kind of know this feature will always break to some extent. Is it worth it to have things that are only clickable some of the time? cc @yuinchien

@connorjclark
Copy link
Collaborator

I think this feature is too useful to some people to remove. At the very least, I'd like to explore #2289 (comment) first, before giving up on this.

@carmacleod
Copy link

@hoten Does node linking work if you don't reload the page?
There is an outstanding issue for making page refresh optional.

@connorjclark
Copy link
Collaborator

I think if you limit LH to one pass (example, just accessibility/seo) AND disabled the refresh at the end, all node links would work. currently the only node links that work are for pages where the node path does not change.

currently I find things work inconsistently on cnn.com - for some reason the load event doesn't always fire when expected #2289 (comment)

@connorjclark
Copy link
Collaborator

@carmacleod I can test the URL you have myself to see if it ever works for me. Just now I tried cnn.com, it didn't work the first few times, but now it always works..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment