Skip to content

Commit df37783

Browse files
authored
core(network): revert strict wrapping of network requests (#16949)
1 parent 607ff1a commit df37783

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

cli/test/smokehouse/test-definitions/redirects-scripts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const expectations = {
3535
// This check ensures that we resolve the redirect and use the final redirect network request to compute savings.
3636
// We can distinguish using totalBytes because the final request is compressed while the redirect request is not.
3737
url: 'http://localhost:10200/simple-script.js?redirect=%2Funused-javascript.js%3Fgzip%3D1',
38-
totalBytes: '285000 +/- 2000',
38+
totalBytes: '285000 +/- 4000',
3939
},
4040
],
4141
},

core/computed/main-resource.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import * as Lantern from '../lib/lantern/lantern.js';
88
import {makeComputedArtifact} from './computed-artifact.js';
99
import {NetworkRecords} from './network-records.js';
10-
import {NetworkRequest} from '../lib/network-request.js';
1110

1211
/**
1312
* @fileoverview This artifact identifies the main resource on the page. Current solution assumes
@@ -30,14 +29,16 @@ class MainResource {
3029
// would have evicted the first request by the time `MainDocumentRequest` (a consumer
3130
// of this computed artifact) attempts to fetch the contents, resulting in a protocol error.
3231
const mainResource = Lantern.Core.NetworkAnalyzer.findLastDocumentForUrl(
33-
records.map(NetworkRequest.asLanternNetworkRequest),
32+
// @ts-expect-error - trace engine types for InitiatorType are outdated
33+
records,
3434
mainDocumentUrl
3535
);
36-
if (!mainResource?.rawRequest) {
36+
if (!mainResource) {
3737
throw new Error('Unable to identify the main resource');
3838
}
3939

40-
return mainResource.rawRequest;
40+
// @ts-expect-error - Return type is typed as Lantern request by trace engine, but it is a raw record at runtime since we passed raw records.
41+
return mainResource;
4142
}
4243
}
4344

core/computed/network-analysis.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import log from 'lighthouse-logger';
99
import * as Lantern from '../lib/lantern/lantern.js';
1010
import {makeComputedArtifact} from './computed-artifact.js';
1111
import {NetworkRecords} from './network-records.js';
12-
import {NetworkRequest} from '../lib/network-request.js';
1312

1413
class NetworkAnalysis {
1514
/**
@@ -20,7 +19,8 @@ class NetworkAnalysis {
2019
static async compute_(devtoolsLog, context) {
2120
const records = await NetworkRecords.request(devtoolsLog, context);
2221
const analysis = Lantern.Core.NetworkAnalyzer.analyze(
23-
records.map(NetworkRequest.asLanternNetworkRequest)
22+
// @ts-expect-error - trace engine types for InitiatorType are outdated
23+
records
2424
);
2525
if (!analysis) {
2626
log.error('NetworkAnalysis', 'Network analysis failed due to lack of transfer data');

core/lib/navigation-error.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ function getNonHtmlError(finalRecord) {
131131
function getPageLoadError(navigationError, context) {
132132
const {url, networkRecords} = context;
133133
const mainRecordLantern = Lantern.Core.NetworkAnalyzer.findResourceForUrl(
134-
networkRecords.map(NetworkRequest.asLanternNetworkRequest),
134+
// @ts-expect-error - trace engine types for InitiatorType are outdated
135+
networkRecords,
135136
url
136137
);
137-
let mainRecord = mainRecordLantern?.rawRequest;
138+
let mainRecord = mainRecordLantern;
138139

139140
// If the url doesn't give us a network request, it's possible we landed on a chrome-error:// page
140141
// In this case, just get the first document request.
@@ -143,6 +144,7 @@ function getPageLoadError(navigationError, context) {
143144
record.resourceType === NetworkRequest.TYPES.Document
144145
);
145146
if (documentRequests.length) {
147+
// @ts-expect-error - mainRecord is inferred as a Lantern request from findResourceForUrl, but we assign a raw record here.
146148
mainRecord = documentRequests.reduce((min, r) => {
147149
return r.networkRequestTime < min.networkRequestTime ? r : min;
148150
});
@@ -152,9 +154,7 @@ function getPageLoadError(navigationError, context) {
152154
// MIME Type is only set on the final redirected document request. Use this for the HTML check instead of root.
153155
let finalRecord;
154156
if (mainRecord) {
155-
const mainRecordLantern = NetworkRequest.asLanternNetworkRequest(mainRecord);
156-
const finalRecordLantern = Lantern.Core.NetworkAnalyzer.resolveRedirects(mainRecordLantern);
157-
finalRecord = finalRecordLantern?.rawRequest || finalRecordLantern;
157+
finalRecord = Lantern.Core.NetworkAnalyzer.resolveRedirects(mainRecord);
158158
} else {
159159
// We have no network requests to process, use the navError
160160
return navigationError;
@@ -164,7 +164,9 @@ function getPageLoadError(navigationError, context) {
164164
context.warnings.push(str_(UIStrings.warningXhtml));
165165
}
166166

167+
// @ts-expect-error - mainRecord may be typed as a Lantern request, but functions expect a raw record.
167168
const networkError = getNetworkError(mainRecord, context);
169+
// @ts-expect-error - mainRecord may be typed as a Lantern request, but functions expect a raw record.
168170
const interstitialError = getInterstitialError(mainRecord, networkRecords);
169171
// @ts-expect-error - finalRecord may be a Lantern request, which is compatible enough
170172
// for getNonHtmlError.

0 commit comments

Comments
 (0)