Skip to content

Commit

Permalink
clients(lr): enable uses-http2, add protocol override header (#11439)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Sep 17, 2020
1 parent b080896 commit 2e9967b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lighthouse-core/audits/network-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class NetworkRequests extends Audit {

return {
url: URL.elideDataURI(record.url),
protocol: record.protocol,
startTime: timeToMs(record.startTime),
endTime: timeToMs(record.endTime),
finished: record.finished,
Expand All @@ -67,6 +68,7 @@ class NetworkRequests extends Audit {
/** @type {LH.Audit.Details.Table['headings']} */
const headings = [
{key: 'url', itemType: 'url', text: 'URL'},
{key: 'protocol', itemType: 'text', text: 'Protocol'},
{key: 'startTime', itemType: 'ms', granularity: 1, text: 'Start Time'},
{key: 'endTime', itemType: 'ms', granularity: 1, text: 'End Time'},
{
Expand Down
2 changes: 0 additions & 2 deletions lighthouse-core/config/lr-desktop-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const config = {
maxWaitForLoad: 35 * 1000,
emulatedFormFactor: 'desktop',
throttling: desktopDense4G,
// Skip the h2 audit so it doesn't lie to us. See https://github.com/GoogleChrome/lighthouse/issues/6539
skipAudits: ['uses-http2'],
},
};

Expand Down
2 changes: 0 additions & 2 deletions lighthouse-core/config/lr-mobile-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const config = {
settings: {
maxWaitForFcp: 15 * 1000,
maxWaitForLoad: 35 * 1000,
// Skip the h2 audit so it doesn't lie to us. See https://github.com/GoogleChrome/lighthouse/issues/6539
skipAudits: ['uses-http2'],
},
audits: [
'metrics/first-contentful-paint-3g',
Expand Down
15 changes: 15 additions & 0 deletions lighthouse-core/lib/network-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const HEADER_REQ = 'X-RequestMs';
const HEADER_RES = 'X-ResponseMs';
const HEADER_TOTAL = 'X-TotalMs';
const HEADER_FETCHED_SIZE = 'X-TotalFetchedSize';
const HEADER_PROTOCOL_IS_H2 = 'X-ProtocolIsH2';

/**
* @typedef HeaderEntry
Expand Down Expand Up @@ -195,6 +196,7 @@ class NetworkRequest {
*/
onResponseReceived(data) {
this._onResponse(data.response, data.timestamp, data.type);
this._updateProtocolForLightrider();
this.frameId = data.frameId;
}

Expand Down Expand Up @@ -366,6 +368,18 @@ class NetworkRequest {
this.transferSize = floatValue;
}

/**
* LR loses protocol information.
*/
_updateProtocolForLightrider() {
// Bail if we aren't in Lightrider.
if (!global.isLightrider) return;

if (this.responseHeaders.some(item => item.name === HEADER_PROTOCOL_IS_H2)) {
this.protocol = 'h2';
}
}

/**
* LR gets additional, accurate timing information from its underlying fetch infrastructure. This
* is passed in via X-Headers similar to 'X-TotalFetchedSize'.
Expand Down Expand Up @@ -462,5 +476,6 @@ NetworkRequest.HEADER_REQ = HEADER_REQ;
NetworkRequest.HEADER_RES = HEADER_RES;
NetworkRequest.HEADER_TOTAL = HEADER_TOTAL;
NetworkRequest.HEADER_FETCHED_SIZE = HEADER_FETCHED_SIZE;
NetworkRequest.HEADER_PROTOCOL_IS_H2 = HEADER_PROTOCOL_IS_H2;

module.exports = NetworkRequest;
39 changes: 39 additions & 0 deletions lighthouse-core/test/lib/network-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,45 @@ describe('NetworkRequest', () => {
});
});

describe('update protocol for Lightrider', () => {
function getRequest() {
return {
protocol: 'http/1.1',
responseHeaders: [{name: NetworkRequest.HEADER_PROTOCOL_IS_H2, value: '1'}],
};
}

it('does nothing if not Lightrider', () => {
const req = getRequest();

const devtoolsLog = networkRecordsToDevtoolsLog([req]);
const record = NetworkRecorder.recordsFromLogs(devtoolsLog)[0];

expect(record.protocol).toStrictEqual('http/1.1');
});

it('updates protocol if Lightrider', () => {
const req = getRequest();

const devtoolsLog = networkRecordsToDevtoolsLog([req]);
global.isLightrider = true;
const record = NetworkRecorder.recordsFromLogs(devtoolsLog)[0];

expect(record.protocol).toStrictEqual('h2');
});

it('does nothing if no header is set', () => {
const req = getRequest();
req.responseHeaders = [];

const devtoolsLog = networkRecordsToDevtoolsLog([req]);
global.isLightrider = true;
const record = NetworkRecorder.recordsFromLogs(devtoolsLog)[0];

expect(record.protocol).toStrictEqual('http/1.1');
});
});

describe('update fetch stats for Lightrider', () => {
function getRequest() {
return {
Expand Down
23 changes: 23 additions & 0 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,11 @@
"itemType": "url",
"text": "URL"
},
{
"key": "protocol",
"itemType": "text",
"text": "Protocol"
},
{
"key": "startTime",
"itemType": "ms",
Expand Down Expand Up @@ -1031,6 +1036,7 @@
"items": [
{
"url": "http://localhost:10200/dobetterweb/dbw_tester.html",
"protocol": "http/1.1",
"startTime": 0,
"endTime": 640.1550000009593,
"finished": true,
Expand All @@ -1042,6 +1048,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/dbw_tester.css?delay=2000&async=true",
"protocol": "http/1.1",
"startTime": 630.2950000099372,
"endTime": 2635.035000013886,
"finished": true,
Expand All @@ -1053,6 +1060,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/dbw_tester.css?delay=100",
"protocol": "http/1.1",
"startTime": 635.496000002604,
"endTime": 1204.6590000099968,
"finished": true,
Expand All @@ -1064,6 +1072,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/unknown404.css?delay=200",
"protocol": "http/1.1",
"startTime": 636.6400000115391,
"endTime": 1213.2910000218544,
"finished": true,
Expand All @@ -1075,6 +1084,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/dbw_tester.css?delay=2200",
"protocol": "http/1.1",
"startTime": 638.0040000076406,
"endTime": 2849.3670000170823,
"finished": true,
Expand All @@ -1086,6 +1096,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/dbw_disabled.css?delay=200&isdisabled",
"protocol": "http/1.1",
"startTime": 638.7899999972433,
"endTime": 1220.04100002232,
"finished": true,
Expand All @@ -1097,6 +1108,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/dbw_partial_a.html?delay=200",
"protocol": "http/1.1",
"startTime": 640.5979999981355,
"endTime": 1228.5180000180844,
"finished": true,
Expand All @@ -1108,6 +1120,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/dbw_partial_b.html?delay=200&isasync",
"protocol": "http/1.1",
"startTime": 641.3450000109151,
"endTime": 1776.4320000133011,
"finished": true,
Expand All @@ -1119,6 +1132,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/dbw_tester.css?delay=3000&async=true",
"protocol": "http/1.1",
"startTime": 642.8679999953602,
"endTime": 4216.161000018474,
"finished": true,
Expand All @@ -1130,6 +1144,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/dbw_tester.js",
"protocol": "http/1.1",
"startTime": 644.0820000134408,
"endTime": 1792.0860000012908,
"finished": true,
Expand All @@ -1141,6 +1156,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/empty_module.js?delay=500",
"protocol": "http/1.1",
"startTime": 645.529000001261,
"endTime": 1236.1859999946319,
"finished": true,
Expand All @@ -1152,6 +1168,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/lighthouse-480x318.jpg",
"protocol": "http/1.1",
"startTime": 3951.6250000160653,
"endTime": 4779.641000000993,
"finished": true,
Expand All @@ -1163,6 +1180,7 @@
},
{
"url": "http://localhost:10200/zone.js",
"protocol": "http/1.1",
"startTime": 2849.7340000176337,
"endTime": 3961.049000005005,
"finished": true,
Expand All @@ -1174,6 +1192,7 @@
},
{
"url": "http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js",
"protocol": "http/1.1",
"startTime": 3874.7540000185836,
"endTime": 4796.288000012282,
"finished": true,
Expand All @@ -1185,6 +1204,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/dbw_tester.css?scriptActivated&delay=200",
"protocol": "http/1.1",
"startTime": 2924.34100000537,
"endTime": 3964.233000006061,
"finished": true,
Expand All @@ -1196,6 +1216,7 @@
},
{
"url": "http://localhost:10200/dobetterweb/dbw_tester.html",
"protocol": "http/1.1",
"startTime": 3066.252999997232,
"endTime": 3772.7560000203084,
"finished": true,
Expand All @@ -1207,6 +1228,7 @@
},
{
"url": "blob:http://localhost:10200/ae0eac03-ab9b-4a6a-b299-f5212153e277",
"protocol": "blob",
"startTime": 3829.6360000094865,
"endTime": 3968.59800000675,
"finished": true,
Expand All @@ -1218,6 +1240,7 @@
},
{
"url": "http://localhost:10200/favicon.ico",
"protocol": "http/1.1",
"startTime": 4967.373000021325,
"endTime": 5536.498000001302,
"finished": true,
Expand Down

0 comments on commit 2e9967b

Please sign in to comment.