lighthouse 9.2.0-dev.20220109 → 9.2.0-dev.20220113

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.
@@ -275,7 +275,6 @@ function getShardedDefinitions(testDefns, shardArg) {
275
275
  return shardDefns;
276
276
  }
277
277
 
278
-
279
278
  export {
280
279
  runSmokehouse,
281
280
  getShardedDefinitions,
@@ -73,13 +73,28 @@ class Audit {
73
73
  * considering a log-normal distribution governed by two control points (the 10th
74
74
  * percentile value and the median value) and represents the percentage of sites that are
75
75
  * greater than `value`.
76
+ *
77
+ * Score characteristics:
78
+ * - within [0, 1]
79
+ * - rounded to two digits
80
+ * - value must meet or beat a controlPoint value to meet or exceed its percentile score:
81
+ * - value > median will give a score < 0.5; value ≤ median will give a score ≥ 0.5.
82
+ * - value > p10 will give a score < 0.9; value ≤ p10 will give a score ≥ 0.9.
83
+ * - values < p10 will get a slight boost so a score of 1 is achievable by a
84
+ * `value` other than those close to 0. Scores of > ~0.99524 end up rounded to 1.
76
85
  * @param {{median: number, p10: number}} controlPoints
77
86
  * @param {number} value
78
87
  * @return {number}
79
88
  */
80
89
  static computeLogNormalScore(controlPoints, value) {
81
- const percentile = statistics.getLogNormalScore(controlPoints, value);
82
- return clampTo2Decimals(percentile);
90
+ let percentile = statistics.getLogNormalScore(controlPoints, value);
91
+ // Add a boost to scores of 90+, linearly ramping from 0 at 0.9 to half a
92
+ // point (0.005) at 1. Expands scores in (0.9, 1] to (0.9, 1.005], so more top
93
+ // scores will be a perfect 1 after the two-digit `Math.floor()` rounding below.
94
+ if (percentile > 0.9) { // getLogNormalScore ensures `percentile` can't exceed 1.
95
+ percentile += 0.05 * (percentile - 0.9);
96
+ }
97
+ return Math.floor(percentile * 100) / 100;
83
98
  }
84
99
 
85
100
  /**
@@ -62,8 +62,8 @@ class Deprecations extends Audit {
62
62
  const bundles = await JsBundles.request(artifacts, context);
63
63
 
64
64
  let deprecations;
65
- if (artifacts.InspectorIssues.deprecations.length) {
66
- deprecations = artifacts.InspectorIssues.deprecations
65
+ if (artifacts.InspectorIssues.deprecationIssue.length) {
66
+ deprecations = artifacts.InspectorIssues.deprecationIssue
67
67
  .map(deprecation => {
68
68
  const {url, lineNumber, columnNumber} = deprecation.sourceCodeLocation;
69
69
  const bundle = bundles.find(bundle => bundle.script.src === url);
@@ -161,19 +161,19 @@ class IssuesPanelEntries extends Audit {
161
161
  /** @type LH.Audit.Details.TableItem[] */
162
162
  const items = [];
163
163
 
164
- if (issues.mixedContent.length) {
165
- items.push(this.getMixedContentRow(issues.mixedContent));
164
+ if (issues.mixedContentIssue.length) {
165
+ items.push(this.getMixedContentRow(issues.mixedContentIssue));
166
166
  }
167
- if (issues.sameSiteCookies.length) {
168
- items.push(this.getSameSiteCookieRow(issues.sameSiteCookies));
167
+ if (issues.sameSiteCookieIssue.length) {
168
+ items.push(this.getSameSiteCookieRow(issues.sameSiteCookieIssue));
169
169
  }
170
- if (issues.blockedByResponse.length) {
171
- items.push(this.getBlockedByResponseRow(issues.blockedByResponse));
170
+ if (issues.blockedByResponseIssue.length) {
171
+ items.push(this.getBlockedByResponseRow(issues.blockedByResponseIssue));
172
172
  }
173
- if (issues.heavyAds.length) {
173
+ if (issues.heavyAdIssue.length) {
174
174
  items.push({issueType: str_(UIStrings.issueTypeHeavyAds)});
175
175
  }
176
- const cspIssues = issues.contentSecurityPolicy.filter(issue => {
176
+ const cspIssues = issues.contentSecurityPolicyIssue.filter(issue => {
177
177
  // kTrustedTypesSinkViolation and kTrustedTypesPolicyViolation aren't currently supported by the Issues panel
178
178
  return issue.contentSecurityPolicyViolationType !== 'kTrustedTypesSinkViolation' &&
179
179
  issue.contentSecurityPolicyViolationType !== 'kTrustedTypesPolicyViolation';
@@ -87,7 +87,7 @@ class HTTPS extends Audit {
87
87
  {key: 'resolution', itemType: 'text', text: str_(UIStrings.columnResolution)},
88
88
  ];
89
89
 
90
- for (const details of artifacts.InspectorIssues.mixedContent) {
90
+ for (const details of artifacts.InspectorIssues.mixedContentIssue) {
91
91
  let item = items.find(item => item.url === details.insecureURL);
92
92
  if (!item) {
93
93
  item = {url: details.insecureURL};
@@ -6,7 +6,8 @@
6
6
  'use strict';
7
7
 
8
8
  const Audit = require('../audit.js');
9
- const robotsParser = require('robots-parser');
9
+ // TODO(esmodules): cast can be removed when this switches to import.
10
+ const robotsParser = /** @type {typeof import('robots-parser').default} */ (/** @type {unknown} */(require('robots-parser'))); // eslint-disable-line max-len
10
11
  const URL = require('../../lib/url-shim.js');
11
12
  const MainResource = require('../../computed/main-resource.js');
12
13
  const BLOCKLIST = new Set([
@@ -58,58 +58,48 @@ class InspectorIssues extends FRGatherer {
58
58
  * @return {Promise<LH.Artifacts['InspectorIssues']>}
59
59
  */
60
60
  async _getArtifact(networkRecords) {
61
+ /** @type {LH.Artifacts.InspectorIssues} */
61
62
  const artifact = {
62
- /** @type {Array<LH.Crdp.Audits.MixedContentIssueDetails>} */
63
- mixedContent: [],
64
- /** @type {Array<LH.Crdp.Audits.SameSiteCookieIssueDetails>} */
65
- sameSiteCookies: [],
66
- /** @type {Array<LH.Crdp.Audits.BlockedByResponseIssueDetails>} */
67
- blockedByResponse: [],
68
- /** @type {Array<LH.Crdp.Audits.HeavyAdIssueDetails>} */
69
- heavyAds: [],
70
- /** @type {Array<LH.Crdp.Audits.ContentSecurityPolicyIssueDetails>} */
71
- contentSecurityPolicy: [],
72
- /** @type {Array<LH.Crdp.Audits.DeprecationIssueDetails>} */
73
- deprecations: [],
63
+ attributionReportingIssue: [],
64
+ blockedByResponseIssue: [],
65
+ clientHintIssue: [],
66
+ contentSecurityPolicyIssue: [],
67
+ corsIssue: [],
68
+ deprecationIssue: [],
69
+ genericIssue: [],
70
+ heavyAdIssue: [],
71
+ lowTextContrastIssue: [],
72
+ mixedContentIssue: [],
73
+ navigatorUserAgentIssue: [],
74
+ quirksModeIssue: [],
75
+ sameSiteCookieIssue: [],
76
+ sharedArrayBufferIssue: [],
77
+ twaQualityEnforcement: [],
78
+ wasmCrossOriginModuleSharingIssue: [],
74
79
  };
75
-
76
- for (const issue of this._issues) {
77
- if (issue.details.mixedContentIssueDetails) {
78
- const issueDetails = issue.details.mixedContentIssueDetails;
79
- const issueReqId = issueDetails.request?.requestId;
80
- // Duplicate issues can occur for the same request; only use the one with a matching networkRequest.
81
- if (issueReqId &&
82
- networkRecords.find(req => req.requestId === issueReqId)) {
83
- artifact.mixedContent.push(issueDetails);
80
+ const keys = /** @type {Array<keyof LH.Artifacts['InspectorIssues']>} */(Object.keys(artifact));
81
+ for (const key of keys) {
82
+ // The wasmCrossOriginModuleSharingIssue key doesn't follow the pattern of the rest. See
83
+ // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/public/devtools_protocol/browser_protocol.pdl;l=811;drc=9c10bf258928b5d169ba6a449f8f33958f7947ea
84
+ /** @type {`${key}Details` | `wasmCrossOriginModuleSharingIssue`} */
85
+ const detailsKey = (key === 'wasmCrossOriginModuleSharingIssue' ? `${key}` : `${key}Details`);
86
+ const allDetails = this._issues.map(issue => issue.details[detailsKey]);
87
+ for (const detail of allDetails) {
88
+ if (!detail) {
89
+ continue;
84
90
  }
85
- }
86
- if (issue.details.sameSiteCookieIssueDetails) {
87
- const issueDetails = issue.details.sameSiteCookieIssueDetails;
88
- const issueReqId = issueDetails.request?.requestId;
89
91
  // Duplicate issues can occur for the same request; only use the one with a matching networkRequest.
90
- if (issueReqId &&
91
- networkRecords.find(req => req.requestId === issueReqId)) {
92
- artifact.sameSiteCookies.push(issueDetails);
92
+ const requestId = 'request' in detail && detail.request && detail.request.requestId;
93
+ if (requestId) {
94
+ if (networkRecords.find(req => req.requestId === requestId)) {
95
+ // @ts-expect-error - detail types are not all compatible
96
+ artifact[key].push(detail);
97
+ }
98
+ } else {
99
+ // @ts-expect-error - detail types are not all compatible
100
+ artifact[key].push(detail);
93
101
  }
94
102
  }
95
- if (issue.details.blockedByResponseIssueDetails) {
96
- const issueDetails = issue.details.blockedByResponseIssueDetails;
97
- const issueReqId = issueDetails.request?.requestId;
98
- // Duplicate issues can occur for the same request; only use the one with a matching networkRequest.
99
- if (issueReqId &&
100
- networkRecords.find(req => req.requestId === issueReqId)) {
101
- artifact.blockedByResponse.push(issueDetails);
102
- }
103
- }
104
- if (issue.details.heavyAdIssueDetails) {
105
- artifact.heavyAds.push(issue.details.heavyAdIssueDetails);
106
- }
107
- if (issue.details.contentSecurityPolicyIssueDetails) {
108
- artifact.contentSecurityPolicy.push(issue.details.contentSecurityPolicyIssueDetails);
109
- }
110
- if (issue.details.deprecationIssueDetails) {
111
- artifact.deprecations.push(issue.details.deprecationIssueDetails);
112
- }
113
103
  }
114
104
 
115
105
  return artifact;
@@ -19,6 +19,8 @@ const LHError = require('../lib/lh-error.js');
19
19
  // TODO(esmodules): Rollup does not support `promisfy` or `stream.pipeline`. Bundled files
20
20
  // don't need anything in this file except for `stringifyReplacer`, so a check for
21
21
  // truthiness before using is enough.
22
+ // TODO: Can remove promisify(pipeline) in Node 15.
23
+ // https://nodejs.org/api/stream.html#streams-promises-api
22
24
  const pipeline = promisify && promisify(stream.pipeline);
23
25
 
24
26
  const artifactsFilename = 'artifacts.json';
@@ -238,8 +240,6 @@ async function saveTrace(traceData, traceFilename) {
238
240
  const traceIter = traceJsonGenerator(traceData);
239
241
  const writeStream = fs.createWriteStream(traceFilename);
240
242
 
241
- // TODO: Can remove promisify(pipeline) in Node 15.
242
- // https://nodejs.org/api/stream.html#stream_stream_pipeline_streams_callback
243
243
  return pipeline(traceIter, writeStream);
244
244
  }
245
245
 
@@ -250,10 +250,12 @@ async function saveTrace(traceData, traceFilename) {
250
250
  * @return {Promise<void>}
251
251
  */
252
252
  function saveDevtoolsLog(devtoolsLog, devtoolLogFilename) {
253
- const logIter = arrayOfObjectsJsonGenerator(devtoolsLog);
254
253
  const writeStream = fs.createWriteStream(devtoolLogFilename);
255
254
 
256
- return pipeline(logIter, writeStream);
255
+ return pipeline(function* () {
256
+ yield* arrayOfObjectsJsonGenerator(devtoolsLog);
257
+ yield '\n';
258
+ }, writeStream);
257
259
  }
258
260
 
259
261
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse",
3
- "version": "9.2.0-dev.20220109",
3
+ "version": "9.2.0-dev.20220113",
4
4
  "description": "Automated auditing, performance metrics, and best practices for the web.",
5
5
  "main": "./lighthouse-core/index.js",
6
6
  "bin": {
@@ -14,7 +14,7 @@
14
14
  "scripts": {
15
15
  "prepack": "yarn build-report --standalone --flow --esm",
16
16
  "build-all": "npm-run-posix-or-windows build-all:task",
17
- "build-all:task": "yarn build-report && yarn build-cdt-lib && yarn build-devtools && (yarn build-extension & yarn build-lr & yarn build-viewer & yarn build-treemap & yarn build-smokehouse-bundle & wait) && yarn build-pack",
17
+ "build-all:task": "yarn build-report && yarn build-cdt-lib && yarn build-devtools && concurrently 'yarn build-extension' 'yarn build-lr' 'yarn build-viewer' 'yarn build-treemap' 'yarn build-smokehouse-bundle' && yarn build-pack",
18
18
  "build-all:task:windows": "yarn build-report && yarn build-cdt-lib && yarn build-extension && yarn build-devtools && yarn build-lr && yarn build-viewer && yarn build-treemap && yarn build-smokehouse-bundle",
19
19
  "build-cdt-lib": "node ./build/build-cdt-lib.js",
20
20
  "build-extension": "yarn build-extension-chrome && yarn build-extension-firefox",
@@ -137,11 +137,12 @@
137
137
  "c8": "^7.4.0",
138
138
  "chalk": "^2.4.1",
139
139
  "chrome-devtools-frontend": "1.0.922924",
140
+ "concurrently": "^6.4.0",
140
141
  "conventional-changelog-cli": "^2.1.1",
141
142
  "cpy": "^8.1.2",
142
143
  "cross-env": "^7.0.2",
143
144
  "csv-validator": "^0.0.3",
144
- "devtools-protocol": "0.0.939404",
145
+ "devtools-protocol": "0.0.957544",
145
146
  "es-main": "^1.0.2",
146
147
  "eslint": "^8.4.1",
147
148
  "eslint-config-google": "^0.14.0",
@@ -205,7 +206,7 @@
205
206
  "parse-cache-control": "1.0.1",
206
207
  "ps-list": "^8.0.0",
207
208
  "raven": "^2.2.1",
208
- "robots-parser": "^2.3.0",
209
+ "robots-parser": "^3.0.0",
209
210
  "semver": "^5.3.0",
210
211
  "speedline-core": "^1.4.3",
211
212
  "third-party-web": "^0.12.7",
@@ -215,7 +216,7 @@
215
216
  "yargs-parser": "^20.2.4"
216
217
  },
217
218
  "resolutions": {
218
- "puppeteer/**/devtools-protocol": "0.0.939404"
219
+ "puppeteer/**/devtools-protocol": "0.0.957544"
219
220
  },
220
221
  "repository": "GoogleChrome/lighthouse",
221
222
  "keywords": [
@@ -97,7 +97,7 @@ describe('ReportGenerator', () => {
97
97
  expect(lines.slice(0, 3).join('\n')).toMatchInlineSnapshot(`
98
98
  "requestedUrl,finalUrl,category,name,title,type,score
99
99
  \\"http://localhost:10200/dobetterweb/dbw_tester.html\\",\\"http://localhost:10200/dobetterweb/dbw_tester.html\\",\\"Performance\\",\\"performance-score\\",\\"Overall Performance Category Score\\",\\"numeric\\",\\"0.26\\"
100
- \\"http://localhost:10200/dobetterweb/dbw_tester.html\\",\\"http://localhost:10200/dobetterweb/dbw_tester.html\\",\\"Performance\\",\\"first-contentful-paint\\",\\"First Contentful Paint\\",\\"numeric\\",\\"0.02\\"
100
+ \\"http://localhost:10200/dobetterweb/dbw_tester.html\\",\\"http://localhost:10200/dobetterweb/dbw_tester.html\\",\\"Performance\\",\\"first-contentful-paint\\",\\"First Contentful Paint\\",\\"numeric\\",\\"0.01\\"
101
101
  "
102
102
  `);
103
103
 
@@ -553,12 +553,22 @@ declare module Artifacts {
553
553
  }
554
554
 
555
555
  interface InspectorIssues {
556
- mixedContent: LH.Crdp.Audits.MixedContentIssueDetails[];
557
- sameSiteCookies: LH.Crdp.Audits.SameSiteCookieIssueDetails[];
558
- blockedByResponse: LH.Crdp.Audits.BlockedByResponseIssueDetails[];
559
- heavyAds: LH.Crdp.Audits.HeavyAdIssueDetails[];
560
- contentSecurityPolicy: LH.Crdp.Audits.ContentSecurityPolicyIssueDetails[];
561
- deprecations: LH.Crdp.Audits.DeprecationIssueDetails[];
556
+ attributionReportingIssue: LH.Crdp.Audits.AttributionReportingIssueDetails[];
557
+ blockedByResponseIssue: LH.Crdp.Audits.BlockedByResponseIssueDetails[];
558
+ clientHintIssue: LH.Crdp.Audits.ClientHintIssueDetails[];
559
+ contentSecurityPolicyIssue: LH.Crdp.Audits.ContentSecurityPolicyIssueDetails[];
560
+ corsIssue: LH.Crdp.Audits.CorsIssueDetails[];
561
+ deprecationIssue: LH.Crdp.Audits.DeprecationIssueDetails[];
562
+ genericIssue: LH.Crdp.Audits.GenericIssueDetails[];
563
+ heavyAdIssue: LH.Crdp.Audits.HeavyAdIssueDetails[];
564
+ lowTextContrastIssue: LH.Crdp.Audits.LowTextContrastIssueDetails[];
565
+ mixedContentIssue: LH.Crdp.Audits.MixedContentIssueDetails[];
566
+ navigatorUserAgentIssue: LH.Crdp.Audits.NavigatorUserAgentIssueDetails[];
567
+ quirksModeIssue: LH.Crdp.Audits.QuirksModeIssueDetails[];
568
+ sameSiteCookieIssue: LH.Crdp.Audits.SameSiteCookieIssueDetails[];
569
+ sharedArrayBufferIssue: LH.Crdp.Audits.SharedArrayBufferIssueDetails[];
570
+ twaQualityEnforcement: LH.Crdp.Audits.TrustedWebActivityIssueDetails[];
571
+ wasmCrossOriginModuleSharingIssue: LH.Crdp.Audits.WasmCrossOriginModuleSharingIssueDetails[];
562
572
  }
563
573
 
564
574
  // Computed artifact types below.
@@ -1,20 +0,0 @@
1
- /**
2
- * @license Copyright 2018 The Lighthouse Authors. All Rights Reserved.
3
- * 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
4
- * 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.
5
- */
6
-
7
- declare module 'robots-parser' {
8
- interface Robots {
9
- isAllowed(url: string, ua?: string): boolean | undefined;
10
- isDisallowed(url: string, ua?: string): boolean | undefined;
11
- getMatchingLineNumber(url: string, ua?: string): number | undefined;
12
- getCrawlDelay(ua?: string): number | undefined;
13
- getSitemaps(): Array<string>;
14
- getPreferredHost(): string | null;
15
- }
16
-
17
- function RobotsParser(url: string, robotsTxt: string): Robots;
18
-
19
- export = RobotsParser;
20
- }