lighthouse 11.2.0-dev.20231018 → 11.2.0-dev.20231020

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ export function getYargsParser(manualArgv?: string | undefined): yargs.Argv<yarg
24
24
  default: boolean;
25
25
  describe: string;
26
26
  };
27
- }>, "port" | "screenEmulation" | "emulatedUserAgent" | "hostname" | "preset" | "save-assets" | "list-all-audits" | "list-locales" | "list-trace-categories" | "debug-navigation" | "additional-trace-categories" | "config-path" | "chrome-flags" | "form-factor" | "max-wait-for-load" | "enable-error-reporting" | "gather-mode" | "audit-mode" | "only-audits" | "only-categories" | "skip-audits" | "budget-path" | "disable-full-page-screenshot"> & yargs.InferredOptionTypes<{
27
+ }>, "port" | "screenEmulation" | "emulatedUserAgent" | "hostname" | "preset" | "save-assets" | "list-all-audits" | "list-locales" | "list-trace-categories" | "debug-navigation" | "additional-trace-categories" | "config-path" | "chrome-flags" | "form-factor" | "max-wait-for-load" | "enable-error-reporting" | "gather-mode" | "audit-mode" | "only-audits" | "only-categories" | "skip-audits" | "budget-path" | "disable-full-page-screenshot" | "ignore-status-code"> & yargs.InferredOptionTypes<{
28
28
  'save-assets': {
29
29
  type: "boolean";
30
30
  default: boolean;
@@ -133,6 +133,10 @@ export function getYargsParser(manualArgv?: string | undefined): yargs.Argv<yarg
133
133
  type: "boolean";
134
134
  describe: string;
135
135
  };
136
+ 'ignore-status-code': {
137
+ type: "boolean";
138
+ describe: string;
139
+ };
136
140
  }>, "output" | "view" | "output-path"> & yargs.InferredOptionTypes<{
137
141
  output: {
138
142
  type: "array";
package/cli/cli-flags.js CHANGED
@@ -204,12 +204,16 @@ function getYargsParser(manualArgv) {
204
204
  type: 'boolean',
205
205
  describe: 'Disables collection of the full page screenshot, which can be quite large',
206
206
  },
207
+ 'ignore-status-code': {
208
+ type: 'boolean',
209
+ describe: 'Disables failing on all error status codes, and instead issues a warning.',
210
+ },
207
211
  })
208
212
  .group([
209
213
  'save-assets', 'list-all-audits', 'list-locales', 'list-trace-categories', 'additional-trace-categories',
210
214
  'config-path', 'preset', 'chrome-flags', 'port', 'hostname', 'form-factor', 'screenEmulation', 'emulatedUserAgent',
211
215
  'max-wait-for-load', 'enable-error-reporting', 'gather-mode', 'audit-mode',
212
- 'only-audits', 'only-categories', 'skip-audits', 'budget-path', 'disable-full-page-screenshot',
216
+ 'only-audits', 'only-categories', 'skip-audits', 'budget-path', 'disable-full-page-screenshot', 'ignore-status-code',
213
217
  ], 'Configuration:')
214
218
 
215
219
  // Output
