[go: nahoru, domu]

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 1 commit
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
Next Next commit
core(network-recorder): consider frame requests with responses as fin…
…ished
  • Loading branch information
patrickhulce committed Sep 20, 2018
commit 362345e8d4d10fed7fc201a5b0c9417347e56f28
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 = Number.isFinite(record.responseReceivedTime);
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