lighthouse 9.5.0-dev.20230123 → 9.5.0-dev.20230124
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.
- package/.codecov.yml +0 -5
- package/core/audits/audit.js +1 -1
- package/core/audits/byte-efficiency/legacy-javascript.d.ts +1 -0
- package/core/audits/byte-efficiency/legacy-javascript.js +7 -3
- package/core/audits/dobetterweb/uses-http2.d.ts +5 -2
- package/core/audits/dobetterweb/uses-http2.js +12 -7
- package/core/audits/third-party-facades.d.ts +3 -2
- package/core/audits/third-party-facades.js +12 -9
- package/core/audits/third-party-summary.d.ts +7 -6
- package/core/audits/third-party-summary.js +16 -14
- package/core/audits/valid-source-maps.d.ts +5 -3
- package/core/audits/valid-source-maps.js +11 -9
- package/core/computed/entity-classification.d.ts +29 -0
- package/core/computed/entity-classification.js +102 -0
- package/core/computed/resource-summary.d.ts +4 -2
- package/core/computed/resource-summary.js +8 -5
- package/core/lib/url-utils.js +1 -1
- package/core/runner.d.ts +10 -0
- package/core/runner.js +48 -0
- package/core/util.cjs +1 -1
- package/dist/report/bundle.esm.js +724 -687
- package/dist/report/flow.js +25 -15
- package/dist/report/standalone.js +25 -15
- package/flow-report/src/common.tsx +1 -1
- package/flow-report/src/i18n/i18n.tsx +17 -16
- package/flow-report/src/sidebar/sidebar.tsx +2 -2
- package/flow-report/src/summary/category.tsx +6 -6
- package/flow-report/src/summary/summary.tsx +2 -2
- package/package.json +4 -4
- package/report/renderer/category-renderer.js +19 -17
- package/report/renderer/crc-details-renderer.js +6 -6
- package/report/renderer/details-renderer.js +7 -6
- package/report/renderer/dom.js +1 -1
- package/report/renderer/element-screenshot-renderer.js +3 -3
- package/report/renderer/performance-category-renderer.js +17 -15
- package/report/renderer/pwa-category-renderer.js +5 -4
- package/report/renderer/report-globals.d.ts +21 -0
- package/report/renderer/report-globals.js +49 -0
- package/report/renderer/report-renderer.js +22 -20
- package/report/renderer/report-ui-features.js +9 -8
- package/report/renderer/report-utils.d.ts +116 -0
- package/report/renderer/{util.js → report-utils.js} +81 -429
- package/report/renderer/snippet-renderer.js +3 -2
- package/report/test/renderer/category-renderer-test.js +9 -4
- package/report/test/renderer/crc-details-renderer-test.js +7 -3
- package/report/test/renderer/details-renderer-test.js +7 -3
- package/report/test/renderer/dom-test.js +7 -3
- package/report/test/renderer/element-screenshot-renderer-test.js +8 -4
- package/report/test/renderer/performance-category-renderer-test.js +14 -9
- package/report/test/renderer/pwa-category-renderer-test.js +10 -5
- package/report/test/renderer/report-renderer-test.js +2 -2
- package/report/test/renderer/report-ui-features-test.js +3 -3
- package/report/test/renderer/{util-test.js → report-utils-test.js} +36 -234
- package/report/test/renderer/snippet-renderer-test.js +7 -3
- package/shared/localization/format.js +5 -2
- package/shared/localization/locales/ar-XB.json +50 -50
- package/shared/localization/locales/ar.json +50 -50
- package/shared/localization/locales/bg.json +50 -50
- package/shared/localization/locales/ca.json +50 -50
- package/shared/localization/locales/cs.json +50 -50
- package/shared/localization/locales/da.json +50 -50
- package/shared/localization/locales/de.json +50 -50
- package/shared/localization/locales/el.json +50 -50
- package/shared/localization/locales/en-GB.json +50 -50
- package/shared/localization/locales/en-US.json +54 -54
- package/shared/localization/locales/en-XA.json +50 -50
- package/shared/localization/locales/en-XL.json +54 -54
- package/shared/localization/locales/es-419.json +50 -50
- package/shared/localization/locales/es.json +50 -50
- package/shared/localization/locales/fi.json +50 -50
- package/shared/localization/locales/fil.json +50 -50
- package/shared/localization/locales/fr.json +50 -50
- package/shared/localization/locales/he.json +50 -50
- package/shared/localization/locales/hi.json +50 -50
- package/shared/localization/locales/hr.json +50 -50
- package/shared/localization/locales/hu.json +50 -50
- package/shared/localization/locales/id.json +50 -50
- package/shared/localization/locales/it.json +50 -50
- package/shared/localization/locales/ja.json +50 -50
- package/shared/localization/locales/ko.json +50 -50
- package/shared/localization/locales/lt.json +50 -50
- package/shared/localization/locales/lv.json +50 -50
- package/shared/localization/locales/nl.json +50 -50
- package/shared/localization/locales/no.json +50 -50
- package/shared/localization/locales/pl.json +50 -50
- package/shared/localization/locales/pt-PT.json +50 -50
- package/shared/localization/locales/pt.json +50 -50
- package/shared/localization/locales/ro.json +50 -50
- package/shared/localization/locales/ru.json +50 -50
- package/shared/localization/locales/sk.json +50 -50
- package/shared/localization/locales/sl.json +50 -50
- package/shared/localization/locales/sr-Latn.json +50 -50
- package/shared/localization/locales/sr.json +50 -50
- package/shared/localization/locales/sv.json +50 -50
- package/shared/localization/locales/ta.json +50 -50
- package/shared/localization/locales/te.json +50 -50
- package/shared/localization/locales/th.json +50 -50
- package/shared/localization/locales/tr.json +50 -50
- package/shared/localization/locales/uk.json +50 -50
- package/shared/localization/locales/vi.json +50 -50
- package/shared/localization/locales/zh-HK.json +50 -50
- package/shared/localization/locales/zh-TW.json +50 -50
- package/shared/localization/locales/zh.json +50 -50
- package/shared/test/util-test.js +214 -0
- package/shared/util.d.ts +122 -0
- package/shared/util.js +332 -0
- package/types/artifacts.d.ts +14 -0
- package/types/lhr/lhr.d.ts +33 -0
- package/report/renderer/util.d.ts +0 -342
package/shared/util.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export type SnippetValue = import('../types/lhr/audit-details').default.SnippetValue;
|
|
2
|
+
export class Util {
|
|
3
|
+
static get RATINGS(): {
|
|
4
|
+
PASS: {
|
|
5
|
+
label: string;
|
|
6
|
+
minScore: number;
|
|
7
|
+
};
|
|
8
|
+
AVERAGE: {
|
|
9
|
+
label: string;
|
|
10
|
+
minScore: number;
|
|
11
|
+
};
|
|
12
|
+
FAIL: {
|
|
13
|
+
label: string;
|
|
14
|
+
};
|
|
15
|
+
ERROR: {
|
|
16
|
+
label: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
static get PASS_THRESHOLD(): number;
|
|
20
|
+
static get MS_DISPLAY_VALUE(): string;
|
|
21
|
+
/**
|
|
22
|
+
* If LHR is older than 10.0 it will not have the `finalDisplayedUrl` property.
|
|
23
|
+
* Old LHRs should have the `finalUrl` property which will work fine for the report.
|
|
24
|
+
*
|
|
25
|
+
* @param {LH.Result} lhr
|
|
26
|
+
*/
|
|
27
|
+
static getFinalDisplayedUrl(lhr: LH.Result): string;
|
|
28
|
+
/**
|
|
29
|
+
* If LHR is older than 10.0 it will not have the `mainDocumentUrl` property.
|
|
30
|
+
* Old LHRs should have the `finalUrl` property which is the same as `mainDocumentUrl`.
|
|
31
|
+
*
|
|
32
|
+
* @param {LH.Result} lhr
|
|
33
|
+
*/
|
|
34
|
+
static getMainDocumentUrl(lhr: LH.Result): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* @param {LH.Result} lhr
|
|
37
|
+
* @return {LH.Result.FullPageScreenshot=}
|
|
38
|
+
*/
|
|
39
|
+
static getFullPageScreenshot(lhr: LH.Result): LH.Result.FullPageScreenshot | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Split a string by markdown code spans (enclosed in `backticks`), splitting
|
|
42
|
+
* into segments that were enclosed in backticks (marked as `isCode === true`)
|
|
43
|
+
* and those that outside the backticks (`isCode === false`).
|
|
44
|
+
* @param {string} text
|
|
45
|
+
* @return {Array<{isCode: true, text: string}|{isCode: false, text: string}>}
|
|
46
|
+
*/
|
|
47
|
+
static splitMarkdownCodeSpans(text: string): Array<{
|
|
48
|
+
isCode: true;
|
|
49
|
+
text: string;
|
|
50
|
+
} | {
|
|
51
|
+
isCode: false;
|
|
52
|
+
text: string;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Split a string on markdown links (e.g. [some link](https://...)) into
|
|
56
|
+
* segments of plain text that weren't part of a link (marked as
|
|
57
|
+
* `isLink === false`), and segments with text content and a URL that did make
|
|
58
|
+
* up a link (marked as `isLink === true`).
|
|
59
|
+
* @param {string} text
|
|
60
|
+
* @return {Array<{isLink: true, text: string, linkHref: string}|{isLink: false, text: string}>}
|
|
61
|
+
*/
|
|
62
|
+
static splitMarkdownLink(text: string): Array<{
|
|
63
|
+
isLink: true;
|
|
64
|
+
text: string;
|
|
65
|
+
linkHref: string;
|
|
66
|
+
} | {
|
|
67
|
+
isLink: false;
|
|
68
|
+
text: string;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* @param {URL} parsedUrl
|
|
72
|
+
* @param {{numPathParts?: number, preserveQuery?: boolean, preserveHost?: boolean}=} options
|
|
73
|
+
* @return {string}
|
|
74
|
+
*/
|
|
75
|
+
static getURLDisplayName(parsedUrl: URL, options?: {
|
|
76
|
+
numPathParts?: number | undefined;
|
|
77
|
+
preserveQuery?: boolean | undefined;
|
|
78
|
+
preserveHost?: boolean | undefined;
|
|
79
|
+
} | undefined): string;
|
|
80
|
+
/**
|
|
81
|
+
* Split a URL into a file, hostname and origin for easy display.
|
|
82
|
+
* @param {string} url
|
|
83
|
+
* @return {{file: string, hostname: string, origin: string}}
|
|
84
|
+
*/
|
|
85
|
+
static parseURL(url: string): {
|
|
86
|
+
file: string;
|
|
87
|
+
hostname: string;
|
|
88
|
+
origin: string;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* @param {string|URL} value
|
|
92
|
+
* @return {!URL}
|
|
93
|
+
*/
|
|
94
|
+
static createOrReturnURL(value: string | URL): URL;
|
|
95
|
+
/**
|
|
96
|
+
* Gets the tld of a domain
|
|
97
|
+
*
|
|
98
|
+
* @param {string} hostname
|
|
99
|
+
* @return {string} tld
|
|
100
|
+
*/
|
|
101
|
+
static getTld(hostname: string): string;
|
|
102
|
+
/**
|
|
103
|
+
* Returns a primary domain for provided hostname (e.g. www.example.com -> example.com).
|
|
104
|
+
* @param {string|URL} url hostname or URL object
|
|
105
|
+
* @return {string}
|
|
106
|
+
*/
|
|
107
|
+
static getRootDomain(url: string | URL): string;
|
|
108
|
+
/**
|
|
109
|
+
* Returns only lines that are near a message, or the first few lines if there are
|
|
110
|
+
* no line messages.
|
|
111
|
+
* @param {SnippetValue['lines']} lines
|
|
112
|
+
* @param {SnippetValue['lineMessages']} lineMessages
|
|
113
|
+
* @param {number} surroundingLineCount Number of lines to include before and after
|
|
114
|
+
* the message. If this is e.g. 2 this function might return 5 lines.
|
|
115
|
+
*/
|
|
116
|
+
static filterRelevantLines(lines: SnippetValue['lines'], lineMessages: SnippetValue['lineMessages'], surroundingLineCount: number): {
|
|
117
|
+
content: string;
|
|
118
|
+
lineNumber: number;
|
|
119
|
+
truncated?: boolean | undefined;
|
|
120
|
+
}[];
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=util.d.ts.map
|
package/shared/util.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2017 The Lighthouse Authors. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** @typedef {import('../types/lhr/audit-details').default.SnippetValue} SnippetValue */
|
|
19
|
+
|
|
20
|
+
const ELLIPSIS = '\u2026';
|
|
21
|
+
const NBSP = '\xa0';
|
|
22
|
+
const PASS_THRESHOLD = 0.9;
|
|
23
|
+
|
|
24
|
+
const RATINGS = {
|
|
25
|
+
PASS: {label: 'pass', minScore: PASS_THRESHOLD},
|
|
26
|
+
AVERAGE: {label: 'average', minScore: 0.5},
|
|
27
|
+
FAIL: {label: 'fail'},
|
|
28
|
+
ERROR: {label: 'error'},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// 25 most used tld plus one domains (aka public suffixes) from http archive.
|
|
32
|
+
// @see https://github.com/GoogleChrome/lighthouse/pull/5065#discussion_r191926212
|
|
33
|
+
// The canonical list is https://publicsuffix.org/learn/ but we're only using subset to conserve bytes
|
|
34
|
+
const listOfTlds = [
|
|
35
|
+
'com', 'co', 'gov', 'edu', 'ac', 'org', 'go', 'gob', 'or', 'net', 'in', 'ne', 'nic', 'gouv',
|
|
36
|
+
'web', 'spb', 'blog', 'jus', 'kiev', 'mil', 'wi', 'qc', 'ca', 'bel', 'on',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
class Util {
|
|
40
|
+
static get RATINGS() {
|
|
41
|
+
return RATINGS;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static get PASS_THRESHOLD() {
|
|
45
|
+
return PASS_THRESHOLD;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static get MS_DISPLAY_VALUE() {
|
|
49
|
+
return `%10d${NBSP}ms`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* If LHR is older than 10.0 it will not have the `finalDisplayedUrl` property.
|
|
54
|
+
* Old LHRs should have the `finalUrl` property which will work fine for the report.
|
|
55
|
+
*
|
|
56
|
+
* @param {LH.Result} lhr
|
|
57
|
+
*/
|
|
58
|
+
static getFinalDisplayedUrl(lhr) {
|
|
59
|
+
if (lhr.finalDisplayedUrl) return lhr.finalDisplayedUrl;
|
|
60
|
+
if (lhr.finalUrl) return lhr.finalUrl;
|
|
61
|
+
throw new Error('Could not determine final displayed URL');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* If LHR is older than 10.0 it will not have the `mainDocumentUrl` property.
|
|
66
|
+
* Old LHRs should have the `finalUrl` property which is the same as `mainDocumentUrl`.
|
|
67
|
+
*
|
|
68
|
+
* @param {LH.Result} lhr
|
|
69
|
+
*/
|
|
70
|
+
static getMainDocumentUrl(lhr) {
|
|
71
|
+
return lhr.mainDocumentUrl || lhr.finalUrl;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {LH.Result} lhr
|
|
76
|
+
* @return {LH.Result.FullPageScreenshot=}
|
|
77
|
+
*/
|
|
78
|
+
static getFullPageScreenshot(lhr) {
|
|
79
|
+
if (lhr.fullPageScreenshot) {
|
|
80
|
+
return lhr.fullPageScreenshot;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Prior to 10.0.
|
|
84
|
+
const details = /** @type {LH.Result.FullPageScreenshot=} */ (
|
|
85
|
+
lhr.audits['full-page-screenshot']?.details);
|
|
86
|
+
return details;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Split a string by markdown code spans (enclosed in `backticks`), splitting
|
|
91
|
+
* into segments that were enclosed in backticks (marked as `isCode === true`)
|
|
92
|
+
* and those that outside the backticks (`isCode === false`).
|
|
93
|
+
* @param {string} text
|
|
94
|
+
* @return {Array<{isCode: true, text: string}|{isCode: false, text: string}>}
|
|
95
|
+
*/
|
|
96
|
+
static splitMarkdownCodeSpans(text) {
|
|
97
|
+
/** @type {Array<{isCode: true, text: string}|{isCode: false, text: string}>} */
|
|
98
|
+
const segments = [];
|
|
99
|
+
|
|
100
|
+
// Split on backticked code spans.
|
|
101
|
+
const parts = text.split(/`(.*?)`/g);
|
|
102
|
+
for (let i = 0; i < parts.length; i ++) {
|
|
103
|
+
const text = parts[i];
|
|
104
|
+
|
|
105
|
+
// Empty strings are an artifact of splitting, not meaningful.
|
|
106
|
+
if (!text) continue;
|
|
107
|
+
|
|
108
|
+
// Alternates between plain text and code segments.
|
|
109
|
+
const isCode = i % 2 !== 0;
|
|
110
|
+
segments.push({
|
|
111
|
+
isCode,
|
|
112
|
+
text,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return segments;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Split a string on markdown links (e.g. [some link](https://...)) into
|
|
121
|
+
* segments of plain text that weren't part of a link (marked as
|
|
122
|
+
* `isLink === false`), and segments with text content and a URL that did make
|
|
123
|
+
* up a link (marked as `isLink === true`).
|
|
124
|
+
* @param {string} text
|
|
125
|
+
* @return {Array<{isLink: true, text: string, linkHref: string}|{isLink: false, text: string}>}
|
|
126
|
+
*/
|
|
127
|
+
static splitMarkdownLink(text) {
|
|
128
|
+
/** @type {Array<{isLink: true, text: string, linkHref: string}|{isLink: false, text: string}>} */
|
|
129
|
+
const segments = [];
|
|
130
|
+
|
|
131
|
+
const parts = text.split(/\[([^\]]+?)\]\((https?:\/\/.*?)\)/g);
|
|
132
|
+
while (parts.length) {
|
|
133
|
+
// Shift off the same number of elements as the pre-split and capture groups.
|
|
134
|
+
const [preambleText, linkText, linkHref] = parts.splice(0, 3);
|
|
135
|
+
|
|
136
|
+
if (preambleText) { // Skip empty text as it's an artifact of splitting, not meaningful.
|
|
137
|
+
segments.push({
|
|
138
|
+
isLink: false,
|
|
139
|
+
text: preambleText,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Append link if there are any.
|
|
144
|
+
if (linkText && linkHref) {
|
|
145
|
+
segments.push({
|
|
146
|
+
isLink: true,
|
|
147
|
+
text: linkText,
|
|
148
|
+
linkHref,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return segments;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {URL} parsedUrl
|
|
158
|
+
* @param {{numPathParts?: number, preserveQuery?: boolean, preserveHost?: boolean}=} options
|
|
159
|
+
* @return {string}
|
|
160
|
+
*/
|
|
161
|
+
static getURLDisplayName(parsedUrl, options) {
|
|
162
|
+
// Closure optional properties aren't optional in tsc, so fallback needs undefined values.
|
|
163
|
+
options = options || {numPathParts: undefined, preserveQuery: undefined,
|
|
164
|
+
preserveHost: undefined};
|
|
165
|
+
const numPathParts = options.numPathParts !== undefined ? options.numPathParts : 2;
|
|
166
|
+
const preserveQuery = options.preserveQuery !== undefined ? options.preserveQuery : true;
|
|
167
|
+
const preserveHost = options.preserveHost || false;
|
|
168
|
+
|
|
169
|
+
let name;
|
|
170
|
+
|
|
171
|
+
if (parsedUrl.protocol === 'about:' || parsedUrl.protocol === 'data:') {
|
|
172
|
+
// Handle 'about:*' and 'data:*' URLs specially since they have no path.
|
|
173
|
+
name = parsedUrl.href;
|
|
174
|
+
} else {
|
|
175
|
+
name = parsedUrl.pathname;
|
|
176
|
+
const parts = name.split('/').filter(part => part.length);
|
|
177
|
+
if (numPathParts && parts.length > numPathParts) {
|
|
178
|
+
name = ELLIPSIS + parts.slice(-1 * numPathParts).join('/');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (preserveHost) {
|
|
182
|
+
name = `${parsedUrl.host}/${name.replace(/^\//, '')}`;
|
|
183
|
+
}
|
|
184
|
+
if (preserveQuery) {
|
|
185
|
+
name = `${name}${parsedUrl.search}`;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const MAX_LENGTH = 64;
|
|
190
|
+
if (parsedUrl.protocol !== 'data:') {
|
|
191
|
+
// Always elide hexadecimal hash
|
|
192
|
+
name = name.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, `$1${ELLIPSIS}`);
|
|
193
|
+
// Also elide other hash-like mixed-case strings
|
|
194
|
+
name = name.replace(/([a-zA-Z0-9-_]{9})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9-_]{10,}/g,
|
|
195
|
+
`$1${ELLIPSIS}`);
|
|
196
|
+
// Also elide long number sequences
|
|
197
|
+
name = name.replace(/(\d{3})\d{6,}/g, `$1${ELLIPSIS}`);
|
|
198
|
+
// Merge any adjacent ellipses
|
|
199
|
+
name = name.replace(/\u2026+/g, ELLIPSIS);
|
|
200
|
+
|
|
201
|
+
// Elide query params first
|
|
202
|
+
if (name.length > MAX_LENGTH && name.includes('?')) {
|
|
203
|
+
// Try to leave the first query parameter intact
|
|
204
|
+
name = name.replace(/\?([^=]*)(=)?.*/, `?$1$2${ELLIPSIS}`);
|
|
205
|
+
|
|
206
|
+
// Remove it all if it's still too long
|
|
207
|
+
if (name.length > MAX_LENGTH) {
|
|
208
|
+
name = name.replace(/\?.*/, `?${ELLIPSIS}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Elide too long names next
|
|
214
|
+
if (name.length > MAX_LENGTH) {
|
|
215
|
+
const dotIndex = name.lastIndexOf('.');
|
|
216
|
+
if (dotIndex >= 0) {
|
|
217
|
+
name = name.slice(0, MAX_LENGTH - 1 - (name.length - dotIndex)) +
|
|
218
|
+
// Show file extension
|
|
219
|
+
`${ELLIPSIS}${name.slice(dotIndex)}`;
|
|
220
|
+
} else {
|
|
221
|
+
name = name.slice(0, MAX_LENGTH - 1) + ELLIPSIS;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return name;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Split a URL into a file, hostname and origin for easy display.
|
|
230
|
+
* @param {string} url
|
|
231
|
+
* @return {{file: string, hostname: string, origin: string}}
|
|
232
|
+
*/
|
|
233
|
+
static parseURL(url) {
|
|
234
|
+
const parsedUrl = new URL(url);
|
|
235
|
+
return {
|
|
236
|
+
file: Util.getURLDisplayName(parsedUrl),
|
|
237
|
+
hostname: parsedUrl.hostname,
|
|
238
|
+
origin: parsedUrl.origin,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @param {string|URL} value
|
|
244
|
+
* @return {!URL}
|
|
245
|
+
*/
|
|
246
|
+
static createOrReturnURL(value) {
|
|
247
|
+
if (value instanceof URL) {
|
|
248
|
+
return value;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return new URL(value);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Gets the tld of a domain
|
|
256
|
+
*
|
|
257
|
+
* @param {string} hostname
|
|
258
|
+
* @return {string} tld
|
|
259
|
+
*/
|
|
260
|
+
static getTld(hostname) {
|
|
261
|
+
const tlds = hostname.split('.').slice(-2);
|
|
262
|
+
|
|
263
|
+
if (!listOfTlds.includes(tlds[0])) {
|
|
264
|
+
return `.${tlds[tlds.length - 1]}`;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return `.${tlds.join('.')}`;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Returns a primary domain for provided hostname (e.g. www.example.com -> example.com).
|
|
272
|
+
* @param {string|URL} url hostname or URL object
|
|
273
|
+
* @return {string}
|
|
274
|
+
*/
|
|
275
|
+
static getRootDomain(url) {
|
|
276
|
+
const hostname = Util.createOrReturnURL(url).hostname;
|
|
277
|
+
const tld = Util.getTld(hostname);
|
|
278
|
+
|
|
279
|
+
// tld is .com or .co.uk which means we means that length is 1 to big
|
|
280
|
+
// .com => 2 & .co.uk => 3
|
|
281
|
+
const splitTld = tld.split('.');
|
|
282
|
+
|
|
283
|
+
// get TLD + root domain
|
|
284
|
+
return hostname.split('.').slice(-splitTld.length).join('.');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Returns only lines that are near a message, or the first few lines if there are
|
|
289
|
+
* no line messages.
|
|
290
|
+
* @param {SnippetValue['lines']} lines
|
|
291
|
+
* @param {SnippetValue['lineMessages']} lineMessages
|
|
292
|
+
* @param {number} surroundingLineCount Number of lines to include before and after
|
|
293
|
+
* the message. If this is e.g. 2 this function might return 5 lines.
|
|
294
|
+
*/
|
|
295
|
+
static filterRelevantLines(lines, lineMessages, surroundingLineCount) {
|
|
296
|
+
if (lineMessages.length === 0) {
|
|
297
|
+
// no lines with messages, just return the first bunch of lines
|
|
298
|
+
return lines.slice(0, surroundingLineCount * 2 + 1);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const minGapSize = 3;
|
|
302
|
+
const lineNumbersToKeep = new Set();
|
|
303
|
+
// Sort messages so we can check lineNumbersToKeep to see how big the gap to
|
|
304
|
+
// the previous line is.
|
|
305
|
+
lineMessages = lineMessages.sort((a, b) => (a.lineNumber || 0) - (b.lineNumber || 0));
|
|
306
|
+
lineMessages.forEach(({lineNumber}) => {
|
|
307
|
+
let firstSurroundingLineNumber = lineNumber - surroundingLineCount;
|
|
308
|
+
let lastSurroundingLineNumber = lineNumber + surroundingLineCount;
|
|
309
|
+
|
|
310
|
+
while (firstSurroundingLineNumber < 1) {
|
|
311
|
+
// make sure we still show (surroundingLineCount * 2 + 1) lines in total
|
|
312
|
+
firstSurroundingLineNumber++;
|
|
313
|
+
lastSurroundingLineNumber++;
|
|
314
|
+
}
|
|
315
|
+
// If only a few lines would be omitted normally then we prefer to include
|
|
316
|
+
// extra lines to avoid the tiny gap
|
|
317
|
+
if (lineNumbersToKeep.has(firstSurroundingLineNumber - minGapSize - 1)) {
|
|
318
|
+
firstSurroundingLineNumber -= minGapSize;
|
|
319
|
+
}
|
|
320
|
+
for (let i = firstSurroundingLineNumber; i <= lastSurroundingLineNumber; i++) {
|
|
321
|
+
const surroundingLineNumber = i;
|
|
322
|
+
lineNumbersToKeep.add(surroundingLineNumber);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
return lines.filter(line => lineNumbersToKeep.has(line.lineNumber));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export {
|
|
331
|
+
Util,
|
|
332
|
+
};
|
package/types/artifacts.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type { TaskNode as _TaskNode } from '../core/lib/tracehouse/main-thread-t
|
|
|
17
17
|
import AuditDetails from './lhr/audit-details.js'
|
|
18
18
|
import Config from './config.js';
|
|
19
19
|
import Gatherer from './gatherer.js';
|
|
20
|
+
import {IEntity} from 'third-party-web';
|
|
20
21
|
import {IcuMessage} from './lhr/i18n.js';
|
|
21
22
|
import LHResult from './lhr/lhr.js'
|
|
22
23
|
import Protocol from './protocol.js';
|
|
@@ -925,6 +926,19 @@ declare module Artifacts {
|
|
|
925
926
|
/** The MIME type of the underlying image file. */
|
|
926
927
|
mimeType?: string;
|
|
927
928
|
}
|
|
929
|
+
|
|
930
|
+
interface Entity extends IEntity {
|
|
931
|
+
isUnrecognized?: boolean;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
interface EntityClassification {
|
|
935
|
+
urlsByEntity: Map<Entity, Set<string>>;
|
|
936
|
+
entityByUrl: Map<string, Entity>;
|
|
937
|
+
firstParty?: Entity;
|
|
938
|
+
|
|
939
|
+
// Convenience methods.
|
|
940
|
+
isFirstParty: (url: string) => boolean;
|
|
941
|
+
}
|
|
928
942
|
}
|
|
929
943
|
|
|
930
944
|
export interface Trace {
|
package/types/lhr/lhr.d.ts
CHANGED
|
@@ -56,6 +56,8 @@ interface Result {
|
|
|
56
56
|
};
|
|
57
57
|
/** An array containing the result of all stack packs. */
|
|
58
58
|
stackPacks?: Result.StackPack[];
|
|
59
|
+
/** All the origins encountered during this Lighthouse run, and information about what web property (aka "entity") they belong to. Won't be present for snapshot mode. */
|
|
60
|
+
entities?: Result.Entities;
|
|
59
61
|
/** Screenshot taken of the full page, with node rects referencing audit results. If there was an error with collection, this is null. If disabled via the disableFullPageScreenshot setting, this is undefined. */
|
|
60
62
|
fullPageScreenshot?: Result.FullPageScreenshot | null;
|
|
61
63
|
}
|
|
@@ -151,6 +153,37 @@ declare module Result {
|
|
|
151
153
|
nodes: Record<string, AuditDetails.Rect>;
|
|
152
154
|
}
|
|
153
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Entity classification for the run, for resolving URLs/items to entities in report.
|
|
158
|
+
* The two lookup tables (LUT) below provide space-optimized, O(1) index lookup into entities.list.
|
|
159
|
+
*/
|
|
160
|
+
interface Entities {
|
|
161
|
+
/** All entities (1st and 3rd party) discovered during the run */
|
|
162
|
+
list: Array<LhrEntity>;
|
|
163
|
+
/** Name of the first-party entity */
|
|
164
|
+
firstParty?: string;
|
|
165
|
+
/** Entity-name to entity index lookup table */
|
|
166
|
+
entityIndexByName: Record<string, number>;
|
|
167
|
+
/** URL origin to entity index lookup table */
|
|
168
|
+
entityIndexByOrigin: Record<string, number>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* An entity that's either recognized by third-party-web or made up by Lighthouse.
|
|
173
|
+
*/
|
|
174
|
+
interface LhrEntity {
|
|
175
|
+
/** Name of the entity. Maps to third-party-web unique name for recognized entities and a root domain name for the unrecognized. */
|
|
176
|
+
name: string;
|
|
177
|
+
/** Homepage URL for a recognized entity, if available in third-party-web. */
|
|
178
|
+
homepage?: string;
|
|
179
|
+
/** Category name that the entity belongs to, if available. */
|
|
180
|
+
category?: string;
|
|
181
|
+
/** Is this entity the first party? */
|
|
182
|
+
isFirstParty?: boolean;
|
|
183
|
+
/** Is this entity recognized by third-party-web? */
|
|
184
|
+
isUnrecognized?: boolean;
|
|
185
|
+
}
|
|
186
|
+
|
|
154
187
|
/**
|
|
155
188
|
* Info about an `LH.IcuMessage` value that was localized to a string when
|
|
156
189
|
* included in the LHR. Value is either a
|