Skip to content

Commit

Permalink
core(network-request): cleanup DevTools property names (#5606)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Jul 2, 2018
1 parent f3eb462 commit 01b4cb8
Show file tree
Hide file tree
Showing 80 changed files with 4,875 additions and 25,311 deletions.
4 changes: 2 additions & 2 deletions lighthouse-core/audits/bootup-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class BootupTime extends Audit {
}

/**
* @param {LH.WebInspector.NetworkRequest[]} records
* @param {LH.Artifacts.NetworkRequest[]} records
*/
static getJavaScriptURLs(records) {
/** @type {Set<string>} */
const urls = new Set();
for (const record of records) {
if (record._resourceType && record._resourceType === 'Script') {
if (record.resourceType && record.resourceType === 'Script') {
urls.add(record.url);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class UnusedBytes extends Audit {
* Estimates the number of bytes this network record would have consumed on the network based on the
* uncompressed size (totalBytes). Uses the actual transfer size from the network record if applicable.
*
* @param {LH.WebInspector.NetworkRequest=} networkRecord
* @param {LH.Artifacts.NetworkRequest=} networkRecord
* @param {number} totalBytes Uncompressed size of the resource
* @param {LH.Crdp.Page.ResourceType=} resourceType
* @param {number=} compressionRatio
Expand All @@ -79,14 +79,14 @@ class UnusedBytes extends Audit {
// roughly the size of the content gzipped.
// See https://discuss.httparchive.org/t/file-size-and-compression-savings/145 for multipliers
return Math.round(totalBytes * compressionRatio);
} else if (networkRecord._resourceType === resourceType) {
} else if (networkRecord.resourceType === resourceType) {
// This was a regular standalone asset, just use the transfer size.
return networkRecord.transferSize || 0;
} else {
// This was an asset that was inlined in a different resource type (e.g. HTML document).
// Use the compression ratio of the resource to estimate the total transferred bytes.
const transferSize = networkRecord.transferSize || 0;
const resourceSize = networkRecord._resourceSize;
const resourceSize = networkRecord.resourceSize;
const compressionRatio = resourceSize !== undefined ? (transferSize / resourceSize) : 1;
return Math.round(totalBytes * compressionRatio);
}
Expand Down Expand Up @@ -220,7 +220,7 @@ class UnusedBytes extends Audit {

/**
* @param {LH.Artifacts} artifacts
* @param {Array<LH.WebInspector.NetworkRequest>} networkRecords
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
* @param {LH.Audit.Context} context
* @return {ByteEfficiencyProduct|Promise<ByteEfficiencyProduct>}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ class EfficientAnimatedContent extends ByteEfficiencyAudit {

/**
* @param {LH.Artifacts} artifacts
* @param {Array<LH.WebInspector.NetworkRequest>} networkRecords
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
* @return {ByteEfficiencyAudit.ByteEfficiencyProduct}
*/
static audit_(artifacts, networkRecords) {
const unoptimizedContent = networkRecords.filter(
record => record._mimeType === 'image/gif' &&
record._resourceType === NetworkRequest.TYPES.Image &&
(record._resourceSize || 0) > GIF_BYTE_THRESHOLD
record => record.mimeType === 'image/gif' &&
record.resourceType === NetworkRequest.TYPES.Image &&
(record.resourceSize || 0) > GIF_BYTE_THRESHOLD
);

/** @type {Array<{url: string, totalBytes: number, wastedBytes: number}>}*/
const items = unoptimizedContent.map(record => {
const resourceSize = record._resourceSize || 0;
const resourceSize = record.resourceSize || 0;
return {
url: record.url,
totalBytes: resourceSize,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/byte-efficiency/offscreen-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class OffscreenImages extends ByteEfficiencyAudit {

/**
* @param {LH.Artifacts} artifacts
* @param {Array<LH.WebInspector.NetworkRequest>} networkRecords
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
* @param {LH.Audit.Context} context
* @return {Promise<ByteEfficiencyAudit.ByteEfficiencyProduct>}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class RenderBlockingResources extends Audit {
if (node.type !== BaseNode.TYPES.NETWORK) return !canDeferRequest;

const isStylesheet =
node.record._resourceType === NetworkRequest.TYPES.Stylesheet;
node.record.resourceType === NetworkRequest.TYPES.Stylesheet;
if (canDeferRequest && isStylesheet) {
// We'll inline the used bytes of the stylesheet and assume the rest can be deferred
const wastedBytes = wastedCssBytesByUrl.get(node.record.url) || 0;
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/byte-efficiency/unminified-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class UnminifiedCSS extends ByteEfficiencyAudit {

/**
* @param {LH.Artifacts.CSSStyleSheetInfo} stylesheet
* @param {LH.WebInspector.NetworkRequest=} networkRecord
* @param {LH.Artifacts.NetworkRequest=} networkRecord
* @param {string} pageUrl
* @return {{url: string, totalBytes: number, wastedBytes: number, wastedPercent: number}}
*/
Expand Down Expand Up @@ -121,7 +121,7 @@ class UnminifiedCSS extends ByteEfficiencyAudit {

/**
* @param {LH.Artifacts} artifacts
* @param {Array<LH.WebInspector.NetworkRequest>} networkRecords
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
* @return {ByteEfficiencyAudit.ByteEfficiencyProduct}
*/
static audit_(artifacts, networkRecords) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UnminifiedJavaScript extends ByteEfficiencyAudit {

/**
* @param {string} scriptContent
* @param {LH.WebInspector.NetworkRequest} networkRecord
* @param {LH.Artifacts.NetworkRequest} networkRecord
* @return {{url: string, totalBytes: number, wastedBytes: number, wastedPercent: number}}
*/
static computeWaste(scriptContent, networkRecord) {
Expand Down Expand Up @@ -71,7 +71,7 @@ class UnminifiedJavaScript extends ByteEfficiencyAudit {

/**
* @param {LH.Artifacts} artifacts
* @param {Array<LH.WebInspector.NetworkRequest>} networkRecords
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
* @return {ByteEfficiencyAudit.ByteEfficiencyProduct}
*/
static audit_(artifacts, networkRecords) {
Expand All @@ -92,7 +92,7 @@ class UnminifiedJavaScript extends ByteEfficiencyAudit {
!Number.isFinite(result.wastedBytes)) continue;
items.push(result);
} catch (err) {
warnings.push(`Unable to process ${networkRecord._url}: ${err.message}`);
warnings.push(`Unable to process ${networkRecord.url}: ${err.message}`);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/audits/byte-efficiency/unused-css-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ByteEfficiencyAudit = require('./byte-efficiency-audit');
const IGNORE_THRESHOLD_IN_BYTES = 2048;
const PREVIEW_LENGTH = 100;

/** @typedef {LH.Artifacts.CSSStyleSheetInfo & {networkRecord: LH.WebInspector.NetworkRequest, usedRules: Array<LH.Crdp.CSS.RuleUsage>}} StyleSheetInfo */
/** @typedef {LH.Artifacts.CSSStyleSheetInfo & {networkRecord: LH.Artifacts.NetworkRequest, usedRules: Array<LH.Crdp.CSS.RuleUsage>}} StyleSheetInfo */

class UnusedCSSRules extends ByteEfficiencyAudit {
/**
Expand All @@ -30,15 +30,15 @@ class UnusedCSSRules extends ByteEfficiencyAudit {

/**
* @param {Array<LH.Artifacts.CSSStyleSheetInfo>} styles The output of the Styles gatherer.
* @param {Array<LH.WebInspector.NetworkRequest>} networkRecords
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
* @return {Object<string, StyleSheetInfo>} A map of styleSheetId to stylesheet information.
*/
static indexStylesheetsById(styles, networkRecords) {
const indexedNetworkRecords = networkRecords
.reduce((indexed, record) => {
indexed[record.url] = record;
return indexed;
}, /** @type {Object<string, LH.WebInspector.NetworkRequest>} */ ({}));
}, /** @type {Object<string, LH.Artifacts.NetworkRequest>} */ ({}));

return styles.reduce((indexed, stylesheet) => {
indexed[stylesheet.header.styleSheetId] = Object.assign({
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/byte-efficiency/unused-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class UnusedJavaScript extends ByteEfficiencyAudit {

/**
* @param {Array<{unusedLength: number, contentLength: number}>} wasteData
* @param {LH.WebInspector.NetworkRequest} networkRecord
* @param {LH.Artifacts.NetworkRequest} networkRecord
* @return {LH.Audit.ByteEfficiencyItem}
*/
static mergeWaste(wasteData, networkRecord) {
Expand All @@ -87,7 +87,7 @@ class UnusedJavaScript extends ByteEfficiencyAudit {

/**
* @param {LH.Artifacts} artifacts
* @param {Array<LH.WebInspector.NetworkRequest>} networkRecords
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
* @return {ByteEfficiencyAudit.ByteEfficiencyProduct}
*/
static audit_(artifacts, networkRecords) {
Expand Down
10 changes: 5 additions & 5 deletions lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class CacheHeaders extends Audit {
*
* TODO: Investigate impact in HTTPArchive, experiment with this policy to see what changes.
*
* @param {LH.WebInspector.NetworkRequest} record
* @param {LH.Artifacts.NetworkRequest} record
* @return {boolean}
*/
static isCacheableAsset(record) {
Expand All @@ -142,10 +142,10 @@ class CacheHeaders extends Audit {
NetworkRequest.TYPES.Stylesheet,
]);

const resourceUrl = record._url;
const resourceUrl = record.url;
return (
CACHEABLE_STATUS_CODES.has(record.statusCode) &&
STATIC_RESOURCE_TYPES.has(record._resourceType || 'Other') &&
STATIC_RESOURCE_TYPES.has(record.resourceType || 'Other') &&
!resourceUrl.includes('data:')
);
}
Expand All @@ -167,7 +167,7 @@ class CacheHeaders extends Audit {

/** @type {Map<string, string>} */
const headers = new Map();
for (const header of record._responseHeaders || []) {
for (const header of record.responseHeaders || []) {
headers.set(header.name.toLowerCase(), header.value);
}

Expand All @@ -184,7 +184,7 @@ class CacheHeaders extends Audit {
const cacheHitProbability = CacheHeaders.getCacheHitProbability(cacheLifetimeInSeconds);
if (cacheHitProbability > IGNORE_THRESHOLD_IN_PERCENT) continue;

const url = URL.elideDataURI(record._url);
const url = URL.elideDataURI(record.url);
const totalBytes = record.transferSize || 0;
const wastedBytes = (1 - cacheHitProbability) * totalBytes;

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/critical-request-chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CriticalRequestChains extends Audit {
url: request.url,
startTime: request.startTime,
endTime: request.endTime,
_responseReceivedTime: request._responseReceivedTime,
responseReceivedTime: request.responseReceivedTime,
transferSize: request.transferSize,
};

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/dobetterweb/uses-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class UsesHTTP2Audit extends Audit {
// test the protocol first to avoid (potentially) expensive URL parsing
const isOldHttp = /HTTP\/[01][.\d]?/i.test(record.protocol);
if (!isOldHttp) return false;
const requestHost = new URL(record._url).host;
const requestHost = new URL(record.url).host;
return requestHost === finalHost;
}).map(record => {
return {
protocol: record.protocol,
url: record._url,
url: record.url,
};
}).filter(record => {
if (seenURLs.has(record.url)) return false;
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/font-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FontDisplay extends Audit {

return artifacts.requestNetworkRecords(devtoolsLogs).then((networkRecords) => {
const results = networkRecords.filter(record => {
const isFont = record._resourceType === NetworkRequest.TYPES.Font;
const isFont = record.resourceType === NetworkRequest.TYPES.Font;

return isFont;
})
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/network-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class NetworkRequests extends Audit {
endTime: timeToMs(record.endTime),
transferSize: record.transferSize,
statusCode: record.statusCode,
mimeType: record._mimeType,
resourceType: record._resourceType,
mimeType: record.mimeType,
resourceType: record.resourceType,
};
});

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/seo/canonical.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Canonical extends Audit {
/** @type {Array<string>} */
let hreflangs = [];

mainResource._responseHeaders && mainResource._responseHeaders
mainResource.responseHeaders && mainResource.responseHeaders
.filter(h => h.name.toLowerCase() === LINK_HEADER)
.forEach(h => {
canonicals = canonicals.concat(getCanonicalLinksFromHeader(h.value));
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/seo/hreflang.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Hreflang extends Audit {
});
}

mainResource._responseHeaders && mainResource._responseHeaders
mainResource.responseHeaders && mainResource.responseHeaders
.filter(h => h.name.toLowerCase() === LINK_HEADER && !headerHasValidHreflangs(h.value))
.forEach(h => invalidHreflangs.push({source: `${h.name}: ${h.value}`}));

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/seo/is-crawlable.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class IsCrawlable extends Audit {
}
}

mainResource._responseHeaders && mainResource._responseHeaders
mainResource.responseHeaders && mainResource.responseHeaders
.filter(h => h.name.toLowerCase() === ROBOTS_HEADER && !hasUserAgent(h.value) &&
hasBlockingDirective(h.value))
.forEach(h => blockingDirectives.push({source: `${h.name}: ${h.value}`}));
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/audits/time-to-first-byte.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class TTFBMetric extends Audit {
}

/**
* @param {LH.WebInspector.NetworkRequest} record
* @param {LH.Artifacts.NetworkRequest} record
*/
static caclulateTTFB(record) {
const timing = record._timing;
const timing = record.timing;
return timing ? timing.receiveHeadersEnd - timing.sendEnd : 0;
}

Expand All @@ -44,7 +44,7 @@ class TTFBMetric extends Audit {
let displayValue = '';

const finalUrl = artifacts.URL.finalUrl;
const finalUrlRequest = networkRecords.find(record => record._url === finalUrl);
const finalUrlRequest = networkRecords.find(record => record.url === finalUrl);
if (!finalUrlRequest) {
throw new Error(`finalUrl '${finalUrl} not found in network records.`);
}
Expand Down
Loading

0 comments on commit 01b4cb8

Please sign in to comment.