lighthouse 11.7.0-dev.20240331 → 11.7.0-dev.20240401

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 (71) 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/dist/report/flow.js +14 -14
  15. package/flow-report/src/summary/category.tsx +10 -12
  16. package/package.json +1 -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/types/lhr/audit-details.d.ts +9 -4
  66. package/core/audits/accessibility/duplicate-id-active.d.ts +0 -10
  67. package/core/audits/accessibility/duplicate-id-active.js +0 -42
  68. package/core/audits/seo/tap-targets.d.ts +0 -50
  69. package/core/audits/seo/tap-targets.js +0 -352
  70. package/core/gather/gatherers/seo/tap-targets.d.ts +0 -21
  71. package/core/gather/gatherers/seo/tap-targets.js +0 -389
@@ -1,389 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2018 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /* global document, window, getComputedStyle, getElementsInDocument, Node, getNodeDetails, getRectCenterPoint */
8
-
9
- import BaseGatherer from '../../base-gatherer.js';
10
- import {pageFunctions} from '../../../lib/page-functions.js';
11
- import * as RectHelpers from '../../../lib/rect-helpers.js';
12
-
13
- const TARGET_SELECTORS = [
14
- 'button',
15
- 'a',
16
- 'input',
17
- 'textarea',
18
- 'select',
19
- 'option',
20
- '[role=button]',
21
- '[role=checkbox]',
22
- '[role=link]',
23
- '[role=menuitem]',
24
- '[role=menuitemcheckbox]',
25
- '[role=menuitemradio]',
26
- '[role=option]',
27
- '[role=scrollbar]',
28
- '[role=slider]',
29
- '[role=spinbutton]',
30
- ];
31
- const tapTargetsSelector = TARGET_SELECTORS.join(',');
32
-
33
- /**
34
- * @param {HTMLElement} element
35
- * @return {boolean}
36
- */
37
- /* c8 ignore start */
38
- function elementIsVisible(element) {
39
- return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
40
- }
41
- /* c8 ignore stop */
42
-
43
- /**
44
- * @param {Element} element
45
- * @return {LH.Artifacts.Rect[]}
46
- */
47
- /* c8 ignore start */
48
- function getClientRects(element) {
49
- const clientRects = Array.from(
50
- element.getClientRects()
51
- ).map(clientRect => {
52
- // Contents of DOMRect get lost when returned from Runtime.evaluate call,
53
- // so we convert them to plain objects.
54
- const {width, height, left, top, right, bottom} = clientRect;
55
- return {width, height, left, top, right, bottom};
56
- });
57
-
58
- for (const child of element.children) {
59
- clientRects.push(...getClientRects(child));
60
- }
61
-
62
- return clientRects;
63
- }
64
- /* c8 ignore stop */
65
-
66
- /**
67
- * @param {Element} element
68
- * @param {string} tapTargetsSelector
69
- * @return {boolean}
70
- */
71
- /* c8 ignore start */
72
- function elementHasAncestorTapTarget(element, tapTargetsSelector) {
73
- if (!element.parentElement) {
74
- return false;
75
- }
76
- if (element.parentElement.matches(tapTargetsSelector)) {
77
- return true;
78
- }
79
- return elementHasAncestorTapTarget(element.parentElement, tapTargetsSelector);
80
- }
81
- /* c8 ignore stop */
82
-
83
- /**
84
- * @param {Element} element
85
- */
86
- /* c8 ignore start */
87
- function hasTextNodeSiblingsFormingTextBlock(element) {
88
- if (!element.parentElement) {
89
- return false;
90
- }
91
-
92
- const parentElement = element.parentElement;
93
-
94
- const nodeText = element.textContent || '';
95
- const parentText = parentElement.textContent || '';
96
- if (parentText.length - nodeText.length < 5) {
97
- // Parent text mostly consists of this node, so the parent
98
- // is not a text block container
99
- return false;
100
- }
101
-
102
- for (const sibling of element.parentElement.childNodes) {
103
- if (sibling === element) {
104
- continue;
105
- }
106
- const siblingTextContent = (sibling.textContent || '').trim();
107
- // Only count text in text nodes so that a series of e.g. buttons isn't counted
108
- // as a text block.
109
- // This works reasonably well, but means we miss text blocks where all text is e.g.
110
- // wrapped in spans
111
- if (sibling.nodeType === Node.TEXT_NODE && siblingTextContent.length > 0) {
112
- return true;
113
- }
114
- }
115
-
116
- return false;
117
- }
118
- /* c8 ignore stop */
119
-
120
- /**
121
- * Check if element is in a block of text, such as paragraph with a bunch of links in it.
122
- * Makes a reasonable guess, but for example gets it wrong if the element is surrounded by other
123
- * HTML elements instead of direct text nodes.
124
- * @param {Element} element
125
- * @return {boolean}
126
- */
127
- /* c8 ignore start */
128
- function elementIsInTextBlock(element) {
129
- const {display} = getComputedStyle(element);
130
- if (display !== 'inline' && display !== 'inline-block') {
131
- return false;
132
- }
133
-
134
- if (hasTextNodeSiblingsFormingTextBlock(element)) {
135
- return true;
136
- } else if (element.parentElement) {
137
- return elementIsInTextBlock(element.parentElement);
138
- } else {
139
- return false;
140
- }
141
- }
142
- /* c8 ignore stop */
143
-
144
- /**
145
- * @param {Element} el
146
- * @param {{x: number, y: number}} elCenterPoint
147
- */
148
- /* c8 ignore start */
149
- function elementCenterIsAtZAxisTop(el, elCenterPoint) {
150
- const viewportHeight = window.innerHeight;
151
- const targetScrollY = Math.floor(elCenterPoint.y / viewportHeight) * viewportHeight;
152
- if (window.scrollY !== targetScrollY) {
153
- window.scrollTo(0, targetScrollY);
154
- }
155
-
156
- const topEl = document.elementFromPoint(
157
- elCenterPoint.x,
158
- elCenterPoint.y - window.scrollY
159
- );
160
-
161
- return topEl === el || el.contains(topEl);
162
- }
163
- /* c8 ignore stop */
164
-
165
- /**
166
- * Finds all position sticky/absolute elements on the page and adds a class
167
- * that disables pointer events on them.
168
- * @param {string} className
169
- * @return {() => void} - undo function to re-enable pointer events
170
- */
171
- /* c8 ignore start */
172
- function disableFixedAndStickyElementPointerEvents(className) {
173
- document.querySelectorAll('*').forEach(el => {
174
- const position = getComputedStyle(el).position;
175
- if (position === 'fixed' || position === 'sticky') {
176
- el.classList.add(className);
177
- }
178
- });
179
-
180
- return function undo() {
181
- Array.from(document.getElementsByClassName(className)).forEach(el => {
182
- el.classList.remove(className);
183
- });
184
- };
185
- }
186
- /* c8 ignore stop */
187
-
188
- /**
189
- * @param {string} tapTargetsSelector
190
- * @param {string} className
191
- * @return {LH.Artifacts.TapTarget[]}
192
- */
193
- /* c8 ignore start */
194
- function gatherTapTargets(tapTargetsSelector, className) {
195
- /** @type {LH.Artifacts.TapTarget[]} */
196
- const targets = [];
197
-
198
- // Capture element positions relative to the top of the page
199
- window.scrollTo(0, 0);
200
-
201
- /** @type {HTMLElement[]} */
202
- // @ts-expect-error - getElementsInDocument put into scope via stringification
203
- const tapTargetElements = getElementsInDocument(tapTargetsSelector);
204
-
205
- /** @type {{
206
- tapTargetElement: Element,
207
- clientRects: LH.Artifacts.Rect[]
208
- }[]} */
209
- const tapTargetsWithClientRects = [];
210
- tapTargetElements.forEach(tapTargetElement => {
211
- // Filter out tap targets that are likely to cause false failures:
212
- if (elementHasAncestorTapTarget(tapTargetElement, tapTargetsSelector)) {
213
- // This is usually intentional, either the tap targets trigger the same action
214
- // or there's a child with a related action (like a delete button for an item)
215
- return;
216
- }
217
- if (elementIsInTextBlock(tapTargetElement)) {
218
- // Links inside text blocks cause a lot of failures, and there's also an exception for them
219
- // in the Web Content Accessibility Guidelines https://www.w3.org/TR/WCAG21/#target-size
220
- return;
221
- }
222
- if (!elementIsVisible(tapTargetElement)) {
223
- return;
224
- }
225
-
226
- tapTargetsWithClientRects.push({
227
- tapTargetElement,
228
- clientRects: getClientRects(tapTargetElement),
229
- });
230
- });
231
-
232
- // Disable pointer events so that tap targets below them don't get
233
- // detected as non-tappable (they are tappable, just not while the viewport
234
- // is at the current scroll position)
235
- const reenableFixedAndStickyElementPointerEvents =
236
- disableFixedAndStickyElementPointerEvents(className);
237
-
238
- /** @type {{
239
- tapTargetElement: Element,
240
- visibleClientRects: LH.Artifacts.Rect[]
241
- }[]} */
242
- const tapTargetsWithVisibleClientRects = [];
243
- // We use separate loop here to get visible client rects because that involves
244
- // scrolling around the page for elementCenterIsAtZAxisTop, which would affect the
245
- // client rect positions.
246
- tapTargetsWithClientRects.forEach(({tapTargetElement, clientRects}) => {
247
- // Filter out empty client rects
248
- let visibleClientRects = clientRects.filter(cr => cr.width !== 0 && cr.height !== 0);
249
-
250
- // Filter out client rects that are invisible, e.g because they are in a position absolute element
251
- // with a lower z-index than the main content.
252
- // This will also filter out all position fixed or sticky tap targets elements because we disable pointer
253
- // events on them before running this. That's the correct behavior because whether a position fixed/stick
254
- // element overlaps with another tap target depends on the scroll position.
255
- visibleClientRects = visibleClientRects.filter(rect => {
256
- // Just checking the center can cause false failures for large partially hidden tap targets,
257
- // but that should be a rare edge case
258
- // @ts-expect-error - put into scope via stringification
259
- const rectCenterPoint = getRectCenterPoint(rect);
260
- return elementCenterIsAtZAxisTop(tapTargetElement, rectCenterPoint);
261
- });
262
-
263
- if (visibleClientRects.length > 0) {
264
- tapTargetsWithVisibleClientRects.push({
265
- tapTargetElement,
266
- visibleClientRects,
267
- });
268
- }
269
- });
270
-
271
- for (const {tapTargetElement, visibleClientRects} of tapTargetsWithVisibleClientRects) {
272
- targets.push({
273
- clientRects: visibleClientRects,
274
- href: /** @type {HTMLAnchorElement} */(tapTargetElement)['href'] || '',
275
- // @ts-expect-error - getNodeDetails put into scope via stringification
276
- node: getNodeDetails(tapTargetElement),
277
- });
278
- }
279
-
280
- reenableFixedAndStickyElementPointerEvents();
281
-
282
- return targets;
283
- }
284
-
285
- /**
286
- * @param {string} tapTargetsSelector
287
- * @param {string} className
288
- * @return {LH.Artifacts.TapTarget[]}
289
- */
290
- function gatherTapTargetsAndResetScroll(tapTargetsSelector, className) {
291
- const originalScrollPosition = {
292
- x: window.scrollX,
293
- y: window.scrollY,
294
- };
295
-
296
- try {
297
- return gatherTapTargets(tapTargetsSelector, className);
298
- } finally {
299
- window.scrollTo(originalScrollPosition.x, originalScrollPosition.y);
300
- }
301
- }
302
- /* c8 ignore stop */
303
-
304
- class TapTargets extends BaseGatherer {
305
- constructor() {
306
- super();
307
- /**
308
- * This needs to be in the constructor.
309
- * https://github.com/GoogleChrome/lighthouse/issues/12134
310
- * @type {LH.Gatherer.GathererMeta}
311
- */
312
- this.meta = {
313
- supportedModes: ['snapshot', 'navigation'],
314
- };
315
- }
316
-
317
- /**
318
- * @param {LH.Gatherer.ProtocolSession} session
319
- * @param {string} className
320
- * @return {Promise<string>}
321
- */
322
- async addStyleRule(session, className) {
323
- const frameTreeResponse = await session.sendCommand('Page.getFrameTree');
324
- const {styleSheetId} = await session.sendCommand('CSS.createStyleSheet', {
325
- frameId: frameTreeResponse.frameTree.frame.id,
326
- });
327
- const ruleText = `.${className} { pointer-events: none !important }`;
328
- await session.sendCommand('CSS.setStyleSheetText', {
329
- styleSheetId,
330
- text: ruleText,
331
- });
332
- return styleSheetId;
333
- }
334
-
335
- /**
336
- * @param {LH.Gatherer.ProtocolSession} session
337
- * @param {string} styleSheetId
338
- */
339
- async removeStyleRule(session, styleSheetId) {
340
- await session.sendCommand('CSS.setStyleSheetText', {
341
- styleSheetId,
342
- text: '',
343
- });
344
- }
345
-
346
- /**
347
- * @param {LH.Gatherer.Context} passContext
348
- * @return {Promise<LH.Artifacts.TapTarget[]>} All visible tap targets with their positions and sizes
349
- */
350
- async getArtifact(passContext) {
351
- const session = passContext.driver.defaultSession;
352
- await session.sendCommand('DOM.enable');
353
- await session.sendCommand('CSS.enable');
354
-
355
- const className = 'lighthouse-disable-pointer-events';
356
- const styleSheetId = await this.addStyleRule(session, className);
357
-
358
- const tapTargets =
359
- await passContext.driver.executionContext.evaluate(gatherTapTargetsAndResetScroll, {
360
- args: [tapTargetsSelector, className],
361
- useIsolation: true,
362
- deps: [
363
- pageFunctions.getNodeDetails,
364
- pageFunctions.getElementsInDocument,
365
- disableFixedAndStickyElementPointerEvents,
366
- elementIsVisible,
367
- elementHasAncestorTapTarget,
368
- elementCenterIsAtZAxisTop,
369
- getClientRects,
370
- hasTextNodeSiblingsFormingTextBlock,
371
- elementIsInTextBlock,
372
- RectHelpers.getRectCenterPoint,
373
- pageFunctions.getNodePath,
374
- pageFunctions.getNodeSelector,
375
- pageFunctions.getNodeLabel,
376
- gatherTapTargets,
377
- ],
378
- });
379
-
380
- await this.removeStyleRule(session, styleSheetId);
381
-
382
- await session.sendCommand('CSS.disable');
383
- await session.sendCommand('DOM.disable');
384
-
385
- return tapTargets;
386
- }
387
- }
388
-
389
- export default TapTargets;