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): consider iframe responses finished #6078

Merged
merged 2 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lighthouse-core/lib/network-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ class NetworkRecorder extends EventEmitter {
return !!(isQUIC && receivedHeaders && record.endTime);
}

/**
* frame root network requests don't always "finish" even when they're done loading data, use responseReceived instead
* @see https://github.com/GoogleChrome/lighthouse/issues/6067#issuecomment-423211201
* @param {LH.Artifacts.NetworkRequest} record
* @return {boolean}
*/
static _isFrameRootRequestAndFinished(record) {
const isFrameRootRequest = record.url === record.documentURL;
Copy link
Member

@brendankenny brendankenny Sep 20, 2018

Choose a reason for hiding this comment

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

do we have to worry about query strings or anything else throwing this check off? (are these fields ever canonicalized through different paths, I guess I'm asking)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From what I could tell this is always the full query string-included URL. There were lots of samples on the verge that had misc query string params.

const responseReceived = record.responseReceivedTime > 0;
Copy link
Member

Choose a reason for hiding this comment

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

I really hate trying to remember the difference between data-received/response-received/finished/etc (as well as where things like requestServedFromCache fall into things), but just to make sure I understand, typically responseReceived only fires once, we just usually expect a loadingFinished to also be fired?

Copy link
Collaborator Author

@patrickhulce patrickhulce Sep 20, 2018

Choose a reason for hiding this comment

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

Correct that is my understanding as well, data received can fire lots of times, but we always expect response received + one of loadingFinished/loadingFailed to signal the end of the request.

Copy link
Collaborator

@wardpeet wardpeet Sep 20, 2018

Choose a reason for hiding this comment

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

do we need to consider preloads or won't this affect anything? I was thinking if a preloaded iframe was requested we might get endTime of 0. (not sure if people preload iframes) or it even counts when appending with javascript

return !!(isFrameRootRequest && responseReceived && record.endTime);
}

/**
* Finds all time periods where the number of inflight requests is less than or equal to the
* number of allowed concurrent requests.
Expand All @@ -119,7 +131,9 @@ class NetworkRecorder extends EventEmitter {

// convert the network record timestamp to ms
timeBoundaries.push({time: record.startTime * 1000, isStart: true});
if (record.finished || NetworkRecorder._isQUICAndFinished(record)) {
if (record.finished ||
NetworkRecorder._isQUICAndFinished(record) ||
NetworkRecorder._isFrameRootRequestAndFinished(record)) {
timeBoundaries.push({time: record.endTime * 1000, isStart: false});
}
});
Expand Down
19 changes: 19 additions & 0 deletions lighthouse-core/test/lib/network-recorder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ describe('network recorder', function() {
]);
});

it('should handle iframe requests', () => {
const iframeRequest = {
finished: false,
url: 'https://iframe.com',
documentURL: 'https://iframe.com',
responseReceivedTime: 1.2,
};

const records = [
record({startTime: 0, endTime: 1}),
record({startTime: 0, endTime: 1.2, ...iframeRequest}),
];

const periods = NetworkRecorder.findNetworkQuietPeriods(records, 0);
assert.deepStrictEqual(periods, [
{start: 1200, end: Infinity},
]);
});

it('should handle QUIC requests', () => {
const quicRequest = {
finished: false,
Expand Down