lighthouse 12.5.1-dev.20250415 → 12.5.1-dev.20250416
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.
|
@@ -12,9 +12,10 @@ export type ImageWithNaturalDimensions = LH.Artifacts.ImageElement & Required<Pi
|
|
|
12
12
|
declare class ImageSizeResponsive extends Audit {
|
|
13
13
|
/**
|
|
14
14
|
* @param {LH.Artifacts} artifacts
|
|
15
|
-
* @
|
|
15
|
+
* @param {LH.Audit.Context} context
|
|
16
|
+
* @return {Promise<LH.Audit.Product>}
|
|
16
17
|
*/
|
|
17
|
-
static audit(artifacts: LH.Artifacts): LH.Audit.Product
|
|
18
|
+
static audit(artifacts: LH.Artifacts, context: LH.Audit.Context): Promise<LH.Audit.Product>;
|
|
18
19
|
}
|
|
19
20
|
export namespace UIStrings {
|
|
20
21
|
let title: string;
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
import {Audit} from './audit.js';
|
|
14
|
+
import {ImageRecords} from '../computed/image-records.js';
|
|
15
|
+
import {NetworkRecords} from '../computed/network-records.js';
|
|
14
16
|
import UrlUtils from '../lib/url-utils.js';
|
|
15
17
|
import * as i18n from '../lib/i18n/i18n.js';
|
|
16
18
|
|
|
@@ -77,9 +79,10 @@ function isSmallerThanViewport(imageRect, viewportDimensions) {
|
|
|
77
79
|
|
|
78
80
|
/**
|
|
79
81
|
* @param {LH.Artifacts.ImageElement} image
|
|
82
|
+
* @param {LH.Artifacts.ImageElementRecord | undefined} imageRecord
|
|
80
83
|
* @return {boolean}
|
|
81
84
|
*/
|
|
82
|
-
function isCandidate(image) {
|
|
85
|
+
function isCandidate(image, imageRecord) {
|
|
83
86
|
/** image-rendering solution for pixel art scaling.
|
|
84
87
|
* https://developer.mozilla.org/en-US/docs/Games/Techniques/Crisp_pixel_art_look
|
|
85
88
|
*/
|
|
@@ -96,6 +99,10 @@ function isCandidate(image) {
|
|
|
96
99
|
) {
|
|
97
100
|
return false;
|
|
98
101
|
}
|
|
102
|
+
// Check the actual mimeType before guessing, since file extension is not guaranteed
|
|
103
|
+
if (imageRecord?.mimeType === 'image/svg+xml') {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
99
106
|
if (UrlUtils.guessMimeType(image.src) === 'image/svg+xml') {
|
|
100
107
|
return false;
|
|
101
108
|
}
|
|
@@ -243,19 +250,38 @@ class ImageSizeResponsive extends Audit {
|
|
|
243
250
|
failureTitle: str_(UIStrings.failureTitle),
|
|
244
251
|
description: str_(UIStrings.description),
|
|
245
252
|
requiredArtifacts: ['ImageElements', 'ViewportDimensions'],
|
|
253
|
+
__internalOptionalArtifacts: ['DevtoolsLog'],
|
|
246
254
|
};
|
|
247
255
|
}
|
|
248
256
|
|
|
249
257
|
/**
|
|
250
258
|
* @param {LH.Artifacts} artifacts
|
|
251
|
-
* @
|
|
259
|
+
* @param {LH.Audit.Context} context
|
|
260
|
+
* @return {Promise<LH.Audit.Product>}
|
|
252
261
|
*/
|
|
253
|
-
static audit(artifacts) {
|
|
262
|
+
static async audit(artifacts, context) {
|
|
254
263
|
const DPR = artifacts.ViewportDimensions.devicePixelRatio;
|
|
255
264
|
|
|
265
|
+
// Prepare ImageElementRecord map for retrieving the real mimeType
|
|
266
|
+
// Derived from ./is-on-https.js and ./byte-efficiency/uses-responsive-images.js
|
|
267
|
+
/** @type {Map<string, LH.Artifacts.ImageElementRecord>} */
|
|
268
|
+
const imageRecordsByURL = new Map();
|
|
269
|
+
|
|
270
|
+
if (artifacts.DevtoolsLog) {
|
|
271
|
+
// https://github.com/GoogleChrome/lighthouse/blob/main/docs/plugins.md#using-network-requests
|
|
272
|
+
// if DevtoolsLog is provided, use it to fetch image networkRecords
|
|
273
|
+
// else the empty imageRecordsByURL map will satisfy isCandidate with an undefined image and fallback to the original logic
|
|
274
|
+
const networkRecords = await NetworkRecords.request(artifacts.DevtoolsLog, context);
|
|
275
|
+
const images = await ImageRecords.request({
|
|
276
|
+
ImageElements: artifacts.ImageElements,
|
|
277
|
+
networkRecords,
|
|
278
|
+
}, context);
|
|
279
|
+
images.forEach(img => imageRecordsByURL.set(img.src, img));
|
|
280
|
+
}
|
|
281
|
+
|
|
256
282
|
const results = Array
|
|
257
283
|
.from(artifacts.ImageElements)
|
|
258
|
-
.filter(isCandidate)
|
|
284
|
+
.filter(image => isCandidate(image, imageRecordsByURL.get(image.src)))
|
|
259
285
|
.filter(imageHasNaturalDimensions)
|
|
260
286
|
.filter(image => !imageHasRightSize(image, DPR))
|
|
261
287
|
.filter(image => isVisible(image.clientRect, artifacts.ViewportDimensions))
|
package/package.json
CHANGED