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

core(iframe-elements): Include new IFrameElements gatherer #8979

Merged
merged 23 commits into from
Sep 18, 2019

Conversation

jburger424
Copy link
Contributor

@jburger424
Copy link
Contributor Author

TODO: unit tests

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome stuff thank you so much for bringing all this work over @jburger424! 🎉

lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
types/artifacts.d.ts Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
@brendankenny
Copy link
Member

for the travis failure, will need to update the index-test.js.snap snapshot with yarn run unit-cli -u to include the new gatherer.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feedback. Thanks for opening this!

types/artifacts.d.ts Outdated Show resolved Hide resolved
types/artifacts.d.ts Outdated Show resolved Hide resolved
types/artifacts.d.ts Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
types/artifacts.d.ts Outdated Show resolved Hide resolved
types/artifacts.d.ts Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
types/artifacts.d.ts Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Show resolved Hide resolved
types/artifacts.d.ts Outdated Show resolved Hide resolved
@jburger424 jburger424 changed the title WIP: Include IFrameElements gatherer. core(iframe-elements): Include new IFrameElements gatherer. Jul 1, 2019
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm pretty much there other than tests!

unit tests can mock out the connection of driver to exercise the toVisit frame tree traversal, smoke tests can just assert that the whole flow works. the OOPIF smoketest should already have some nested iframes you can assert the artifacts on.

lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
types/artifacts.d.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jburger424! Functionality all LGTM, just some style and tests left for me :)

lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
Update getElementsInDocument function to find child elements within IFrames.
@jburger424
Copy link
Contributor Author

@patrickhulce I'm ensuring that frame traversal is working properly in the smoke test, by ensuring that the nested iframe has a frame attr. Do you still think it would be good to test this in a unit test?

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming all highlighted quirks are WAI, LGTM :)

lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Outdated Show resolved Hide resolved
lighthouse-core/lib/page-functions.js Show resolved Hide resolved
types/artifacts.d.ts Outdated Show resolved Hide resolved
@patrickhulce
Copy link
Collaborator

@paulirish @brendankenny do you have any desire to take another look at this one?

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the downside here is that we gotta manually match up collectIFrameElements() results with getFrameTree().

as noted below, we can't match up with name vs id.
frameTree's only DOM-mutable property is name, but that isn't supposed to be unique and indeed I see google_osd_static_frame as the name frequently, so I don't think we want to rely on it as a unique key.

I looked at DOMSnapshot.captureSnapshot which has style data, clientRects, and attributes, so we can 100% replace collectIFrameElements() with this protocol call. The downside is that I think we still don't have anything to bind to our frameTree objects. I wish backendNodeId was available on the frameTree, then we'd be peachy.

... looks around...

One option... DOM.getFrameOwner accepts a frameId and returns a backendNodeId.
So that would allow us to get a frameTree, send the frameIds within into DOM.getFrameOwner and then we use the resulting BackendNodeId's to match up against the captureSnapshot output.

the snapshot output is a little wild, but workable.

I know this is a big curveball, but as it stands I don't think the iframe id/name matching is reliable for most iframes.

types/artifacts.d.ts Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/iframe-elements.js Outdated Show resolved Hide resolved
@@ -98,6 +98,10 @@ function getElementsInDocument(selector) {
if (el.shadowRoot) {
_findAllElements(el.shadowRoot.querySelectorAll('*'));
}
// If the element has a contentDocument (IFrame), dig deeper.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only some iframes have contentDocuments... I honestly dont understand why some do and some dont (even within google ads iframes...)
image

  1. can we make this comment more specific to which iframes are included
  2. i think we need this behind a pierceIframes option that defaults to off, otherwise our dom-size audit is about to go pretty crazy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to go ahead and remove this functionality for the time being.

In the future it may:

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update: getFrameOwner gets the DOM details of the frame's parent frame. That's not what we want. :/

Also.. when I was just testing getFrameTree() on theverge.. i'm only seeing 5 frames, whereas qSA returns 12 and I see ~26 iframes in the DOM tree. It feels like there's something else going on here leading to frames missing from the frameTree, or maybe i'm holding it wrong.

@jburger424
Copy link
Contributor Author

@paulirish Sorry for the late response, have been OOO for past week. Will start digging into these today.

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upstream the iframe-elements gatherer
7 participants