Skip to content
Merged
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
25 changes: 18 additions & 7 deletions lighthouse-core/lib/network-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,35 @@ class NetworkRecorder extends EventEmitter {
}

isIdle() {
return !!this._getActiveIdlePeriod(0);
return this._isActiveIdlePeriod(0);
}

is2Idle() {
return !!this._getActiveIdlePeriod(2);
return this._isActiveIdlePeriod(2);
}

/**
* Returns whether the number of currently inflight requests is less than or
* equal to the number of allowed concurrent requests.
* @param {number} allowedRequests
* @return {boolean}
*/
_getActiveIdlePeriod(allowedRequests) {
const quietPeriods = NetworkRecorder.findNetworkQuietPeriods(this._records, allowedRequests);
return quietPeriods.find(period => !Number.isFinite(period.end));
_isActiveIdlePeriod(allowedRequests) {
let inflightRequests = 0;

for (let i = 0; i < this._records.length; i++) {
const record = this._records[i];
if (NetworkRecorder.isNetworkRecordFinished(record)) continue;
if (IGNORED_NETWORK_SCHEMES.includes(record.parsedURL.scheme)) continue;
inflightRequests++;
}

return inflightRequests <= allowedRequests;
}

_emitNetworkStatus() {
const zeroQuiet = this._getActiveIdlePeriod(0);
const twoQuiet = this._getActiveIdlePeriod(2);
const zeroQuiet = this.isIdle();
const twoQuiet = this.is2Idle();

if (twoQuiet && zeroQuiet) {
log.verbose('NetworkRecorder', 'network fully-quiet');
Expand Down