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(network-recorder): redirects started by script are set as initiators #7352

Merged
merged 6 commits into from
Mar 6, 2019

Conversation

paulirish
Copy link
Member

Given this test page:

<!DOCTYPE html>
<script>
setTimeout(_ => {
  // add an iframe to the page via script
  // the iframe will open :10200/redirects-script.html
  // which redirects to :10503/redirects-script.html
  // which redirects to airhorner.com
  const elem = document.createElement('iframe');
  elem.src = 'http://localhost:10200/redirects-script.html?redirect=http%3A%2F%2Flocalhost%3A10503%2Fredirects-script.html%3Fredirect%3Dhttps%253A%252F%252Fairhorner.com%252F';
  document.body.append(elem);
}, 400);
</script>

We'd expect to see a request chain like so:
image

But we currently see this instead:
image

This PR resolves this.

Our technique of setting initiator was mostly considering network redirects of the main document, but not when the initiator was Script. A quick logic fix later and we're good.


I ran into this while looking at #6704 and #6675.

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.

LGTM!

though would you find forcing lantern smoketests to run? we should add "network-recorder" and "network-request" to the list of files that force a lantern run in travis

for now you can make a bogus commit or something that touches lantern stuff?

@@ -368,7 +368,7 @@ class NetworkRecorder extends EventEmitter {
for (const record of records) {
const stackFrames = (record.initiator.stack && record.initiator.stack.callFrames) || [];
const initiatorURL = record.initiator.url || (stackFrames[0] && stackFrames[0].url);
const initiator = recordsByURL.get(initiatorURL) || record.redirectSource;
Copy link
Collaborator

Choose a reason for hiding this comment

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

presumably there was some reason I fellback this way but I have no idea what is was at this point and this seems to make more sense, so..... cool!

maybe add a comment so we don't forget again?

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.

LGTM, though it makes me nervous that we had no tests that failed when switching those around :)

lighthouse-core/lib/network-recorder.js Outdated Show resolved Hide resolved
paulirish and others added 2 commits March 1, 2019 11:54
@paulirish
Copy link
Member Author

lantern tests results:
image

@paulirish paulirish merged commit bd1c4c1 into master Mar 6, 2019
@paulirish paulirish deleted the redirectsintiatiors branch March 6, 2019 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants