lighthouse 12.8.2-dev.20250923 → 12.8.2-dev.20250925

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.
Files changed (74) hide show
  1. package/cli/test/smokehouse/version-check.d.ts +1 -1
  2. package/core/audits/accessibility/aria-allowed-role.js +1 -0
  3. package/core/audits/accessibility/image-redundant-alt.js +1 -0
  4. package/core/audits/accessibility/landmark-one-main.js +0 -1
  5. package/core/audits/accessibility/table-duplicate-name.js +1 -0
  6. package/core/config/default-config.js +90 -71
  7. package/core/gather/gatherers/image-elements.js +32 -6
  8. package/core/lib/emulation.d.ts +10 -0
  9. package/core/lib/emulation.js +21 -6
  10. package/core/lib/legacy-javascript/legacy-javascript.js +4 -11
  11. package/core/lib/proto-preprocessor.js +5 -3
  12. package/core/scoring.js +1 -1
  13. package/package.json +3 -4
  14. package/readme.md +1 -1
  15. package/report/renderer/details-renderer.d.ts +1 -2
  16. package/report/renderer/details-renderer.js +0 -1
  17. package/shared/localization/locales/ar-XB.json +0 -30
  18. package/shared/localization/locales/ar.json +0 -30
  19. package/shared/localization/locales/bg.json +0 -30
  20. package/shared/localization/locales/ca.json +0 -30
  21. package/shared/localization/locales/cs.json +0 -30
  22. package/shared/localization/locales/da.json +0 -30
  23. package/shared/localization/locales/de.json +0 -30
  24. package/shared/localization/locales/el.json +0 -30
  25. package/shared/localization/locales/en-GB.json +0 -30
  26. package/shared/localization/locales/en-US.json +0 -30
  27. package/shared/localization/locales/en-XA.json +0 -30
  28. package/shared/localization/locales/en-XL.json +0 -30
  29. package/shared/localization/locales/es-419.json +0 -30
  30. package/shared/localization/locales/es.json +0 -30
  31. package/shared/localization/locales/fi.json +0 -30
  32. package/shared/localization/locales/fil.json +0 -30
  33. package/shared/localization/locales/fr.json +0 -30
  34. package/shared/localization/locales/he.json +0 -30
  35. package/shared/localization/locales/hi.json +0 -30
  36. package/shared/localization/locales/hr.json +0 -30
  37. package/shared/localization/locales/hu.json +0 -30
  38. package/shared/localization/locales/id.json +0 -30
  39. package/shared/localization/locales/it.json +0 -30
  40. package/shared/localization/locales/ja.json +0 -30
  41. package/shared/localization/locales/ko.json +0 -30
  42. package/shared/localization/locales/lt.json +0 -30
  43. package/shared/localization/locales/lv.json +0 -30
  44. package/shared/localization/locales/nl.json +0 -30
  45. package/shared/localization/locales/no.json +0 -30
  46. package/shared/localization/locales/pl.json +0 -30
  47. package/shared/localization/locales/pt-PT.json +0 -30
  48. package/shared/localization/locales/pt.json +0 -30
  49. package/shared/localization/locales/ro.json +0 -30
  50. package/shared/localization/locales/ru.json +0 -30
  51. package/shared/localization/locales/sk.json +0 -30
  52. package/shared/localization/locales/sl.json +0 -30
  53. package/shared/localization/locales/sr-Latn.json +0 -30
  54. package/shared/localization/locales/sr.json +0 -30
  55. package/shared/localization/locales/sv.json +0 -30
  56. package/shared/localization/locales/ta.json +0 -30
  57. package/shared/localization/locales/te.json +0 -30
  58. package/shared/localization/locales/th.json +0 -30
  59. package/shared/localization/locales/tr.json +0 -30
  60. package/shared/localization/locales/uk.json +0 -30
  61. package/shared/localization/locales/vi.json +0 -30
  62. package/shared/localization/locales/zh-HK.json +0 -30
  63. package/shared/localization/locales/zh-TW.json +0 -30
  64. package/shared/localization/locales/zh.json +0 -30
  65. package/shared/localization/locales.d.ts +2 -0
  66. package/shared/localization/locales.js +130 -139
  67. package/shared/tsconfig.json +2 -0
  68. package/tsconfig-base.json +1 -1
  69. package/tsconfig.json +1 -1
  70. package/types/artifacts.d.ts +0 -33
  71. package/core/audits/seo/font-size.d.ts +0 -24
  72. package/core/audits/seo/font-size.js +0 -344
  73. package/core/gather/gatherers/seo/font-size.d.ts +0 -131
  74. package/core/gather/gatherers/seo/font-size.js +0 -347
