lighthouse 11.7.0-dev.20240331 → 11.7.0-dev.20240402

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 (72) hide show
  1. package/cli/test/smokehouse/core-tests.js +0 -2
  2. package/core/audits/byte-efficiency/byte-efficiency-audit.d.ts +0 -16
  3. package/core/audits/byte-efficiency/byte-efficiency-audit.js +1 -38
  4. package/core/audits/byte-efficiency/offscreen-images.d.ts +0 -11
  5. package/core/audits/byte-efficiency/offscreen-images.js +0 -15
  6. package/core/audits/dobetterweb/uses-http2.d.ts +0 -13
  7. package/core/audits/dobetterweb/uses-http2.js +2 -34
  8. package/core/audits/seo/is-crawlable.d.ts +2 -1
  9. package/core/computed/page-dependency-graph.js +2 -1
  10. package/core/config/default-config.js +1 -6
  11. package/core/gather/gatherers/accessibility.js +1 -3
  12. package/core/lib/lantern/page-dependency-graph.d.ts +4 -4
  13. package/core/lib/lantern/page-dependency-graph.js +5 -5
  14. package/core/lib/proto-preprocessor.js +24 -8
  15. package/dist/report/flow.js +14 -14
  16. package/flow-report/src/summary/category.tsx +10 -12
  17. package/package.json +1 -1
  18. package/shared/localization/locales/ar-XB.json +0 -30
  19. package/shared/localization/locales/ar.json +0 -30
  20. package/shared/localization/locales/bg.json +0 -30
  21. package/shared/localization/locales/ca.json +0 -30
  22. package/shared/localization/locales/cs.json +0 -30
  23. package/shared/localization/locales/da.json +0 -30
  24. package/shared/localization/locales/de.json +0 -30
  25. package/shared/localization/locales/el.json +0 -30
  26. package/shared/localization/locales/en-GB.json +0 -30
  27. package/shared/localization/locales/en-US.json +0 -30
  28. package/shared/localization/locales/en-XA.json +0 -30
  29. package/shared/localization/locales/en-XL.json +0 -30
  30. package/shared/localization/locales/es-419.json +0 -30
  31. package/shared/localization/locales/es.json +0 -30
  32. package/shared/localization/locales/fi.json +0 -30
  33. package/shared/localization/locales/fil.json +0 -30
  34. package/shared/localization/locales/fr.json +0 -30
  35. package/shared/localization/locales/he.json +0 -30
  36. package/shared/localization/locales/hi.json +0 -30
  37. package/shared/localization/locales/hr.json +0 -30
  38. package/shared/localization/locales/hu.json +0 -30
  39. package/shared/localization/locales/id.json +0 -30
  40. package/shared/localization/locales/it.json +0 -30
  41. package/shared/localization/locales/ja.json +0 -30
  42. package/shared/localization/locales/ko.json +0 -30
  43. package/shared/localization/locales/lt.json +0 -30
  44. package/shared/localization/locales/lv.json +0 -30
  45. package/shared/localization/locales/nl.json +0 -30
  46. package/shared/localization/locales/no.json +0 -30
  47. package/shared/localization/locales/pl.json +0 -30
  48. package/shared/localization/locales/pt-PT.json +0 -30
  49. package/shared/localization/locales/pt.json +0 -30
  50. package/shared/localization/locales/ro.json +0 -30
  51. package/shared/localization/locales/ru.json +0 -30
  52. package/shared/localization/locales/sk.json +0 -30
  53. package/shared/localization/locales/sl.json +0 -30
  54. package/shared/localization/locales/sr-Latn.json +0 -30
  55. package/shared/localization/locales/sr.json +0 -30
  56. package/shared/localization/locales/sv.json +0 -30
  57. package/shared/localization/locales/ta.json +0 -30
  58. package/shared/localization/locales/te.json +0 -30
  59. package/shared/localization/locales/th.json +0 -30
  60. package/shared/localization/locales/tr.json +0 -30
  61. package/shared/localization/locales/uk.json +0 -30
  62. package/shared/localization/locales/vi.json +0 -30
  63. package/shared/localization/locales/zh-HK.json +0 -30
  64. package/shared/localization/locales/zh-TW.json +0 -30
  65. package/shared/localization/locales/zh.json +0 -30
  66. package/types/lhr/audit-details.d.ts +9 -4
  67. package/core/audits/accessibility/duplicate-id-active.d.ts +0 -10
  68. package/core/audits/accessibility/duplicate-id-active.js +0 -42
  69. package/core/audits/seo/tap-targets.d.ts +0 -50
  70. package/core/audits/seo/tap-targets.js +0 -352
  71. package/core/gather/gatherers/seo/tap-targets.d.ts +0 -21
  72. package/core/gather/gatherers/seo/tap-targets.js +0 -389
