-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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): handle LR transferSize #5895
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,8 @@ module.exports = class NetworkRequest { | |
this.initiatorRequest = undefined; | ||
/** @type {HeaderEntry[]} */ | ||
this.responseHeaders = []; | ||
/** @type {string} */ | ||
this.responseHeadersText = ''; | ||
|
||
this.fetchedViaServiceWorker = false; | ||
/** @type {string|undefined} */ | ||
|
@@ -172,6 +174,7 @@ module.exports = class NetworkRequest { | |
} | ||
|
||
this._updateResponseReceivedTimeIfNecessary(); | ||
this._updateTransferSizeForLightRiderIfNecessary(); | ||
} | ||
|
||
/** | ||
|
@@ -234,12 +237,15 @@ module.exports = class NetworkRequest { | |
this.timing = response.timing; | ||
if (resourceType) this.resourceType = RESOURCE_TYPES[resourceType]; | ||
this.mimeType = response.mimeType; | ||
this.responseHeadersText = response.headersText || ''; | ||
this.responseHeaders = NetworkRequest._headersDictToHeadersArray(response.headers); | ||
|
||
this.fetchedViaServiceWorker = !!response.fromServiceWorker; | ||
|
||
if (this.fromMemoryCache) this.timing = undefined; | ||
if (this.timing) this._recomputeTimesWithResourceTiming(this.timing); | ||
|
||
this._updateTransferSizeForLightRiderIfNecessary(); | ||
} | ||
|
||
/** | ||
|
@@ -269,6 +275,28 @@ module.exports = class NetworkRequest { | |
this.responseReceivedTime = Math.min(this.endTime, this.responseReceivedTime); | ||
} | ||
|
||
/** | ||
* LR loses transfer size information and passes it in the 'X-Original-Content-Length' header. | ||
*/ | ||
_updateTransferSizeForLightRiderIfNecessary() { | ||
// Bail if we're not in LightRider, this only applies there. | ||
if (!global.isLightRider) return; | ||
// Bail if we somehow already have transfer size data. | ||
if (this.transferSize) return; | ||
// Bail if we didn't get any response headers. | ||
if (!this.responseHeadersText) return; | ||
|
||
const originalContentLength = this.responseHeaders. | ||
find(item => item.name === 'X-Original-Content-Length'); | ||
// Bail if the x-original-content-length header was missing. | ||
if (!originalContentLength) return; | ||
|
||
// Transfer size is the original content length + length of headers | ||
const contentBytes = parseFloat(originalContentLength.value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am tickled. :) |
||
const headerBytes = this.responseHeadersText.length; | ||
this.transferSize = contentBytes + headerBytes; | ||
} | ||
|
||
/** | ||
* Convert the requestId to backend-version by removing the `:redirect` portion | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,9 @@ async function runLighthouseInExtension(flags, categoryIDs) { | |
* @return {Promise<string|Array<string>|void>} | ||
*/ | ||
async function runLighthouseInLR(connection, url, flags, {lrDevice, categoryIDs, logAssets}) { | ||
// Certain fixes need to kick-in under LR, see https://github.com/GoogleChrome/lighthouse/issues/5839 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One if the origin RTT estimates only applies in LR. Do you want to re use this there? Fine if you don't. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah that's ok that fallback is a lot more sound than this one :) |
||
global.isLightRider = true; | ||
|
||
// Override default device to be desktop, since LR default device has viewport 1x1. | ||
connection.sendCommand('Emulation.setDeviceMetricsOverride', | ||
{width: 800, height: 600, deviceScaleFactor: 0, mobile: false}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
declare module NodeJS { | ||
interface Global { | ||
isLightRider?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brendankenny on a scale of 1-5, how offensive is this to you? |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figure this is the best global reference we got.. better than self? WFM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah was just using what we decided to go with in web-inspector.js last time