lighthouse 12.8.2 → 13.0.0-dev.20251010

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 (270) hide show
  1. package/cli/cli-flags.js +1 -1
  2. package/cli/test/smokehouse/config/exclusions.js +0 -2
  3. package/cli/test/smokehouse/version-check.d.ts +1 -1
  4. package/core/audits/accessibility/accesskeys.js +3 -3
  5. package/core/audits/accessibility/aria-allowed-attr.js +3 -3
  6. package/core/audits/accessibility/aria-allowed-role.js +2 -1
  7. package/core/audits/accessibility/aria-command-name.js +1 -1
  8. package/core/audits/accessibility/aria-conditional-attr.js +1 -1
  9. package/core/audits/accessibility/aria-deprecated-role.js +1 -1
  10. package/core/audits/accessibility/aria-dialog-name.js +1 -1
  11. package/core/audits/accessibility/aria-hidden-body.js +3 -3
  12. package/core/audits/accessibility/aria-hidden-focus.js +3 -3
  13. package/core/audits/accessibility/aria-input-field-name.js +3 -3
  14. package/core/audits/accessibility/aria-meter-name.js +1 -1
  15. package/core/audits/accessibility/aria-progressbar-name.js +1 -1
  16. package/core/audits/accessibility/aria-prohibited-attr.js +1 -1
  17. package/core/audits/accessibility/aria-required-attr.js +3 -3
  18. package/core/audits/accessibility/aria-required-children.js +3 -3
  19. package/core/audits/accessibility/aria-required-parent.js +3 -3
  20. package/core/audits/accessibility/aria-roles.js +3 -3
  21. package/core/audits/accessibility/aria-text.js +3 -3
  22. package/core/audits/accessibility/aria-toggle-field-name.js +3 -3
  23. package/core/audits/accessibility/aria-tooltip-name.js +1 -1
  24. package/core/audits/accessibility/aria-treeitem-name.js +1 -1
  25. package/core/audits/accessibility/aria-valid-attr-value.js +3 -3
  26. package/core/audits/accessibility/aria-valid-attr.js +3 -3
  27. package/core/audits/accessibility/button-name.js +3 -3
  28. package/core/audits/accessibility/bypass.js +3 -3
  29. package/core/audits/accessibility/color-contrast.js +3 -3
  30. package/core/audits/accessibility/definition-list.js +3 -3
  31. package/core/audits/accessibility/dlitem.js +3 -3
  32. package/core/audits/accessibility/document-title.js +3 -3
  33. package/core/audits/accessibility/duplicate-id-aria.js +3 -3
  34. package/core/audits/accessibility/empty-heading.js +3 -3
  35. package/core/audits/accessibility/form-field-multiple-labels.js +3 -3
  36. package/core/audits/accessibility/frame-title.js +3 -3
  37. package/core/audits/accessibility/heading-order.js +3 -3
  38. package/core/audits/accessibility/html-has-lang.js +3 -3
  39. package/core/audits/accessibility/html-lang-valid.js +3 -3
  40. package/core/audits/accessibility/html-xml-lang-mismatch.js +3 -3
  41. package/core/audits/accessibility/identical-links-same-purpose.js +3 -3
  42. package/core/audits/accessibility/image-alt.js +3 -3
  43. package/core/audits/accessibility/image-redundant-alt.js +4 -3
  44. package/core/audits/accessibility/input-button-name.js +3 -3
  45. package/core/audits/accessibility/input-image-alt.js +3 -3
  46. package/core/audits/accessibility/label-content-name-mismatch.js +3 -3
  47. package/core/audits/accessibility/label.js +3 -3
  48. package/core/audits/accessibility/landmark-one-main.js +3 -4
  49. package/core/audits/accessibility/link-in-text-block.js +3 -3
  50. package/core/audits/accessibility/link-name.js +3 -3
  51. package/core/audits/accessibility/list.js +3 -3
  52. package/core/audits/accessibility/listitem.js +3 -3
  53. package/core/audits/accessibility/meta-refresh.js +3 -3
  54. package/core/audits/accessibility/meta-viewport.js +3 -3
  55. package/core/audits/accessibility/object-alt.js +3 -3
  56. package/core/audits/accessibility/select-name.js +3 -3
  57. package/core/audits/accessibility/skip-link.js +3 -3
  58. package/core/audits/accessibility/tabindex.js +3 -3
  59. package/core/audits/accessibility/table-duplicate-name.js +4 -3
  60. package/core/audits/accessibility/table-fake-caption.js +3 -3
  61. package/core/audits/accessibility/target-size.js +3 -3
  62. package/core/audits/accessibility/td-has-header.js +3 -3
  63. package/core/audits/accessibility/td-headers-attr.js +3 -3
  64. package/core/audits/accessibility/th-has-data-cells.js +3 -3
  65. package/core/audits/accessibility/valid-lang.js +3 -3
  66. package/core/audits/accessibility/video-caption.js +3 -3
  67. package/core/audits/audit.d.ts +0 -4
  68. package/core/audits/audit.js +2 -13
  69. package/core/audits/insights/cls-culprits-insight.js +1 -1
  70. package/core/audits/insights/dom-size-insight.js +11 -7
  71. package/core/audits/insights/font-display-insight.js +3 -1
  72. package/core/audits/insights/image-delivery-insight.js +4 -1
  73. package/core/audits/insights/insight-audit.d.ts +6 -4
  74. package/core/audits/insights/insight-audit.js +27 -8
  75. package/core/audits/insights/third-parties-insight.js +1 -1
  76. package/core/audits/layout-shifts.js +1 -1
  77. package/core/audits/predictive-perf.js +2 -2
  78. package/core/audits/seo/crawlable-anchors.js +2 -3
  79. package/core/audits/seo/manual/structured-data.js +1 -1
  80. package/core/audits/server-response-time.d.ts +0 -5
  81. package/core/audits/server-response-time.js +12 -26
  82. package/core/computed/metrics/cumulative-layout-shift.js +2 -2
  83. package/core/computed/metrics/lantern-metric.js +3 -3
  84. package/core/computed/metrics/lcp-breakdown.d.ts +10 -5
  85. package/core/computed/metrics/lcp-breakdown.js +50 -22
  86. package/core/computed/metrics/time-to-first-byte.js +33 -10
  87. package/core/computed/metrics/timing-summary.js +3 -2
  88. package/core/computed/page-dependency-graph.js +1 -1
  89. package/core/computed/trace-engine-result.js +2 -2
  90. package/core/config/default-config.js +110 -152
  91. package/core/config/experimental-config.js +1 -32
  92. package/core/config/filters.js +6 -9
  93. package/core/config/lr-desktop-config.js +0 -1
  94. package/core/config/lr-mobile-config.js +0 -1
  95. package/core/gather/driver/target-manager.d.ts +1 -1
  96. package/core/gather/driver.d.ts +1 -1
  97. package/core/gather/gatherers/anchor-elements.js +8 -24
  98. package/core/gather/gatherers/image-elements.js +32 -6
  99. package/core/gather/gatherers/inspector-issues.js +1 -28
  100. package/core/gather/gatherers/trace-elements.d.ts +2 -11
  101. package/core/gather/gatherers/trace-elements.js +9 -39
  102. package/core/gather/navigation-runner.js +0 -3
  103. package/core/gather/session.d.ts +1 -1
  104. package/core/lib/asset-saver.d.ts +2 -2
  105. package/core/lib/asset-saver.js +33 -43
  106. package/core/lib/bf-cache-strings.js +10 -9
  107. package/core/lib/deprecations-strings.js +5 -5
  108. package/core/lib/emulation.d.ts +10 -0
  109. package/core/lib/emulation.js +21 -6
  110. package/core/lib/legacy-javascript/legacy-javascript.js +4 -11
  111. package/core/lib/network-request.d.ts +0 -7
  112. package/core/lib/network-request.js +0 -16
  113. package/core/lib/proto-preprocessor.js +10 -25
  114. package/core/runner.js +1 -8
  115. package/core/scoring.js +1 -1
  116. package/dist/report/bundle.esm.js +10 -49
  117. package/dist/report/flow.js +12 -51
  118. package/dist/report/standalone.js +11 -50
  119. package/flow-report/src/i18n/i18n.d.ts +4 -6
  120. package/package.json +16 -19
  121. package/readme.md +2 -2
  122. package/report/assets/styles.css +0 -39
  123. package/report/renderer/api.js +0 -1
  124. package/report/renderer/category-renderer.js +6 -0
  125. package/report/renderer/components.js +1 -1
  126. package/report/renderer/details-renderer.d.ts +1 -2
  127. package/report/renderer/details-renderer.js +0 -1
  128. package/report/renderer/dom.d.ts +0 -13
  129. package/report/renderer/dom.js +0 -38
  130. package/report/renderer/performance-category-renderer.d.ts +0 -26
  131. package/report/renderer/performance-category-renderer.js +10 -142
  132. package/report/renderer/report-ui-features.d.ts +0 -1
  133. package/report/renderer/report-ui-features.js +2 -13
  134. package/report/renderer/report-utils.d.ts +2 -3
  135. package/report/renderer/report-utils.js +4 -6
  136. package/report/types/report-renderer.d.ts +0 -6
  137. package/shared/localization/locales/ar-XB.json +107 -455
  138. package/shared/localization/locales/ar.json +107 -455
  139. package/shared/localization/locales/bg.json +96 -444
  140. package/shared/localization/locales/ca.json +96 -444
  141. package/shared/localization/locales/cs.json +96 -444
  142. package/shared/localization/locales/da.json +96 -444
  143. package/shared/localization/locales/de.json +96 -444
  144. package/shared/localization/locales/el.json +96 -444
  145. package/shared/localization/locales/en-GB.json +96 -444
  146. package/shared/localization/locales/en-US.json +116 -467
  147. package/shared/localization/locales/en-XA.json +93 -441
  148. package/shared/localization/locales/en-XL.json +116 -467
  149. package/shared/localization/locales/es-419.json +96 -444
  150. package/shared/localization/locales/es.json +96 -444
  151. package/shared/localization/locales/fi.json +96 -444
  152. package/shared/localization/locales/fil.json +96 -444
  153. package/shared/localization/locales/fr.json +96 -444
  154. package/shared/localization/locales/he.json +118 -466
  155. package/shared/localization/locales/hi.json +96 -444
  156. package/shared/localization/locales/hr.json +100 -448
  157. package/shared/localization/locales/hu.json +96 -444
  158. package/shared/localization/locales/id.json +96 -444
  159. package/shared/localization/locales/it.json +96 -444
  160. package/shared/localization/locales/ja.json +96 -444
  161. package/shared/localization/locales/ko.json +97 -445
  162. package/shared/localization/locales/lt.json +96 -444
  163. package/shared/localization/locales/lv.json +97 -445
  164. package/shared/localization/locales/nl.json +96 -444
  165. package/shared/localization/locales/no.json +96 -444
  166. package/shared/localization/locales/pl.json +96 -444
  167. package/shared/localization/locales/pt-PT.json +96 -444
  168. package/shared/localization/locales/pt.json +97 -445
  169. package/shared/localization/locales/ro.json +97 -445
  170. package/shared/localization/locales/ru.json +96 -444
  171. package/shared/localization/locales/sk.json +96 -444
  172. package/shared/localization/locales/sl.json +96 -444
  173. package/shared/localization/locales/sr-Latn.json +96 -444
  174. package/shared/localization/locales/sr.json +96 -444
  175. package/shared/localization/locales/sv.json +96 -444
  176. package/shared/localization/locales/ta.json +96 -444
  177. package/shared/localization/locales/te.json +97 -445
  178. package/shared/localization/locales/th.json +96 -444
  179. package/shared/localization/locales/tr.json +96 -444
  180. package/shared/localization/locales/uk.json +96 -444
  181. package/shared/localization/locales/vi.json +96 -444
  182. package/shared/localization/locales/zh-HK.json +96 -444
  183. package/shared/localization/locales/zh-TW.json +97 -445
  184. package/shared/localization/locales/zh.json +96 -444
  185. package/shared/localization/locales.d.ts +2 -0
  186. package/shared/localization/locales.js +130 -139
  187. package/shared/tsconfig.json +2 -0
  188. package/tsconfig-base.json +2 -2
  189. package/tsconfig.json +1 -4
  190. package/types/artifacts.d.ts +6 -81
  191. package/types/audit.d.ts +1 -1
  192. package/types/lhr/settings.d.ts +1 -1
  193. package/core/audits/byte-efficiency/duplicated-javascript.d.ts +0 -45
  194. package/core/audits/byte-efficiency/duplicated-javascript.js +0 -223
  195. package/core/audits/byte-efficiency/efficient-animated-content.d.ts +0 -22
  196. package/core/audits/byte-efficiency/efficient-animated-content.js +0 -93
  197. package/core/audits/byte-efficiency/legacy-javascript.d.ts +0 -28
  198. package/core/audits/byte-efficiency/legacy-javascript.js +0 -144
  199. package/core/audits/byte-efficiency/modern-image-formats.d.ts +0 -38
  200. package/core/audits/byte-efficiency/modern-image-formats.js +0 -187
  201. package/core/audits/byte-efficiency/offscreen-images.d.ts +0 -63
  202. package/core/audits/byte-efficiency/offscreen-images.js +0 -240
  203. package/core/audits/byte-efficiency/render-blocking-resources.d.ts +0 -53
  204. package/core/audits/byte-efficiency/render-blocking-resources.js +0 -312
  205. package/core/audits/byte-efficiency/uses-long-cache-ttl.d.ts +0 -59
  206. package/core/audits/byte-efficiency/uses-long-cache-ttl.js +0 -293
  207. package/core/audits/byte-efficiency/uses-optimized-images.d.ts +0 -33
  208. package/core/audits/byte-efficiency/uses-optimized-images.js +0 -146
  209. package/core/audits/byte-efficiency/uses-responsive-images-snapshot.d.ts +0 -16
  210. package/core/audits/byte-efficiency/uses-responsive-images-snapshot.js +0 -106
  211. package/core/audits/byte-efficiency/uses-responsive-images.d.ts +0 -44
  212. package/core/audits/byte-efficiency/uses-responsive-images.js +0 -202
  213. package/core/audits/byte-efficiency/uses-text-compression.d.ts +0 -14
  214. package/core/audits/byte-efficiency/uses-text-compression.js +0 -108
  215. package/core/audits/critical-request-chains.d.ts +0 -44
  216. package/core/audits/critical-request-chains.js +0 -221
  217. package/core/audits/dobetterweb/dom-size.d.ts +0 -32
  218. package/core/audits/dobetterweb/dom-size.js +0 -182
  219. package/core/audits/dobetterweb/no-document-write.d.ts +0 -16
  220. package/core/audits/dobetterweb/no-document-write.js +0 -86
  221. package/core/audits/dobetterweb/uses-http2.d.ts +0 -72
  222. package/core/audits/dobetterweb/uses-http2.js +0 -276
  223. package/core/audits/dobetterweb/uses-passive-event-listeners.d.ts +0 -16
  224. package/core/audits/dobetterweb/uses-passive-event-listeners.js +0 -69
  225. package/core/audits/font-display.d.ts +0 -32
  226. package/core/audits/font-display.js +0 -195
  227. package/core/audits/largest-contentful-paint-element.d.ts +0 -34
  228. package/core/audits/largest-contentful-paint-element.js +0 -181
  229. package/core/audits/lcp-lazy-loaded.d.ts +0 -22
  230. package/core/audits/lcp-lazy-loaded.js +0 -115
  231. package/core/audits/metrics/first-meaningful-paint.d.ts +0 -12
  232. package/core/audits/metrics/first-meaningful-paint.js +0 -47
  233. package/core/audits/preload-fonts.d.ts +0 -25
  234. package/core/audits/preload-fonts.js +0 -97
  235. package/core/audits/prioritize-lcp-image.d.ts +0 -74
  236. package/core/audits/prioritize-lcp-image.js +0 -297
  237. package/core/audits/seo/font-size.d.ts +0 -24
  238. package/core/audits/seo/font-size.js +0 -344
  239. package/core/audits/third-party-facades.d.ts +0 -41
  240. package/core/audits/third-party-facades.js +0 -234
  241. package/core/audits/third-party-summary.d.ts +0 -78
  242. package/core/audits/third-party-summary.js +0 -236
  243. package/core/audits/uses-rel-preconnect.d.ts +0 -37
  244. package/core/audits/uses-rel-preconnect.js +0 -286
  245. package/core/audits/uses-rel-preload.d.ts +0 -57
  246. package/core/audits/uses-rel-preload.js +0 -263
  247. package/core/audits/viewport.d.ts +0 -17
  248. package/core/audits/viewport.js +0 -87
  249. package/core/audits/work-during-interaction.d.ts +0 -81
  250. package/core/audits/work-during-interaction.js +0 -287
  251. package/core/computed/critical-request-chains.d.ts +0 -42
  252. package/core/computed/critical-request-chains.js +0 -143
  253. package/core/computed/viewport-meta.d.ts +0 -37
  254. package/core/computed/viewport-meta.js +0 -71
  255. package/core/gather/gatherers/cache-contents.d.ts +0 -11
  256. package/core/gather/gatherers/cache-contents.js +0 -56
  257. package/core/gather/gatherers/devtools-log-compat.d.ts +0 -13
  258. package/core/gather/gatherers/devtools-log-compat.js +0 -35
  259. package/core/gather/gatherers/dobetterweb/domstats.d.ts +0 -10
  260. package/core/gather/gatherers/dobetterweb/domstats.js +0 -102
  261. package/core/gather/gatherers/dobetterweb/optimized-images.d.ts +0 -48
  262. package/core/gather/gatherers/dobetterweb/optimized-images.js +0 -169
  263. package/core/gather/gatherers/dobetterweb/response-compression.d.ts +0 -23
  264. package/core/gather/gatherers/dobetterweb/response-compression.js +0 -136
  265. package/core/gather/gatherers/seo/font-size.d.ts +0 -131
  266. package/core/gather/gatherers/seo/font-size.js +0 -347
  267. package/core/gather/gatherers/trace-compat.d.ts +0 -13
  268. package/core/gather/gatherers/trace-compat.js +0 -35
  269. package/types/internal/metaviewport-parser.d.ts +0 -13
  270. package/types/internal/parse-cache-control.d.ts +0 -20