@@ -1,352 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2018 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /**
8
- * @fileoverview Checks that links, buttons, etc. are sufficiently large and that there's
9
- * no other tap target that's too close so that the user might accidentally tap on.
10
- */
11
-
12
- import {Audit} from '../audit.js';
13
- import {ViewportMeta} from '../../computed/viewport-meta.js';
14
- import {
15
- rectsTouchOrOverlap,
16
- getRectOverlapArea,
17
- getRectAtCenter,
18
- allRectsContainedWithinEachOther,
19
- getLargestRect,
20
- getBoundingRectWithPadding,
21
- } from '../../lib/rect-helpers.js';
22
- import {getTappableRectsFromClientRects} from '../../lib/tappable-rects.js';
23
- import * as i18n from '../../lib/i18n/i18n.js';
24
-
25
- const UIStrings = {
26
- /** Title of a Lighthouse audit that provides detail on whether tap targets (like buttons and links) on a page are big enough so they can easily be tapped on a mobile device. This descriptive title is shown when tap targets are easy to tap on. */
27
- title: 'Tap targets are sized appropriately',
28
- /** Descriptive title of a Lighthouse audit that provides detail on whether tap targets (like buttons and links) on a page are big enough so they can easily be tapped on a mobile device. This descriptive title is shown when tap targets are not easy to tap on. */
29
- failureTitle: 'Tap targets are not sized appropriately',
30
- /** Description of a Lighthouse audit that tells the user why buttons and links need to be big enough and what 'big enough' means. 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. */
31
- description: 'Interactive elements like buttons and links should be large enough (48x48px), or have enough space around them, to be easy enough to tap without overlapping onto other elements. [Learn more about tap targets](https://developer.chrome.com/docs/lighthouse/seo/tap-targets/).',
32
- /** Label of a table column that identifies tap targets (like buttons and links) that have failed the audit and aren't easy to tap on. */
33
- tapTargetHeader: 'Tap Target',
34
- /** Label of a table column that identifies a tap target (like a link or button) that overlaps with another tap target. */
35
- overlappingTargetHeader: 'Overlapping Target',
36
- /** Explanatory message stating that there was a failure in an audit caused by the viewport meta tag not being optimized for mobile screens, which caused tap targets like buttons and links to be too small to tap on. */
37
- /* eslint-disable-next-line max-len */
38
- explanationViewportMetaNotOptimized: 'Tap targets are too small because there\'s no viewport meta tag optimized for mobile screens',
39
- /** Explanatory message stating that a certain percentage of the tap targets (like buttons and links) on the page are of an appropriately large size. */
40
- displayValue: '{decimalProportion, number, percent} appropriately sized tap targets',
41
- };
42
-
43
- const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
44
-
45
- const FINGER_SIZE_PX = 48;
46
- // Ratio of the finger area tapping on an unintended element
47
- // to the finger area tapping on the intended element
48
- const MAX_ACCEPTABLE_OVERLAP_SCORE_RATIO = 0.25;
49
-
50
- /**
51
- * Returns a tap target augmented with a bounding rect for quick overlapping
52
- * rejections. Rect contains all the client rects, padded to half FINGER_SIZE_PX.
53
- * @param {LH.Artifacts.TapTarget[]} targets
54
- * @return {BoundedTapTarget[]}
55
- */
56
- function getBoundedTapTargets(targets) {
57
- return targets.map(tapTarget => {
58
- return {
59
- tapTarget,
60
- paddedBoundsRect: getBoundingRectWithPadding(tapTarget.clientRects, FINGER_SIZE_PX),
61
- };
62
- });
63
- }
64
-
65
- /**
66
- * @param {LH.Artifacts.Rect} cr
67
- */
68
- function clientRectBelowMinimumSize(cr) {
69
- return cr.width < FINGER_SIZE_PX || cr.height < FINGER_SIZE_PX;
70
- }
71
-
72
- /**
73
- * A target is "too small" if none of its clientRects are at least the size of a finger.
74
- * @param {BoundedTapTarget[]} targets
75
- * @return {BoundedTapTarget[]}
76
- */
77
- function getTooSmallTargets(targets) {
78
- return targets.filter(target => {
79
- return target.tapTarget.clientRects.every(clientRectBelowMinimumSize);
80
- });
81
- }
82
-
83
- /**
84
- * @param {BoundedTapTarget[]} tooSmallTargets
85
- * @param {BoundedTapTarget[]} allTargets
86
- * @return {TapTargetOverlapFailure[]}
87
- */
88
- function getAllOverlapFailures(tooSmallTargets, allTargets) {
89
- /** @type {TapTargetOverlapFailure[]} */
90
- const failures = [];
91
-
92
- tooSmallTargets.forEach(target => {
93
- // Convert client rects to unique tappable areas from a user's perspective
94
- const tappableRects = getTappableRectsFromClientRects(target.tapTarget.clientRects);
95
-
96
- for (const maybeOverlappingTarget of allTargets) {
97
- if (maybeOverlappingTarget === target) {
98
- // Checking the same target with itself, skip.
99
- continue;
100
- }
101
-
102
- if (!rectsTouchOrOverlap(target.paddedBoundsRect, maybeOverlappingTarget.paddedBoundsRect)) {
103
- // Bounding boxes (padded with half FINGER_SIZE_PX) don't overlap, skip.
104
- continue;
105
- }
106
-
107
- if (target.tapTarget.href === maybeOverlappingTarget.tapTarget.href) {
108
- const isHttpOrHttpsLink = /https?:\/\//.test(target.tapTarget.href);
109
- if (isHttpOrHttpsLink) {
110
- // No overlap because same target action, skip.
111
- continue;
112
- }
113
- }
114
-
115
- const maybeOverlappingRects = maybeOverlappingTarget.tapTarget.clientRects;
116
- if (allRectsContainedWithinEachOther(tappableRects, maybeOverlappingRects)) {
117
- // If one tap target is fully contained within the other that's
118
- // probably intentional (e.g. an item with a delete button inside).
119
- // We'll miss some problems because of this, but that's better
120
- // than falsely reporting a failure.
121
- continue;
122
- }
123
-
124
- const rectFailure = getOverlapFailureForTargetPair(tappableRects, maybeOverlappingRects);
125
- if (rectFailure) {
126
- failures.push({
127
- ...rectFailure,
128
- tapTarget: target.tapTarget,
129
- overlappingTarget: maybeOverlappingTarget.tapTarget,
130
- });
131
- }
132
- }
133
- });
134
-
135
- return failures;
136
- }
137
-
138
- /**
139
- * @param {LH.Artifacts.Rect[]} tappableRects
140
- * @param {LH.Artifacts.Rect[]} maybeOverlappingRects
141
- * @return {ClientRectOverlapFailure | null}
142
- */
143
- function getOverlapFailureForTargetPair(tappableRects, maybeOverlappingRects) {
144
- /** @type ClientRectOverlapFailure | null */
145
- let greatestFailure = null;
146
-
147
- for (const targetCR of tappableRects) {
148
- const fingerRect = getRectAtCenter(targetCR, FINGER_SIZE_PX);
149
- // Score indicates how much of the finger area overlaps each target when the user
150
- // taps on the center of targetCR
151
- const tapTargetScore = getRectOverlapArea(fingerRect, targetCR);
152
-
153
- for (const maybeOverlappingCR of maybeOverlappingRects) {
154
- const overlappingTargetScore = getRectOverlapArea(fingerRect, maybeOverlappingCR);
155
-
156
- const overlapScoreRatio = overlappingTargetScore / tapTargetScore;
157
- if (overlapScoreRatio < MAX_ACCEPTABLE_OVERLAP_SCORE_RATIO) {
158
- // low score means it's clear that the user tried to tap on the targetCR,
159
- // rather than the other tap target client rect
160
- continue;
161
- }
162
-
163
- // only update our state if this was the biggest failure we've seen for this pair
164
- if (!greatestFailure || overlapScoreRatio > greatestFailure.overlapScoreRatio) {
165
- greatestFailure = {
166
- overlapScoreRatio,
167
- tapTargetScore,
168
- overlappingTargetScore,
169
- };
170
- }
171
- }
172
- }
173
- return greatestFailure;
174
- }
175
-
176
- /**
177
- * Only report one failure if two targets overlap each other
178
- * @param {TapTargetOverlapFailure[]} overlapFailures
179
- * @return {TapTargetOverlapFailure[]}
180
- */
181
- function mergeSymmetricFailures(overlapFailures) {
182
- /** @type TapTargetOverlapFailure[] */
183
- const failuresAfterMerging = [];
184
-
185
- overlapFailures.forEach((failure, overlapFailureIndex) => {
186
- const symmetricFailure = overlapFailures.find(f =>
187
- f.tapTarget === failure.overlappingTarget &&
188
- f.overlappingTarget === failure.tapTarget
189
- );
190
-
191
- if (!symmetricFailure) {
192
- failuresAfterMerging.push(failure);
193
- return;
194
- }
195
-
196
- const {overlapScoreRatio: failureOSR} = failure;
197
- const {overlapScoreRatio: symmetricOSR} = symmetricFailure;
198
- // Push if:
199
- // - the current failure has a higher OSR
200
- // - OSRs are the same, and the current failure comes before its symmetric partner in the list
201
- // Otherwise do nothing and let the symmetric partner be pushed later.
202
- if (failureOSR > symmetricOSR || (
203
- failureOSR === symmetricOSR &&
204
- overlapFailureIndex < overlapFailures.indexOf(symmetricFailure)
205
- )) {
206
- failuresAfterMerging.push(failure);
207
- }
208
- });
209
-
210
- return failuresAfterMerging;
211
- }
212
-
213
- /**
214
- * @param {TapTargetOverlapFailure[]} overlapFailures
215
- * @return {TapTargetTableItem[]}
216
- */
217
- function getTableItems(overlapFailures) {
218
- const tableItems = overlapFailures.map(failure => {
219
- const largestCR = getLargestRect(failure.tapTarget.clientRects);
220
- const width = Math.floor(largestCR.width);
221
- const height = Math.floor(largestCR.height);
222
- const size = width + 'x' + height;
223
- return {
224
- tapTarget: Audit.makeNodeItem(failure.tapTarget.node),
225
- overlappingTarget: Audit.makeNodeItem(failure.overlappingTarget.node),
226
- tapTargetScore: failure.tapTargetScore,
227
- overlappingTargetScore: failure.overlappingTargetScore,
228
- overlapScoreRatio: failure.overlapScoreRatio,
229
- size,
230
- width,
231
- height,
232
- };
233
- });
234
-
235
- tableItems.sort((a, b) => {
236
- return b.overlapScoreRatio - a.overlapScoreRatio;
237
- });
238
-
239
- return tableItems;
240
- }
241
-
242
- class TapTargets extends Audit {
243
- /**
244
- * @return {LH.Audit.Meta}
245
- */
246
- static get meta() {
247
- return {
248
- id: 'tap-targets',
249
- title: str_(UIStrings.title),
250
- failureTitle: str_(UIStrings.failureTitle),
251
- description: str_(UIStrings.description),
252
- requiredArtifacts: ['MetaElements', 'TapTargets'],
253
- };
254
- }
255
-
256
- /**
257
- * @param {LH.Artifacts} artifacts
258
- * @param {LH.Audit.Context} context
259
- * @return {Promise<LH.Audit.Product>}
260
- */
261
- static async audit(artifacts, context) {
262
- if (context.settings.formFactor === 'desktop') {
263
- // Tap target sizes aren't important for desktop SEO, so disable the audit there.
264
- // On desktop people also tend to have more precise pointing devices than fingers.
265
- return {
266
- score: 1,
267
- notApplicable: true,
268
- };
269
- }
270
-
271
- const viewportMeta = await ViewportMeta.request(artifacts.MetaElements, context);
272
- if (!viewportMeta.isMobileOptimized) {
273
- return {
274
- score: 0,
275
- explanation: str_(UIStrings.explanationViewportMetaNotOptimized),
276
- };
277
- }
278
-
279
- // Augment the targets with padded bounding rects for quick intersection testing.
280
- const boundedTapTargets = getBoundedTapTargets(artifacts.TapTargets);
281
-
282
- const tooSmallTargets = getTooSmallTargets(boundedTapTargets);
283
- const overlapFailures = getAllOverlapFailures(tooSmallTargets, boundedTapTargets);
284
- const overlapFailuresForDisplay = mergeSymmetricFailures(overlapFailures);
285
- const tableItems = getTableItems(overlapFailuresForDisplay);
286
-
287
- /** @type {LH.Audit.Details.Table['headings']} */
288
- const headings = [
289
- {key: 'tapTarget', valueType: 'node', label: str_(UIStrings.tapTargetHeader)},
290
- {key: 'size', valueType: 'text', label: str_(i18n.UIStrings.columnSize)},
291
- {key: 'overlappingTarget', valueType: 'node', label: str_(UIStrings.overlappingTargetHeader)},
292
- ];
293
-
294
- const details = Audit.makeTableDetails(headings, tableItems);
295
-
296
- const tapTargetCount = artifacts.TapTargets.length;
297
- const failingTapTargetCount = new Set(overlapFailures.map(f => f.tapTarget)).size;
298
- const passingTapTargetCount = tapTargetCount - failingTapTargetCount;
299
-
300
- let score = 1;
301
- let passingTapTargetRatio = 1;
302
- if (failingTapTargetCount > 0) {
303
- passingTapTargetRatio = (passingTapTargetCount / tapTargetCount);
304
- // If there are any failures then we don't want the audit to pass,
305
- // so keep the score below 90.
306
- score = passingTapTargetRatio * 0.89;
307
- }
308
- const displayValue = str_(UIStrings.displayValue, {decimalProportion: passingTapTargetRatio});
309
-
310
- return {
311
- score,
312
- details,
313
- displayValue,
314
- };
315
- }
316
- }
317
-
318
- TapTargets.FINGER_SIZE_PX = FINGER_SIZE_PX;
319
-
320
- export default TapTargets;
321
- export {UIStrings};
322
-
323
-
324
- /** @typedef {{
325
- overlapScoreRatio: number;
326
- tapTargetScore: number;
327
- overlappingTargetScore: number;
328
- }} ClientRectOverlapFailure */
329
-
330
- /** @typedef {{
331
- overlapScoreRatio: number;
332
- tapTargetScore: number;
333
- overlappingTargetScore: number;
334
- tapTarget: LH.Artifacts.TapTarget;
335
- overlappingTarget: LH.Artifacts.TapTarget;
336
- }} TapTargetOverlapFailure */
337
-
338
- /** @typedef {{
339
- paddedBoundsRect: LH.Artifacts.Rect;
340
- tapTarget: LH.Artifacts.TapTarget;
341
- }} BoundedTapTarget */
342
-
343
- /** @typedef {{
344
- tapTarget: LH.Audit.Details.NodeValue;
345
- overlappingTarget: LH.Audit.Details.NodeValue;
346
- size: string;
347
- overlapScoreRatio: number;
348
- height: number;
349
- width: number;
350
- tapTargetScore: number;
351
- overlappingTargetScore: number;
352
- }} TapTargetTableItem */
@@ -1,21 +0,0 @@
1
- export default TapTargets;
2
- declare class TapTargets extends BaseGatherer {
3
- /**
4
- * @param {LH.Gatherer.ProtocolSession} session
5
- * @param {string} className
6
- * @return {Promise<string>}
7
- */
8
- addStyleRule(session: LH.Gatherer.ProtocolSession, className: string): Promise<string>;
9
- /**
10
- * @param {LH.Gatherer.ProtocolSession} session
11
- * @param {string} styleSheetId
12
- */
13
- removeStyleRule(session: LH.Gatherer.ProtocolSession, styleSheetId: string): Promise<void>;
14
- /**
15
- * @param {LH.Gatherer.Context} passContext
16
- * @return {Promise<LH.Artifacts.TapTarget[]>} All visible tap targets with their positions and sizes
17
- */
18
- getArtifact(passContext: LH.Gatherer.Context): Promise<LH.Artifacts.TapTarget[]>;
19
- }
20
- import BaseGatherer from '../../base-gatherer.js';
21
- //# sourceMappingURL=tap-targets.d.ts.map