@@ -1,344 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /** @typedef {LH.Artifacts.FontSize['analyzedFailingNodesData'][0]} FailingNodeData */
8
-
9
- import * as i18n from '../../lib/i18n/i18n.js';
10
- import {Audit} from '../audit.js';
11
- import {ViewportMeta} from '../../computed/viewport-meta.js';
12
-
13
- const MINIMAL_PERCENTAGE_OF_LEGIBLE_TEXT = 60;
14
-
15
- const UIStrings = {
16
- /** Title of a Lighthouse audit that provides detail on the font sizes used on the page. This descriptive title is shown to users when the fonts used on the page are large enough to be considered legible. */
17
- title: 'Document uses legible font sizes',
18
- /** Title of a Lighthouse audit that provides detail on the font sizes used on the page. This descriptive title is shown to users when there is a font that may be too small to be read by users. */
19
- failureTitle: 'Document doesn\'t use legible font sizes',
20
- /** Description of a Lighthouse audit that tells the user *why* they need to use a larger font size. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
21
- description: 'Font sizes less than 12px are too small to be legible and require mobile visitors to “pinch to zoom” in order to read. Strive to have >60% of page text ≥12px. [Learn more about legible font sizes](https://developer.chrome.com/docs/lighthouse/seo/font-size/).',
22
- /** Label for the audit identifying font sizes that are too small. */
23
- displayValue: '{decimalProportion, number, extendedPercent} legible text',
24
- /** Explanatory message stating that there was a failure in an audit caused by a missing page viewport meta tag configuration. "viewport" and "meta" are HTML terms and should not be translated. */
25
- explanationViewport: 'Text is illegible because there\'s no viewport meta tag optimized ' +
26
- 'for mobile screens.',
27
- /** Label for the table row which summarizes all failing nodes that were not fully analyzed. "Add'l" is shorthand for "Additional" */
28
- additionalIllegibleText: 'Add\'l illegible text',
29
- /** Label for the table row which displays the percentage of nodes that have proper font size. */
30
- legibleText: 'Legible text',
31
- /** Label for a column in a data table; entries will be css style rule selectors. */
32
- columnSelector: 'Selector',
33
- /** Label for a column in a data table; entries will be the percent of page text a specific CSS rule applies to. */
34
- columnPercentPageText: '% of Page Text',
35
- /** Label for a column in a data table; entries will be text font sizes. */
36
- columnFontSize: 'Font Size',
37
- };
38
-
39
- const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
40
-
41
- /**
42
- * @param {Array<FailingNodeData>} fontSizeArtifact
43
- * @return {Array<FailingNodeData>}
44
- */
45
- function getUniqueFailingRules(fontSizeArtifact) {
46
- /** @type {Map<string, FailingNodeData>} */
47
- const failingRules = new Map();
48
-
49
- fontSizeArtifact.forEach((failingNodeData) => {
50
- const {nodeId, cssRule, fontSize, textLength, parentNode} = failingNodeData;
51
- const artifactId = getFontArtifactId(cssRule, nodeId);
52
- const failingRule = failingRules.get(artifactId);
53
-
54
- if (!failingRule) {
55
- failingRules.set(artifactId, {
56
- nodeId,
57
- parentNode,
58
- cssRule,
59
- fontSize,
60
- textLength,
61
- });
62
- } else {
63
- failingRule.textLength += textLength;
64
- }
65
- });
66
-
67
- return [...failingRules.values()];
68
- }
69
-
70
- /**
71
- * @param {Array<string|undefined>=} attributes
72
- * @return {Map<string, string>}
73
- */
74
- function getAttributeMap(attributes = []) {
75
- const map = new Map();
76
-
77
- for (let i = 0; i < attributes.length; i += 2) {
78
- const name = attributes[i];
79
- const value = attributes[i + 1];
80
- if (!name || !value) continue;
81
-
82
- const normalizedValue = value.trim();
83
-
84
- if (normalizedValue) {
85
- map.set(name.toLowerCase(), normalizedValue);
86
- }
87
- }
88
-
89
- return map;
90
- }
91
-
92
- /**
93
- * TODO: return unique selector, like axe-core does, instead of just id/class/name of a single node
94
- * @param {FailingNodeData['parentNode']} parentNode
95
- * @return {string}
96
- */
97
- function getSelector(parentNode) {
98
- const attributeMap = getAttributeMap(parentNode.attributes);
99
-
100
- if (attributeMap.has('id')) {
101
- return '#' + attributeMap.get('id');
102
- } else {
103
- const attrClass = attributeMap.get('class');
104
- if (attrClass) {
105
- return '.' + attrClass.split(/\s+/).join('.');
106
- }
107
- }
108
-
109
- return parentNode.nodeName.toLowerCase();
110
- }
111
-
112
- /**
113
- * @param {FailingNodeData['parentNode']} parentNode
114
- * @return {LH.Audit.Details.NodeValue}
115
- */
116
- function nodeToTableNode(parentNode) {
117
- const attributes = parentNode.attributes || [];
118
- const attributesString = attributes.map((value, idx) =>
119
- (idx % 2 === 0) ? ` ${value}` : `="${value}"`
120
- ).join('');
121
-
122
- return {
123
- type: 'node',
124
- selector: parentNode.parentNode ? getSelector(parentNode.parentNode) : '',
125
- snippet: `<${parentNode.nodeName.toLowerCase()}${attributesString}>`,
126
- };
127
- }
128
-
129
- /**
130
- * @param {string} baseURL
131
- * @param {FailingNodeData['cssRule']} styleDeclaration
132
- * @param {FailingNodeData['parentNode']} parentNode
133
- * @return {{source: LH.Audit.Details.UrlValue | LH.Audit.Details.SourceLocationValue | LH.Audit.Details.CodeValue, selector: string | LH.Audit.Details.NodeValue}}
134
- */
135
- function findStyleRuleSource(baseURL, styleDeclaration, parentNode) {
136
- if (!styleDeclaration ||
137
- styleDeclaration.type === 'Attributes' ||
138
- styleDeclaration.type === 'Inline'
139
- ) {
140
- return {
141
- source: {type: 'url', value: baseURL},
142
- selector: nodeToTableNode(parentNode),
143
- };
144
- }
145
-
146
- if (styleDeclaration.parentRule &&
147
- styleDeclaration.parentRule.origin === 'user-agent') {
148
- return {
149
- source: {type: 'code', value: 'User Agent Stylesheet'},
150
- selector: styleDeclaration.parentRule.selectors.map(item => item.text).join(', '),
151
- };
152
- }
153
-
154
- // Combine all the selectors for the associated style rule
155
- // example: .some-selector, .other-selector {...} => `.some-selector, .other-selector`
156
- let selector = '';
157
- if (styleDeclaration.parentRule) {
158
- const rule = styleDeclaration.parentRule;
159
- selector = rule.selectors.map(item => item.text).join(', ');
160
- }
161
-
162
- if (styleDeclaration.stylesheet && !styleDeclaration.stylesheet.sourceURL) {
163
- // Dynamically injected into page.
164
- return {
165
- source: {type: 'code', value: 'dynamic'},
166
- selector,
167
- };
168
- }
169
-
170
- // !!range == has defined location in a source file (.css or .html)
171
- // sourceURL == stylesheet URL || raw value of magic `sourceURL` comment
172
- // hasSourceURL == flag that signals sourceURL is the raw value of a magic `sourceURL` comment, *not* a real resource
173
- if (styleDeclaration.stylesheet && styleDeclaration.range) {
174
- const {range, stylesheet} = styleDeclaration;
175
-
176
- // DevTools protocol does not provide the resource URL if there is a magic `sourceURL` comment.
177
- // `sourceURL` will be the raw value of the magic `sourceURL` comment, which likely refers to
178
- // a file at build time, not one that is served over the network that we could link to.
179
- const urlProvider = stylesheet.hasSourceURL ? 'comment' : 'network';
180
-
181
- let line = range.startLine;
182
- let column = range.startColumn;
183
-
184
- // Add the startLine/startColumn of the <style> element to the range, if stylesheet
185
- // is inline.
186
- // Always use the rule's location if a sourceURL magic comment is
187
- // present (`hasSourceURL` is true) - this makes the line/col relative to the start
188
- // of the style tag, which makes them relevant when the "file" is open in DevTool's
189
- // Sources panel.
190
- const addHtmlLocationOffset = stylesheet.isInline && urlProvider !== 'comment';
191
- if (addHtmlLocationOffset) {
192
- line += stylesheet.startLine;
193
- // The column the stylesheet begins on is only relevant if the rule is declared on the same line.
194
- if (range.startLine === 0) {
195
- column += stylesheet.startColumn;
196
- }
197
- }
198
-
199
- const source = Audit.makeSourceLocation(stylesheet.sourceURL, line, column);
200
- source.urlProvider = urlProvider;
201
-
202
- return {
203
- source,
204
- selector,
205
- };
206
- }
207
-
208
- // The responsible style declaration was not captured in the font-size gatherer due to
209
- // the rate limiting we do in `fetchFailingNodeSourceRules`.
210
- return {
211
- selector,
212
- source: {type: 'code', value: 'Unknown'},
213
- };
214
- }
215
-
216
- /**
217
- * @param {FailingNodeData['cssRule']} styleDeclaration
218
- * @param {number} textNodeId
219
- * @return {string}
220
- */
221
- function getFontArtifactId(styleDeclaration, textNodeId) {
222
- if (styleDeclaration && styleDeclaration.type === 'Regular') {
223
- const startLine = styleDeclaration.range ? styleDeclaration.range.startLine : 0;
224
- const startColumn = styleDeclaration.range ? styleDeclaration.range.startColumn : 0;
225
- return `${styleDeclaration.styleSheetId}@${startLine}:${startColumn}`;
226
- } else {
227
- return `node_${textNodeId}`;
228
- }
229
- }
230
-
231
- class FontSize extends Audit {
232
- /**
233
- * @return {LH.Audit.Meta}
234
- */
235
- static get meta() {
236
- return {
237
- id: 'font-size',
238
- title: str_(UIStrings.title),
239
- failureTitle: str_(UIStrings.failureTitle),
240
- description: str_(UIStrings.description),
241
- requiredArtifacts: ['FontSize', 'URL', 'MetaElements'],
242
- };
243
- }
244
-
245
- /**
246
- * @param {LH.Artifacts} artifacts
247
- * @param {LH.Audit.Context} context
248
- * @return {Promise<LH.Audit.Product>}
249
- */
250
- static async audit(artifacts, context) {
251
- if (context.settings.formFactor === 'desktop') {
252
- // Font size isn't important to desktop SEO
253
- return {
254
- score: 1,
255
- notApplicable: true,
256
- };
257
- }
258
-
259
- const viewportMeta = await ViewportMeta.request(artifacts.MetaElements, context);
260
- if (!viewportMeta.isMobileOptimized) {
261
- return {
262
- score: 0,
263
- explanation: str_(UIStrings.explanationViewport),
264
- };
265
- }
266
-
267
- const {
268
- analyzedFailingNodesData,
269
- analyzedFailingTextLength,
270
- failingTextLength,
271
- totalTextLength,
272
- } = artifacts.FontSize;
273
-
274
- if (totalTextLength === 0) {
275
- return {
276
- score: 1,
277
- };
278
- }
279
-
280
- const failingRules = getUniqueFailingRules(analyzedFailingNodesData);
281
- const percentageOfPassingText =
282
- (totalTextLength - failingTextLength) / totalTextLength * 100;
283
- const pageUrl = artifacts.URL.finalDisplayedUrl;
284
-
285
- /** @type {LH.Audit.Details.Table['headings']} */
286
- const headings = [
287
- {key: 'source', valueType: 'source-location', label: str_(i18n.UIStrings.columnSource)},
288
- {key: 'selector', valueType: 'code', label: str_(UIStrings.columnSelector)},
289
- {key: 'coverage', valueType: 'text', label: str_(UIStrings.columnPercentPageText)},
290
- {key: 'fontSize', valueType: 'text', label: str_(UIStrings.columnFontSize)},
291
- ];
292
-
293
- const tableData = failingRules.sort((a, b) => b.textLength - a.textLength)
294
- .map(({cssRule, textLength, fontSize, parentNode}) => {
295
- const percentageOfAffectedText = textLength / totalTextLength * 100;
296
- const origin = findStyleRuleSource(pageUrl, cssRule, parentNode);
297
-
298
- return {
299
- source: origin.source,
300
- selector: origin.selector,
301
- coverage: `${percentageOfAffectedText.toFixed(2)}%`,
302
- fontSize: `${fontSize}px`,
303
- };
304
- });
305
-
306
- // all failing nodes that were not fully analyzed will be displayed in a single row
307
- if (analyzedFailingTextLength < failingTextLength) {
308
- const percentageOfUnanalyzedFailingText =
309
- (failingTextLength - analyzedFailingTextLength) / totalTextLength * 100;
310
-
311
- tableData.push({
312
- // Overrides default `source-location`
313
- source: {type: 'code', value: str_(UIStrings.additionalIllegibleText)},
314
- selector: '',
315
- coverage: `${percentageOfUnanalyzedFailingText.toFixed(2)}%`,
316
- fontSize: '< 12px',
317
- });
318
- }
319
-
320
- if (percentageOfPassingText > 0) {
321
- tableData.push({
322
- // Overrides default `source-location`
323
- source: {type: 'code', value: str_(UIStrings.legibleText)},
324
- selector: '',
325
- coverage: `${percentageOfPassingText.toFixed(2)}%`,
326
- fontSize: '≥ 12px',
327
- });
328
- }
329
-
330
- const decimalProportion = (percentageOfPassingText / 100);
331
- const displayValue = str_(UIStrings.displayValue, {decimalProportion});
332
- const details = Audit.makeTableDetails(headings, tableData);
333
- const passed = percentageOfPassingText >= MINIMAL_PERCENTAGE_OF_LEGIBLE_TEXT;
334
-
335
- return {
336
- score: Number(passed),
337
- details,
338
- displayValue,
339
- };
340
- }
341
- }
342
-
343
- export default FontSize;
344
- export {UIStrings};
@@ -1,131 +0,0 @@
1
- export default FontSize;
2
- export type NodeFontData = LH.Artifacts.FontSize["analyzedFailingNodesData"][0];
3
- export type BackendIdsToFontData = Map<number, {
4
- fontSize: number;
5
- textLength: number;
6
- }>;
7
- declare class FontSize extends BaseGatherer {
8
- /**
9
- * @param {LH.Gatherer.ProtocolSession} session
10
- * @param {Array<NodeFontData>} failingNodes
11
- */
12
- static fetchFailingNodeSourceRules(session: LH.Gatherer.ProtocolSession, failingNodes: Array<NodeFontData>): Promise<{
13
- analyzedFailingNodesData: {
14
- nodeId: number;
15
- fontSize: number;
16
- textLength: number;
17
- parentNode: {
18
- backendNodeId: number;
19
- attributes: string[];
20
- nodeName: string;
21
- parentNode?: {
22
- backendNodeId: number;
23
- attributes: string[];
24
- nodeName: string;
25
- };
26
- };
27
- cssRule?: {
28
- type: "Regular" | "Inline" | "Attributes";
29
- range?: {
30
- startLine: number;
31
- startColumn: number;
32
- };
33
- parentRule?: {
34
- origin: import("devtools-protocol").Protocol.CSS.StyleSheetOrigin;
35
- selectors: {
36
- text: string;
37
- }[];
38
- };
39
- styleSheetId?: string;
40
- stylesheet?: import("devtools-protocol").Protocol.CSS.CSSStyleSheetHeader;
41
- cssProperties?: Array<import("devtools-protocol").Protocol.CSS.CSSProperty>;
42
- };
43
- }[];
44
- analyzedFailingTextLength: number;
45
- }>;
46
- /**
47
- * Returns the TextNodes in a DOM Snapshot.
48
- * Every entry is associated with a TextNode in the layout tree (not display: none).
49
- * @param {LH.Crdp.DOMSnapshot.CaptureSnapshotResponse} snapshot
50
- */
51
- getTextNodesInLayoutFromSnapshot(snapshot: LH.Crdp.DOMSnapshot.CaptureSnapshotResponse): {
52
- nodeIndex: number;
53
- backendNodeId: number;
54
- fontSize: number;
55
- visibility: string;
56
- textLength: number;
57
- parentNode: {
58
- parentNode: {
59
- backendNodeId: number;
60
- attributes: string[];
61
- nodeName: string;
62
- } | undefined;
63
- backendNodeId: number;
64
- attributes: string[];
65
- nodeName: string;
66
- };
67
- }[];
68
- /**
69
- * Get all the failing text nodes that don't meet the legible text threshold.
70
- * @param {LH.Crdp.DOMSnapshot.CaptureSnapshotResponse} snapshot
71
- */
72
- findFailingNodes(snapshot: LH.Crdp.DOMSnapshot.CaptureSnapshotResponse): {
73
- totalTextLength: number;
74
- failingTextLength: number;
75
- failingNodes: {
76
- nodeId: number;
77
- fontSize: number;
78
- textLength: number;
79
- parentNode: {
80
- backendNodeId: number;
81
- attributes: string[];
82
- nodeName: string;
83
- parentNode?: {
84
- backendNodeId: number;
85
- attributes: string[];
86
- nodeName: string;
87
- };
88
- };
89
- cssRule?: {
90
- type: "Regular" | "Inline" | "Attributes";
91
- range?: {
92
- startLine: number;
93
- startColumn: number;
94
- };
95
- parentRule?: {
96
- origin: import("devtools-protocol").Protocol.CSS.StyleSheetOrigin;
97
- selectors: {
98
- text: string;
99
- }[];
100
- };
101
- styleSheetId?: string;
102
- stylesheet?: import("devtools-protocol").Protocol.CSS.CSSStyleSheetHeader;
103
- cssProperties?: Array<import("devtools-protocol").Protocol.CSS.CSSProperty>;
104
- };
105
- }[];
106
- };
107
- /**
108
- * @param {LH.Gatherer.Context} passContext
109
- * @return {Promise<LH.Artifacts.FontSize>} font-size analysis
110
- */
111
- getArtifact(passContext: LH.Gatherer.Context): Promise<LH.Artifacts.FontSize>;
112
- }
113
- /**
114
- * Returns the governing/winning CSS font-size rule for the set of styles given.
115
- * This is roughly a stripped down version of the CSSMatchedStyle class in DevTools.
116
- *
117
- * @see https://cs.chromium.org/chromium/src/third_party/blink/renderer/devtools/front_end/sdk/CSSMatchedStyles.js?q=CSSMatchedStyles+f:devtools+-f:out&sq=package:chromium&dr=C&l=59-134
118
- * @param {LH.Crdp.CSS.GetMatchedStylesForNodeResponse} matched CSS rules
119
- * @return {NodeFontData['cssRule']|undefined}
120
- */
121
- export function getEffectiveFontRule({ attributesStyle, inlineStyle, matchedCSSRules, inherited }: LH.Crdp.CSS.GetMatchedStylesForNodeResponse): NodeFontData["cssRule"] | undefined;
122
- /**
123
- * Finds the most specific directly matched CSS font-size rule from the list.
124
- *
125
- * @param {Array<LH.Crdp.CSS.RuleMatch>} matchedCSSRules
126
- * @param {function(LH.Crdp.CSS.CSSStyle):boolean|string|undefined} isDeclarationOfInterest
127
- * @return {NodeFontData['cssRule']|undefined}
128
- */
129
- export function findMostSpecificMatchedCSSRule(matchedCSSRules: Array<LH.Crdp.CSS.RuleMatch> | undefined, isDeclarationOfInterest: (arg0: LH.Crdp.CSS.CSSStyle) => boolean | string | undefined): NodeFontData["cssRule"] | undefined;
130
- import BaseGatherer from '../../base-gatherer.js';
131
- //# sourceMappingURL=font-size.d.ts.map