@@ -1,297 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2020 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import {Audit} from './audit.js';
8
- import * as i18n from '../lib/i18n/i18n.js';
9
- import {NetworkRequest} from '../lib/network-request.js';
10
- import {MainResource} from '../computed/main-resource.js';
11
- import {LanternLargestContentfulPaint} from '../computed/metrics/lantern-largest-contentful-paint.js';
12
- import {LoadSimulator} from '../computed/load-simulator.js';
13
- import {LCPImageRecord} from '../computed/lcp-image-record.js';
14
-
15
- const UIStrings = {
16
- /** Title of a lighthouse audit that tells a user to preload an image in order to improve their LCP time. */
17
- title: 'Preload Largest Contentful Paint image',
18
- /** Description of a lighthouse audit that tells a user to preload an image in order to improve their LCP time. */
19
- description: 'If the LCP element is dynamically added to the page, you should preload the ' +
20
- 'image in order to improve LCP. [Learn more about preloading LCP elements](https://web.dev/articles/optimize-lcp#optimize_when_the_resource_is_discovered).',
21
- };
22
-
23
- const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
24
-
25
- /**
26
- * @typedef {LH.Crdp.Network.Initiator['type']|'redirect'|'fallbackToMain'} InitiatorType
27
- * @typedef {Array<{url: string, initiatorType: InitiatorType}>} InitiatorPath
28
- */
29
-
30
- class PrioritizeLcpImage extends Audit {
31
- /**
32
- * @return {LH.Audit.Meta}
33
- */
34
- static get meta() {
35
- return {
36
- id: 'prioritize-lcp-image',
37
- title: str_(UIStrings.title),
38
- description: str_(UIStrings.description),
39
- supportedModes: ['navigation'],
40
- guidanceLevel: 4,
41
- requiredArtifacts: ['Trace', 'DevtoolsLog', 'GatherContext', 'URL', 'TraceElements',
42
- 'SourceMaps'],
43
- scoreDisplayMode: Audit.SCORING_MODES.METRIC_SAVINGS,
44
- };
45
- }
46
-
47
- /**
48
- *
49
- * @param {LH.Artifacts.NetworkRequest} request
50
- * @param {LH.Artifacts.NetworkRequest} mainResource
51
- * @param {InitiatorPath} initiatorPath
52
- * @return {boolean}
53
- */
54
- static shouldPreloadRequest(request, mainResource, initiatorPath) {
55
- // If it's already preloaded, no need to recommend it.
56
- if (request.isLinkPreload) return false;
57
- // It's not a request loaded over the network, don't recommend it.
58
- if (NetworkRequest.isNonNetworkRequest(request)) return false;
59
- // It's already discoverable from the main document (a path of [lcpRecord, mainResource]), don't recommend it.
60
- if (initiatorPath.length <= 2) return false;
61
- // Finally, return whether or not it belongs to the main frame
62
- return request.frameId === mainResource.frameId;
63
- }
64
-
65
- /**
66
- * @param {LH.Gatherer.Simulation.GraphNode} graph
67
- * @param {NetworkRequest} lcpRecord
68
- * @return {LH.Gatherer.Simulation.GraphNetworkNode|undefined}
69
- */
70
- static findLCPNode(graph, lcpRecord) {
71
- for (const {node} of graph.traverseGenerator()) {
72
- if (node.type !== 'network') continue;
73
- if (node.request.requestId === lcpRecord.requestId) {
74
- return node;
75
- }
76
- }
77
- }
78
-
79
- /**
80
- * Get the initiator path starting with lcpRecord back to mainResource, inclusive.
81
- * Navigation redirects *to* the mainResource are not included.
82
- * Path returned will always be at least [lcpRecord, mainResource].
83
- * @param {NetworkRequest} lcpRecord
84
- * @param {NetworkRequest} mainResource
85
- * @return {InitiatorPath}
86
- */
87
- static getLcpInitiatorPath(lcpRecord, mainResource) {
88
- /** @type {InitiatorPath} */
89
- const initiatorPath = [];
90
- let mainResourceReached = false;
91
- /** @type {NetworkRequest|undefined} */
92
- let request = lcpRecord;
93
-
94
- while (request) {
95
- mainResourceReached ||= request.requestId === mainResource.requestId;
96
-
97
- /** @type {InitiatorType} */
98
- let initiatorType = request.initiator?.type ?? 'other';
99
- // Initiator type usually comes from redirect, but 'redirect' is used for more informative debugData.
100
- if (request.initiatorRequest && request.initiatorRequest === request.redirectSource) {
101
- initiatorType = 'redirect';
102
- }
103
- // Sometimes the initiator chain is broken and the best that can be done is stitch
104
- // back to the main resource. Note this in the initiatorType.
105
- if (!request.initiatorRequest && !mainResourceReached) {
106
- initiatorType = 'fallbackToMain';
107
- }
108
-
109
- initiatorPath.push({url: request.url, initiatorType});
110
-
111
- // Can't preload before the main resource, so break off initiator path there.
112
- if (mainResourceReached) break;
113
-
114
- // Continue up chain, falling back to mainResource if chain is broken.
115
- request = request.initiatorRequest || mainResource;
116
- }
117
-
118
- return initiatorPath;
119
- }
120
-
121
- /**
122
- * @param {LH.Artifacts.NetworkRequest} mainResource
123
- * @param {LH.Gatherer.Simulation.GraphNode} graph
124
- * @param {NetworkRequest|undefined} lcpRecord
125
- * @return {{lcpNodeToPreload?: LH.Gatherer.Simulation.GraphNetworkNode, initiatorPath?: InitiatorPath}}
126
- */
127
- static getLCPNodeToPreload(mainResource, graph, lcpRecord) {
128
- if (!lcpRecord) return {};
129
- const lcpNode = PrioritizeLcpImage.findLCPNode(graph, lcpRecord);
130
- const initiatorPath = PrioritizeLcpImage.getLcpInitiatorPath(lcpRecord, mainResource);
131
- if (!lcpNode) return {initiatorPath};
132
-
133
- // eslint-disable-next-line max-len
134
- const shouldPreload = PrioritizeLcpImage.shouldPreloadRequest(lcpRecord, mainResource, initiatorPath);
135
- const lcpNodeToPreload = shouldPreload ? lcpNode : undefined;
136
-
137
- return {
138
- lcpNodeToPreload,
139
- initiatorPath,
140
- };
141
- }
142
-
143
- /**
144
- * Computes the estimated effect of preloading the LCP image.
145
- * @param {LH.Artifacts.TraceElement} lcpElement
146
- * @param {LH.Gatherer.Simulation.GraphNetworkNode|undefined} lcpNode
147
- * @param {LH.Gatherer.Simulation.GraphNode} graph
148
- * @param {LH.Gatherer.Simulation.Simulator} simulator
149
- * @return {{wastedMs: number, results: Array<{node: LH.Audit.Details.NodeValue, url: string, wastedMs: number}>}}
150
- */
151
- static computeWasteWithGraph(lcpElement, lcpNode, graph, simulator) {
152
- if (!lcpNode) {
153
- return {
154
- wastedMs: 0,
155
- results: [],
156
- };
157
- }
158
-
159
- const modifiedGraph = graph.cloneWithRelationships();
160
-
161
- // Store the IDs of the LCP Node's dependencies for later
162
- /** @type {Set<string>} */
163
- const dependenciesIds = new Set();
164
- for (const node of lcpNode.getDependencies()) {
165
- dependenciesIds.add(node.id);
166
- }
167
-
168
- /** @type {LH.Gatherer.Simulation.GraphNode|null} */
169
- let modifiedLCPNode = null;
170
- /** @type {LH.Gatherer.Simulation.GraphNode|null} */
171
- let mainDocumentNode = null;
172
-
173
- for (const {node} of modifiedGraph.traverseGenerator()) {
174
- if (node.type !== 'network') continue;
175
-
176
- if (node.isMainDocument()) {
177
- mainDocumentNode = node;
178
- } else if (node.id === lcpNode.id) {
179
- modifiedLCPNode = node;
180
- }
181
- }
182
-
183
- if (!mainDocumentNode) {
184
- // Should always find the main document node
185
- throw new Error('Could not find main document node');
186
- }
187
-
188
- if (!modifiedLCPNode) {
189
- // Should always find the LCP node as well or else this function wouldn't have been called
190
- throw new Error('Could not find the LCP node');
191
- }
192
-
193
- // Preload will request the resource as soon as its discovered in the main document.
194
- // Reflect this change in the dependencies in our modified graph.
195
- modifiedLCPNode.removeAllDependencies();
196
- modifiedLCPNode.addDependency(mainDocumentNode);
197
-
198
- const simulationBeforeChanges = simulator.simulate(graph);
199
- const simulationAfterChanges = simulator.simulate(modifiedGraph);
200
- const lcpTimingsBefore = simulationBeforeChanges.nodeTimings.get(lcpNode);
201
- if (!lcpTimingsBefore) throw new Error('Impossible - node timings should never be undefined');
202
- const lcpTimingsAfter = simulationAfterChanges.nodeTimings.get(modifiedLCPNode);
203
- if (!lcpTimingsAfter) throw new Error('Impossible - node timings should never be undefined');
204
- /** @type {Map<String, LH.Gatherer.Simulation.GraphNode>} */
205
- const modifiedNodesById = Array.from(simulationAfterChanges.nodeTimings.keys())
206
- .reduce((map, node) => map.set(node.id, node), new Map());
207
-
208
- // Even with preload, the image can't be painted before it's even inserted into the DOM.
209
- // New LCP time will be the max of image download and image in DOM (endTime of its deps).
210
- let maxDependencyEndTime = 0;
211
- for (const nodeId of Array.from(dependenciesIds)) {
212
- const node = modifiedNodesById.get(nodeId);
213
- if (!node) throw new Error('Impossible - node should never be undefined');
214
- const timings = simulationAfterChanges.nodeTimings.get(node);
215
- const endTime = timings?.endTime || 0;
216
- maxDependencyEndTime = Math.max(maxDependencyEndTime, endTime);
217
- }
218
-
219
- const wastedMs = lcpTimingsBefore.endTime -
220
- Math.max(lcpTimingsAfter.endTime, maxDependencyEndTime);
221
-
222
- return {
223
- wastedMs,
224
- results: [{
225
- node: Audit.makeNodeItem(lcpElement.node),
226
- url: lcpNode.request.url,
227
- wastedMs,
228
- }],
229
- };
230
- }
231
-
232
- /**
233
- * @param {LH.Artifacts} artifacts
234
- * @param {LH.Audit.Context} context
235
- * @return {Promise<LH.Audit.Product>}
236
- */
237
- static async audit(artifacts, context) {
238
- const gatherContext = artifacts.GatherContext;
239
- const trace = artifacts.Trace;
240
- const devtoolsLog = artifacts.DevtoolsLog;
241
- const {URL, SourceMaps} = artifacts;
242
- const settings = context.settings;
243
- const metricData =
244
- {trace, devtoolsLog, gatherContext, settings, URL, SourceMaps, simulator: null};
245
- const lcpElement = artifacts.TraceElements
246
- .find(element => element.traceEventType === 'largest-contentful-paint');
247
-
248
- if (!lcpElement || lcpElement.type !== 'image') {
249
- return {score: null, notApplicable: true, metricSavings: {LCP: 0}};
250
- }
251
-
252
- const mainResource = await MainResource.request({devtoolsLog, URL}, context);
253
- const lanternLCP = await LanternLargestContentfulPaint.request(metricData, context);
254
- const simulator = await LoadSimulator.request({devtoolsLog, settings}, context);
255
-
256
- const lcpImageRecord = await LCPImageRecord.request({trace, devtoolsLog}, context);
257
- const graph = lanternLCP.pessimisticGraph;
258
- // Note: if moving to LCPAllFrames, mainResource would need to be the LCP frame's main resource.
259
- const {lcpNodeToPreload, initiatorPath} = PrioritizeLcpImage.getLCPNodeToPreload(mainResource,
260
- graph, lcpImageRecord);
261
-
262
- const {results, wastedMs} =
263
- PrioritizeLcpImage.computeWasteWithGraph(lcpElement, lcpNodeToPreload, graph, simulator);
264
-
265
- /** @type {LH.Audit.Details.Opportunity['headings']} */
266
- const headings = [
267
- {key: 'node', valueType: 'node', label: ''},
268
- {key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
269
- {key: 'wastedMs', valueType: 'timespanMs', label: str_(i18n.UIStrings.columnWastedMs)},
270
- ];
271
- const details = Audit.makeOpportunityDetails(headings, results,
272
- {overallSavingsMs: wastedMs, sortedBy: ['wastedMs']});
273
-
274
- // If LCP element was an image and had valid network records (regardless of
275
- // if it should be preloaded), it will be found first in the `initiatorPath`.
276
- // Otherwise path and length will be undefined.
277
- if (initiatorPath) {
278
- details.debugData = {
279
- type: 'debugdata',
280
- initiatorPath,
281
- pathLength: initiatorPath.length,
282
- };
283
- }
284
-
285
- return {
286
- score: results.length ? 0 : 1,
287
- numericValue: wastedMs,
288
- numericUnit: 'millisecond',
289
- displayValue: wastedMs ? str_(i18n.UIStrings.displayValueMsSavings, {wastedMs}) : '',
290
- details,
291
- metricSavings: {LCP: wastedMs},
292
- };
293
- }
294
- }
295
-
296
- export default PrioritizeLcpImage;
297
- export {UIStrings};
@@ -1,24 +0,0 @@
1
- export default FontSize;
2
- export type FailingNodeData = LH.Artifacts.FontSize["analyzedFailingNodesData"][0];
3
- declare class FontSize extends Audit {
4
- /**
5
- * @param {LH.Artifacts} artifacts
6
- * @param {LH.Audit.Context} context
7
- * @return {Promise<LH.Audit.Product>}
8
- */
9
- static audit(artifacts: LH.Artifacts, context: LH.Audit.Context): Promise<LH.Audit.Product>;
10
- }
11
- export namespace UIStrings {
12
- let title: string;
13
- let failureTitle: string;
14
- let description: string;
15
- let displayValue: string;
16
- let explanationViewport: string;
17
- let additionalIllegibleText: string;
18
- let legibleText: string;
19
- let columnSelector: string;
20
- let columnPercentPageText: string;
21
- let columnFontSize: string;
22
- }
23
- import { Audit } from '../audit.js';
24
- //# sourceMappingURL=font-size.d.ts.map
@@ -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};