lighthouse 12.8.2-dev.20251007 → 12.8.2-dev.20251008

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 (70) hide show
  1. package/core/audits/insights/font-display-insight.js +3 -1
  2. package/core/config/default-config.js +0 -12
  3. package/package.json +1 -2
  4. package/shared/localization/locales/ar-XB.json +0 -27
  5. package/shared/localization/locales/ar.json +0 -27
  6. package/shared/localization/locales/bg.json +0 -27
  7. package/shared/localization/locales/ca.json +0 -27
  8. package/shared/localization/locales/cs.json +0 -27
  9. package/shared/localization/locales/da.json +0 -27
  10. package/shared/localization/locales/de.json +0 -27
  11. package/shared/localization/locales/el.json +0 -27
  12. package/shared/localization/locales/en-GB.json +0 -27
  13. package/shared/localization/locales/en-US.json +0 -27
  14. package/shared/localization/locales/en-XA.json +0 -27
  15. package/shared/localization/locales/en-XL.json +0 -27
  16. package/shared/localization/locales/es-419.json +0 -27
  17. package/shared/localization/locales/es.json +0 -27
  18. package/shared/localization/locales/fi.json +0 -27
  19. package/shared/localization/locales/fil.json +0 -27
  20. package/shared/localization/locales/fr.json +0 -27
  21. package/shared/localization/locales/he.json +0 -27
  22. package/shared/localization/locales/hi.json +0 -27
  23. package/shared/localization/locales/hr.json +0 -27
  24. package/shared/localization/locales/hu.json +0 -27
  25. package/shared/localization/locales/id.json +0 -27
  26. package/shared/localization/locales/it.json +0 -27
  27. package/shared/localization/locales/ja.json +0 -27
  28. package/shared/localization/locales/ko.json +0 -27
  29. package/shared/localization/locales/lt.json +0 -27
  30. package/shared/localization/locales/lv.json +0 -27
  31. package/shared/localization/locales/nl.json +0 -27
  32. package/shared/localization/locales/no.json +0 -27
  33. package/shared/localization/locales/pl.json +0 -27
  34. package/shared/localization/locales/pt-PT.json +0 -27
  35. package/shared/localization/locales/pt.json +0 -27
  36. package/shared/localization/locales/ro.json +0 -27
  37. package/shared/localization/locales/ru.json +0 -27
  38. package/shared/localization/locales/sk.json +0 -27
  39. package/shared/localization/locales/sl.json +0 -27
  40. package/shared/localization/locales/sr-Latn.json +0 -27
  41. package/shared/localization/locales/sr.json +0 -27
  42. package/shared/localization/locales/sv.json +0 -27
  43. package/shared/localization/locales/ta.json +0 -27
  44. package/shared/localization/locales/te.json +0 -27
  45. package/shared/localization/locales/th.json +0 -27
  46. package/shared/localization/locales/tr.json +0 -27
  47. package/shared/localization/locales/uk.json +0 -27
  48. package/shared/localization/locales/vi.json +0 -27
  49. package/shared/localization/locales/zh-HK.json +0 -27
  50. package/shared/localization/locales/zh-TW.json +0 -27
  51. package/shared/localization/locales/zh.json +0 -27
  52. package/tsconfig.json +0 -3
  53. package/types/artifacts.d.ts +0 -37
  54. package/core/audits/byte-efficiency/offscreen-images.d.ts +0 -63
  55. package/core/audits/byte-efficiency/offscreen-images.js +0 -240
  56. package/core/audits/dobetterweb/no-document-write.d.ts +0 -16
  57. package/core/audits/dobetterweb/no-document-write.js +0 -86
  58. package/core/audits/dobetterweb/uses-passive-event-listeners.d.ts +0 -16
  59. package/core/audits/dobetterweb/uses-passive-event-listeners.js +0 -69
  60. package/core/audits/metrics/first-meaningful-paint.d.ts +0 -12
  61. package/core/audits/metrics/first-meaningful-paint.js +0 -47
  62. package/core/gather/gatherers/cache-contents.d.ts +0 -11
  63. package/core/gather/gatherers/cache-contents.js +0 -56
  64. package/core/gather/gatherers/dobetterweb/domstats.d.ts +0 -10
  65. package/core/gather/gatherers/dobetterweb/domstats.js +0 -102
  66. package/core/gather/gatherers/dobetterweb/optimized-images.d.ts +0 -48
  67. package/core/gather/gatherers/dobetterweb/optimized-images.js +0 -169
  68. package/core/gather/gatherers/dobetterweb/response-compression.d.ts +0 -23
  69. package/core/gather/gatherers/dobetterweb/response-compression.js +0 -136
  70. package/types/internal/parse-cache-control.d.ts +0 -20