@@ -113,6 +113,7 @@ const defaultSettings = {
113
113
  disableFullPageScreenshot: false,
114
114
  skipAboutBlank: false,
115
115
  blankPage: 'about:blank',
116
+ ignoreStatusCode: false,
116
117
 
117
118
  // the following settings have no defaults but we still want ensure that `key in settings`
118
119
  // in config will work in a typechecked way
@@ -67,6 +67,7 @@ class InspectorIssues extends BaseGatherer {
67
67
  bounceTrackingIssue: [],
68
68
  clientHintIssue: [],
69
69
  contentSecurityPolicyIssue: [],
70
+ cookieDeprecationMetadataIssue: [],
70
71
  corsIssue: [],
71
72
  deprecationIssue: [],
72
73
  federatedAuthRequestIssue: [],
@@ -155,6 +155,7 @@ async function _computeNavigationResult(
155
155
  const pageLoadError = debugData.records
156
156
  ? getPageLoadError(navigationError, {
157
157
  url: mainDocumentUrl,
158
+ ignoreStatusCode: navigationContext.resolvedConfig.settings.ignoreStatusCode,
158
159
  networkRecords: debugData.records,
159
160
  warnings: navigationContext.baseArtifacts.LighthouseRunWarnings,
160
161
  })
@@ -1,9 +1,13 @@
1
1
  /**
2
2
  * Returns an error if the original network request failed or wasn't found.
3
3
  * @param {LH.Artifacts.NetworkRequest|undefined} mainRecord
4
+ * @param {{warnings: Array<string | LH.IcuMessage>, ignoreStatusCode?: LH.Config.Settings['ignoreStatusCode']}} context
4
5
  * @return {LH.LighthouseError|undefined}
5
6
  */
6
- export function getNetworkError(mainRecord: LH.Artifacts.NetworkRequest | undefined): LH.LighthouseError | undefined;
7
+ export function getNetworkError(mainRecord: LH.Artifacts.NetworkRequest | undefined, context: {
8
+ warnings: Array<string | LH.IcuMessage>;
9
+ ignoreStatusCode?: LH.Config.Settings['ignoreStatusCode'];
10
+ }): LH.LighthouseError | undefined;
7
11
  /**
8
12
  * Returns an error if we ended up on the `chrome-error` page and all other requests failed.
9
13
  * @param {LH.Artifacts.NetworkRequest|undefined} mainRecord
@@ -15,11 +19,12 @@ export function getInterstitialError(mainRecord: LH.Artifacts.NetworkRequest | u
15
19
  * Returns an error if the page load should be considered failed, e.g. from a
16
20
  * main document request failure, a security issue, etc.
17
21
  * @param {LH.LighthouseError|undefined} navigationError
18
- * @param {{url: string, networkRecords: Array<LH.Artifacts.NetworkRequest>, warnings: Array<string | LH.IcuMessage>}} context
22
+ * @param {{url: string, ignoreStatusCode?: LH.Config.Settings['ignoreStatusCode'], networkRecords: Array<LH.Artifacts.NetworkRequest>, warnings: Array<string | LH.IcuMessage>}} context
19
23
  * @return {LH.LighthouseError|undefined}
20
24
  */
21
25
  export function getPageLoadError(navigationError: LH.LighthouseError | undefined, context: {
22
26
  url: string;
27
+ ignoreStatusCode?: boolean | undefined;
23
28
  networkRecords: Array<LH.Artifacts.NetworkRequest>;
24
29
  warnings: Array<string | LH.IcuMessage>;
25
30
  }): LH.LighthouseError | undefined;
@@ -32,6 +37,7 @@ export function getPageLoadError(navigationError: LH.LighthouseError | undefined
32
37
  export function getNonHtmlError(finalRecord: LH.Artifacts.NetworkRequest | undefined): LH.LighthouseError | undefined;
33
38
  export namespace UIStrings {
34
39
  const warningXhtml: string;
40
+ const warningStatusCode: string;
35
41
  }
36
42
  import { NetworkRequest } from './network-request.js';
37
43
  import { LighthouseError } from './lh-error.js';
@@ -16,6 +16,13 @@ const UIStrings = {
16
16
  */
17
17
  warningXhtml:
18
18
  'The page MIME type is XHTML: Lighthouse does not explicitly support this document type',
19
+ /**
20
+ * @description Warning shown in report when the page under test returns an error code, which Lighthouse is not able to reliably load so we display a warning.
21
+ * @example {404} errorCode
22
+ */
23
+ warningStatusCode: 'Lighthouse was unable to reliably load the page you requested. Make sure' +
24
+ ' you are testing the correct URL and that the server is properly responding' +
25
+ ' to all requests. (Status code: {errorCode})',
19
26
  };
20
27
 
21
28
  const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
@@ -27,9 +34,10 @@ const XHTML_MIME_TYPE = 'application/xhtml+xml';
27
34
  /**
28
35
  * Returns an error if the original network request failed or wasn't found.
29
36
  * @param {LH.Artifacts.NetworkRequest|undefined} mainRecord
37
+ * @param {{warnings: Array<string | LH.IcuMessage>, ignoreStatusCode?: LH.Config.Settings['ignoreStatusCode']}} context
30
38
  * @return {LH.LighthouseError|undefined}
31
39
  */
32
- function getNetworkError(mainRecord) {
40
+ function getNetworkError(mainRecord, context) {
33
41
  if (!mainRecord) {
34
42
  return new LighthouseError(LighthouseError.errors.NO_DOCUMENT_REQUEST);
35
43
  } else if (mainRecord.failed) {
@@ -47,9 +55,13 @@ function getNetworkError(mainRecord) {
47
55
  LighthouseError.errors.FAILED_DOCUMENT_REQUEST, {errorDetails: netErr});
48
56
  }
49
57
  } else if (mainRecord.hasErrorStatusCode()) {
50
- return new LighthouseError(LighthouseError.errors.ERRORED_DOCUMENT_REQUEST, {
51
- statusCode: `${mainRecord.statusCode}`,
52
- });
58
+ if (context.ignoreStatusCode) {
59
+ context.warnings.push(str_(UIStrings.warningStatusCode, {errorCode: mainRecord.statusCode}));
60
+ } else {
61
+ return new LighthouseError(LighthouseError.errors.ERRORED_DOCUMENT_REQUEST, {
62
+ statusCode: `${mainRecord.statusCode}`,
63
+ });
64
+ }
53
65
  }
54
66
  }
55
67
 
@@ -113,7 +125,7 @@ function getNonHtmlError(finalRecord) {
113
125
  * Returns an error if the page load should be considered failed, e.g. from a
114
126
  * main document request failure, a security issue, etc.
115
127
  * @param {LH.LighthouseError|undefined} navigationError
116
- * @param {{url: string, networkRecords: Array<LH.Artifacts.NetworkRequest>, warnings: Array<string | LH.IcuMessage>}} context
128
+ * @param {{url: string, ignoreStatusCode?: LH.Config.Settings['ignoreStatusCode'], networkRecords: Array<LH.Artifacts.NetworkRequest>, warnings: Array<string | LH.IcuMessage>}} context
117
129
  * @return {LH.LighthouseError|undefined}
118
130
  */
119
131
  function getPageLoadError(navigationError, context) {
@@ -144,7 +156,7 @@ function getPageLoadError(navigationError, context) {
144
156
  context.warnings.push(str_(UIStrings.warningXhtml));
145
157
  }
146
158
 
147
- const networkError = getNetworkError(mainRecord);
159
+ const networkError = getNetworkError(mainRecord, context);
148
160
  const interstitialError = getInterstitialError(mainRecord, networkRecords);
149
161
  const nonHtmlError = getNonHtmlError(finalRecord);
150
162