diff --git a/lighthouse-core/lib/network-recorder.js b/lighthouse-core/lib/network-recorder.js index e6b150a42779..4098fc371e3f 100644 --- a/lighthouse-core/lib/network-recorder.js +++ b/lighthouse-core/lib/network-recorder.js @@ -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; + const responseReceived = record.responseReceivedTime > 0; + 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. @@ -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}); } }); diff --git a/lighthouse-core/test/lib/network-recorder-test.js b/lighthouse-core/test/lib/network-recorder-test.js index 967ef318dc7f..ac73e5fc65e9 100644 --- a/lighthouse-core/test/lib/network-recorder-test.js +++ b/lighthouse-core/test/lib/network-recorder-test.js @@ -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,