@@ -1,56 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2016 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import BaseGatherer from '../base-gatherer.js';
8
-
9
- /**
10
- * @return {Promise<Array<string>>}
11
- */
12
- /* c8 ignore start */
13
- function getCacheContents() {
14
- // Get every cache by name.
15
- return caches.keys()
16
-
17
- // Open each one.
18
- .then(cacheNames => Promise.all(cacheNames.map(cacheName => caches.open(cacheName))))
19
-
20
- .then(caches => {
21
- /** @type {Array<string>} */
22
- const requests = [];
23
-
24
- // Take each cache and get any requests is contains, and bounce each one down to its URL.
25
- return Promise.all(caches.map(cache => {
26
- return cache.keys()
27
- .then(reqs => {
28
- requests.push(...reqs.map(r => r.url));
29
- });
30
- })).then(_ => {
31
- return requests;
32
- });
33
- });
34
- }
35
- /* c8 ignore stop */
36
-
37
- class CacheContents extends BaseGatherer {
38
- /** @type {LH.Gatherer.GathererMeta} */
39
- meta = {
40
- supportedModes: ['snapshot', 'navigation'],
41
- };
42
-
43
- /**
44
- * Creates an array of cached URLs.
45
- * @param {LH.Gatherer.Context} passContext
46
- * @return {Promise<LH.Artifacts['CacheContents']>}
47
- */
48
- async getArtifact(passContext) {
49
- const driver = passContext.driver;
50
-
51
- const cacheUrls = await driver.executionContext.evaluate(getCacheContents, {args: []});
52
- return cacheUrls;
53
- }
54
- }
55
-
56
- export default CacheContents;
@@ -1,10 +0,0 @@
1
- export default DOMStats;
2
- declare class DOMStats extends BaseGatherer {
3
- /**
4
- * @param {LH.Gatherer.Context} passContext
5
- * @return {Promise<LH.Artifacts['DOMStats']>}
6
- */
7
- getArtifact(passContext: LH.Gatherer.Context): Promise<LH.Artifacts["DOMStats"]>;
8
- }
9
- import BaseGatherer from '../../base-gatherer.js';
10
- //# sourceMappingURL=domstats.d.ts.map
@@ -1,102 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /**
8
- * @fileoverview Gathers stats about the max height and width of the DOM tree
9
- * and total number of elements used on the page.
10
- */
11
-
12
- /* global getNodeDetails */
13
-
14
-
15
- import BaseGatherer from '../../base-gatherer.js';
16
- import {pageFunctions} from '../../../lib/page-functions.js';
17
-
18
- /**
19
- * Calculates the maximum tree depth of the DOM.
20
- * @param {HTMLElement} element Root of the tree to look in.
21
- * @param {boolean=} deep True to include shadow roots. Defaults to true.
22
- * @return {LH.Artifacts.DOMStats}
23
- */
24
- /* c8 ignore start */
25
- function getDOMStats(element = document.body, deep = true) {
26
- let deepestElement = null;
27
- let maxDepth = -1;
28
- let maxWidth = -1;
29
- let numElements = 0;
30
- let parentWithMostChildren = null;
31
-
32
- /**
33
- * @param {Element|ShadowRoot} element
34
- * @param {number} depth
35
- */
36
- const _calcDOMWidthAndHeight = function(element, depth = 1) {
37
- if (depth > maxDepth) {
38
- deepestElement = element;
39
- maxDepth = depth;
40
- }
41
- if (element.children.length > maxWidth) {
42
- parentWithMostChildren = element;
43
- maxWidth = element.children.length;
44
- }
45
-
46
- let child = element.firstElementChild;
47
- while (child) {
48
- _calcDOMWidthAndHeight(child, depth + 1);
49
- // If element has shadow dom, traverse into that tree.
50
- if (deep && child.shadowRoot) {
51
- _calcDOMWidthAndHeight(child.shadowRoot, depth + 1);
52
- }
53
- child = child.nextElementSibling;
54
- numElements++;
55
- }
56
-
57
- return {maxDepth, maxWidth, numElements};
58
- };
59
-
60
- const result = _calcDOMWidthAndHeight(element);
61
-
62
- return {
63
- depth: {
64
- max: result.maxDepth,
65
- // @ts-expect-error - getNodeDetails put into scope via stringification
66
- ...getNodeDetails(deepestElement),
67
- },
68
- width: {
69
- max: result.maxWidth,
70
- // @ts-expect-error - getNodeDetails put into scope via stringification
71
- ...getNodeDetails(parentWithMostChildren),
72
- },
73
- totalBodyElements: result.numElements,
74
- };
75
- }
76
- /* c8 ignore stop */
77
-
78
- class DOMStats extends BaseGatherer {
79
- /** @type {LH.Gatherer.GathererMeta} */
80
- meta = {
81
- supportedModes: ['snapshot', 'navigation'],
82
- };
83
-
84
- /**
85
- * @param {LH.Gatherer.Context} passContext
86
- * @return {Promise<LH.Artifacts['DOMStats']>}
87
- */
88
- async getArtifact(passContext) {
89
- const driver = passContext.driver;
90
-
91
- await driver.defaultSession.sendCommand('DOM.enable');
92
- const results = await driver.executionContext.evaluate(getDOMStats, {
93
- args: [],
94
- useIsolation: true,
95
- deps: [pageFunctions.getNodeDetails],
96
- });
97
- await driver.defaultSession.sendCommand('DOM.disable');
98
- return results;
99
- }
100
- }
101
-
102
- export default DOMStats;
@@ -1,48 +0,0 @@
1
- export default OptimizedImages;
2
- export type SimplifiedNetworkRecord = {
3
- requestId: string;
4
- url: string;
5
- mimeType: string;
6
- resourceSize: number;
7
- };
8
- /** @typedef {{requestId: string, url: string, mimeType: string, resourceSize: number}} SimplifiedNetworkRecord */
9
- declare class OptimizedImages extends BaseGatherer {
10
- /**
11
- * @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
12
- * @return {Array<SimplifiedNetworkRecord>}
13
- */
14
- static filterImageRequests(networkRecords: Array<LH.Artifacts.NetworkRequest>): Array<SimplifiedNetworkRecord>;
15
- /** @type {LH.Gatherer.GathererMeta<'DevtoolsLog'>} */
16
- meta: LH.Gatherer.GathererMeta<"DevtoolsLog">;
17
- _encodingStartAt: number;
18
- /**
19
- * @param {LH.Gatherer.ProtocolSession} session
20
- * @param {string} requestId
21
- * @param {'jpeg'|'webp'} encoding Either webp or jpeg.
22
- * @return {Promise<LH.Crdp.Audits.GetEncodedResponseResponse>}
23
- */
24
- _getEncodedResponse(session: LH.Gatherer.ProtocolSession, requestId: string, encoding: "jpeg" | "webp"): Promise<LH.Crdp.Audits.GetEncodedResponseResponse>;
25
- /**
26
- * @param {LH.Gatherer.ProtocolSession} session
27
- * @param {SimplifiedNetworkRecord} networkRecord
28
- * @return {Promise<{originalSize: number, jpegSize?: number, webpSize?: number}>}
29
- */
30
- calculateImageStats(session: LH.Gatherer.ProtocolSession, networkRecord: SimplifiedNetworkRecord): Promise<{
31
- originalSize: number;
32
- jpegSize?: number;
33
- webpSize?: number;
34
- }>;
35
- /**
36
- * @param {LH.Gatherer.ProtocolSession} session
37
- * @param {Array<SimplifiedNetworkRecord>} imageRecords
38
- * @return {Promise<LH.Artifacts['OptimizedImages']>}
39
- */
40
- computeOptimizedImages(session: LH.Gatherer.ProtocolSession, imageRecords: Array<SimplifiedNetworkRecord>): Promise<LH.Artifacts["OptimizedImages"]>;
41
- /**
42
- * @param {LH.Gatherer.Context<'DevtoolsLog'>} context
43
- * @return {Promise<LH.Artifacts['OptimizedImages']>}
44
- */
45
- getArtifact(context: LH.Gatherer.Context<"DevtoolsLog">): Promise<LH.Artifacts["OptimizedImages"]>;
46
- }
47
- import BaseGatherer from '../../base-gatherer.js';
48
- //# sourceMappingURL=optimized-images.d.ts.map
@@ -1,169 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /**
8
- * @fileoverview Determines optimized jpeg/webp filesizes for all same-origin and dataURI images
9
- */
10
-
11
- import log from 'lighthouse-logger';
12
-
13
- import BaseGatherer from '../../base-gatherer.js';
14
- import UrlUtils from '../../../lib/url-utils.js';
15
- import {NetworkRequest} from '../../../lib/network-request.js';
16
- import {Sentry} from '../../../lib/sentry.js';
17
- import {NetworkRecords} from '../../../computed/network-records.js';
18
- import DevtoolsLog from '../devtools-log.js';
19
-
20
- // Image encoding can be slow and we don't want to spend forever on it.
21
- // Cap our encoding to 5 seconds, anything after that will be estimated.
22
- const MAX_TIME_TO_SPEND_ENCODING = 5000;
23
- // Cap our image file size at 2MB, anything bigger than that will be estimated.
24
- const MAX_RESOURCE_SIZE_TO_ENCODE = 2000 * 1024;
25
-
26
- const JPEG_QUALITY = 0.92;
27
- const WEBP_QUALITY = 0.85;
28
-
29
- const MINIMUM_IMAGE_SIZE = 4096; // savings of <4 KiB will be ignored in the audit anyway
30
-
31
- const IMAGE_REGEX = /^image\/((x|ms|x-ms)-)?(png|bmp|jpeg)$/;
32
-
33
- /** @typedef {{requestId: string, url: string, mimeType: string, resourceSize: number}} SimplifiedNetworkRecord */
34
-
35
- class OptimizedImages extends BaseGatherer {
36
- /** @type {LH.Gatherer.GathererMeta<'DevtoolsLog'>} */
37
- meta = {
38
- supportedModes: ['timespan', 'navigation'],
39
- dependencies: {DevtoolsLog: DevtoolsLog.symbol},
40
- };
41
-
42
- constructor() {
43
- super();
44
- this._encodingStartAt = 0;
45
- }
46
-
47
- /**
48
- * @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
49
- * @return {Array<SimplifiedNetworkRecord>}
50
- */
51
- static filterImageRequests(networkRecords) {
52
- /** @type {Set<string>} */
53
- const seenUrls = new Set();
54
- return networkRecords.reduce((prev, record) => {
55
- // Skip records that we've seen before, never finished, or came from OOPIFs/web workers.
56
- if (seenUrls.has(record.url) || !record.finished || record.sessionTargetType !== 'page') {
57
- return prev;
58
- }
59
-
60
- seenUrls.add(record.url);
61
- const isOptimizableImage = record.resourceType === NetworkRequest.TYPES.Image &&
62
- IMAGE_REGEX.test(record.mimeType);
63
-
64
- const actualResourceSize = NetworkRequest.getResourceSizeOnNetwork(record);
65
- if (isOptimizableImage && actualResourceSize > MINIMUM_IMAGE_SIZE) {
66
- prev.push({
67
- requestId: record.requestId,
68
- url: record.url,
69
- mimeType: record.mimeType,
70
- resourceSize: actualResourceSize,
71
- });
72
- }
73
-
74
- return prev;
75
- }, /** @type {Array<SimplifiedNetworkRecord>} */ ([]));
76
- }
77
-
78
- /**
79
- * @param {LH.Gatherer.ProtocolSession} session
80
- * @param {string} requestId
81
- * @param {'jpeg'|'webp'} encoding Either webp or jpeg.
82
- * @return {Promise<LH.Crdp.Audits.GetEncodedResponseResponse>}
83
- */
84
- _getEncodedResponse(session, requestId, encoding) {
85
- requestId = NetworkRequest.getRequestIdForBackend(requestId);
86
-
87
- const quality = encoding === 'jpeg' ? JPEG_QUALITY : WEBP_QUALITY;
88
- const params = {requestId, encoding, quality, sizeOnly: true};
89
- return session.sendCommand('Audits.getEncodedResponse', params);
90
- }
91
-
92
- /**
93
- * @param {LH.Gatherer.ProtocolSession} session
94
- * @param {SimplifiedNetworkRecord} networkRecord
95
- * @return {Promise<{originalSize: number, jpegSize?: number, webpSize?: number}>}
96
- */
97
- async calculateImageStats(session, networkRecord) {
98
- const originalSize = networkRecord.resourceSize;
99
- // Once we've hit our execution time limit or when the image is too big, don't try to re-encode it.
100
- // Images in this execution path will fallback to byte-per-pixel heuristics on the audit side.
101
- if (Date.now() - this._encodingStartAt > MAX_TIME_TO_SPEND_ENCODING ||
102
- originalSize > MAX_RESOURCE_SIZE_TO_ENCODE) {
103
- return {originalSize, jpegSize: undefined, webpSize: undefined};
104
- }
105
-
106
- const jpegData = await this._getEncodedResponse(session, networkRecord.requestId, 'jpeg');
107
- const webpData = await this._getEncodedResponse(session, networkRecord.requestId, 'webp');
108
-
109
- return {
110
- originalSize,
111
- jpegSize: jpegData.encodedSize,
112
- webpSize: webpData.encodedSize,
113
- };
114
- }
115
-
116
- /**
117
- * @param {LH.Gatherer.ProtocolSession} session
118
- * @param {Array<SimplifiedNetworkRecord>} imageRecords
119
- * @return {Promise<LH.Artifacts['OptimizedImages']>}
120
- */
121
- async computeOptimizedImages(session, imageRecords) {
122
- this._encodingStartAt = Date.now();
123
-
124
- /** @type {LH.Artifacts['OptimizedImages']} */
125
- const results = [];
126
-
127
- for (const record of imageRecords) {
128
- try {
129
- const stats = await this.calculateImageStats(session, record);
130
- /** @type {LH.Artifacts.OptimizedImage} */
131
- const image = {failed: false, ...stats, ...record};
132
- results.push(image);
133
- } catch (err) {
134
- log.warn('optimized-images', err.message, record.url);
135
-
136
- // Track this with Sentry since these errors aren't surfaced anywhere else, but we don't
137
- // want to tank the entire run due to a single image.
138
- Sentry.captureException(err, {
139
- tags: {gatherer: 'OptimizedImages'},
140
- extra: {imageUrl: UrlUtils.elideDataURI(record.url)},
141
- level: 'warning',
142
- });
143
-
144
- /** @type {LH.Artifacts.OptimizedImageError} */
145
- const imageError = {failed: true, errMsg: err.message, ...record};
146
- results.push(imageError);
147
- }
148
- }
149
-
150
- return results;
151
- }
152
-
153
- /**
154
- * @param {LH.Gatherer.Context<'DevtoolsLog'>} context
155
- * @return {Promise<LH.Artifacts['OptimizedImages']>}
156
- */
157
- async getArtifact(context) {
158
- const devtoolsLog = context.dependencies.DevtoolsLog;
159
- const networkRecords = await NetworkRecords.request(devtoolsLog, context);
160
-
161
- const imageRecords = OptimizedImages
162
- .filterImageRequests(networkRecords)
163
- .sort((a, b) => b.resourceSize - a.resourceSize);
164
-
165
- return await this.computeOptimizedImages(context.driver.defaultSession, imageRecords);
166
- }
167
- }
168
-
169
- export default OptimizedImages;
@@ -1,23 +0,0 @@
1
- export default ResponseCompression;
2
- declare class ResponseCompression extends BaseGatherer {
3
- /**
4
- * @param {LH.Artifacts.NetworkRequest[]} networkRecords
5
- * @return {LH.Artifacts['ResponseCompression']}
6
- */
7
- static filterUnoptimizedResponses(networkRecords: LH.Artifacts.NetworkRequest[]): LH.Artifacts["ResponseCompression"];
8
- /** @type {LH.Gatherer.GathererMeta<'DevtoolsLog'>} */
9
- meta: LH.Gatherer.GathererMeta<"DevtoolsLog">;
10
- /**
11
- * @param {LH.Gatherer.Context} context
12
- * @param {LH.Artifacts.NetworkRequest[]} networkRecords
13
- * @return {Promise<LH.Artifacts['ResponseCompression']>}
14
- */
15
- getCompressibleRecords(context: LH.Gatherer.Context, networkRecords: LH.Artifacts.NetworkRequest[]): Promise<LH.Artifacts["ResponseCompression"]>;
16
- /**
17
- * @param {LH.Gatherer.Context<'DevtoolsLog'>} context
18
- * @return {Promise<LH.Artifacts['ResponseCompression']>}
19
- */
20
- getArtifact(context: LH.Gatherer.Context<"DevtoolsLog">): Promise<LH.Artifacts["ResponseCompression"]>;
21
- }
22
- import BaseGatherer from '../../base-gatherer.js';
23
- //# sourceMappingURL=response-compression.d.ts.map
@@ -1,136 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /**
8
- * @fileoverview Determines optimized gzip/br/deflate filesizes for all responses by
9
- * checking the content-encoding header.
10
- */
11
-
12
-
13
- import {Buffer} from 'buffer';
14
- import {gzip} from 'zlib';
15
-
16
- import log from 'lighthouse-logger';
17
-
18
- import BaseGatherer from '../../base-gatherer.js';
19
- import UrlUtils from '../../../lib/url-utils.js';
20
- import {NetworkRequest} from '../../../lib/network-request.js';
21
- import DevtoolsLog from '../devtools-log.js';
22
- import {fetchResponseBodyFromCache} from '../../driver/network.js';
23
- import {NetworkRecords} from '../../../computed/network-records.js';
24
-
25
- const CHROME_EXTENSION_PROTOCOL = 'chrome-extension:';
26
- const binaryMimeTypes = ['image', 'audio', 'video'];
27
- /** @type {LH.Crdp.Network.ResourceType[]} */
28
- const textResourceTypes = [
29
- NetworkRequest.TYPES.Document,
30
- NetworkRequest.TYPES.Script,
31
- NetworkRequest.TYPES.Stylesheet,
32
- NetworkRequest.TYPES.XHR,
33
- NetworkRequest.TYPES.Fetch,
34
- NetworkRequest.TYPES.EventSource,
35
- ];
36
-
37
- class ResponseCompression extends BaseGatherer {
38
- /** @type {LH.Gatherer.GathererMeta<'DevtoolsLog'>} */
39
- meta = {
40
- supportedModes: ['timespan', 'navigation'],
41
- dependencies: {DevtoolsLog: DevtoolsLog.symbol},
42
- };
43
-
44
- /**
45
- * @param {LH.Artifacts.NetworkRequest[]} networkRecords
46
- * @return {LH.Artifacts['ResponseCompression']}
47
- */
48
- static filterUnoptimizedResponses(networkRecords) {
49
- /** @type {LH.Artifacts['ResponseCompression']} */
50
- const unoptimizedResponses = [];
51
-
52
- networkRecords.forEach(record => {
53
- if (record.sessionTargetType !== 'page') return;
54
-
55
- const mimeType = record.mimeType;
56
- const resourceType = record.resourceType || NetworkRequest.TYPES.Other;
57
- const resourceSize = record.resourceSize;
58
-
59
- const isBinaryResource = mimeType && binaryMimeTypes.some(type => mimeType.startsWith(type));
60
- const isTextResource = !isBinaryResource && textResourceTypes.includes(resourceType);
61
- const isChromeExtensionResource = record.url.startsWith(CHROME_EXTENSION_PROTOCOL);
62
-
63
- if (!isTextResource || !resourceSize || !record.finished ||
64
- isChromeExtensionResource || !record.transferSize || record.statusCode === 304) {
65
- return;
66
- }
67
-
68
- if (!NetworkRequest.isContentEncoded(record)) {
69
- unoptimizedResponses.push({
70
- requestId: record.requestId,
71
- url: record.url,
72
- mimeType: mimeType,
73
- transferSize: record.transferSize,
74
- resourceSize: resourceSize,
75
- gzipSize: 0,
76
- });
77
- }
78
- });
79
-
80
- return unoptimizedResponses;
81
- }
82
-
83
- /**
84
- * @param {LH.Gatherer.Context} context
85
- * @param {LH.Artifacts.NetworkRequest[]} networkRecords
86
- * @return {Promise<LH.Artifacts['ResponseCompression']>}
87
- */
88
- async getCompressibleRecords(context, networkRecords) {
89
- const session = context.driver.defaultSession;
90
- const textRecords = ResponseCompression.filterUnoptimizedResponses(networkRecords);
91
-
92
- return Promise.all(textRecords.map(record => {
93
- return fetchResponseBodyFromCache(session, record.requestId).then(content => {
94
- // if we don't have any content, gzipSize is already set to 0
95
- if (!content) {
96
- return record;
97
- }
98
-
99
- return new Promise((resolve, reject) => {
100
- return gzip(content, (err, res) => {
101
- if (err) {
102
- return reject(err);
103
- }
104
-
105
- // get gzip size
106
- record.gzipSize = Buffer.byteLength(res, 'utf8');
107
-
108
- resolve(record);
109
- });
110
- });
111
- }).catch(err => {
112
- const isExpectedError = err?.message?.includes('No resource with given identifier found');
113
- if (!isExpectedError) {
114
- err.extra = {url: UrlUtils.elideDataURI(record.url)};
115
- throw err;
116
- }
117
-
118
- log.error('ResponseCompression', err.message);
119
- record.gzipSize = undefined;
120
- return record;
121
- });
122
- }));
123
- }
124
-
125
- /**
126
- * @param {LH.Gatherer.Context<'DevtoolsLog'>} context
127
- * @return {Promise<LH.Artifacts['ResponseCompression']>}
128
- */
129
- async getArtifact(context) {
130
- const devtoolsLog = context.dependencies.DevtoolsLog;
131
- const networkRecords = await NetworkRecords.request(devtoolsLog, context);
132
- return this.getCompressibleRecords(context, networkRecords);
133
- }
134
- }
135
-
136
- export default ResponseCompression;
@@ -1,20 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2019 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- declare module 'parse-cache-control' {
8
- // Follows the potential settings of cache-control, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
9
- interface CacheHeaders {
10
- 'max-age'?: number;
11
- 'must-revalidate'?: boolean;
12
- 'no-cache'?: boolean;
13
- 'no-store'?: boolean;
14
- 'private'?: boolean;
15
- 'stale-while-revalidate'?: boolean;
16
- }
17
-
18
- function ParseCacheControl(headers?: string): CacheHeaders | null;
19
- export = ParseCacheControl;
20
- }