lighthouse 9.5.0-dev.20221128 → 9.5.0-dev.20221129

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.
@@ -124,10 +124,14 @@ class NetworkRequest {
124
124
  this.parsedURL = /** @type {ParsedURL} */ ({scheme: ''});
125
125
  this.documentURL = '';
126
126
 
127
+ /**
128
+ * When the network service is about to handle a request, ie. just before going to the
129
+ * HTTP cache or going to the network for DNS/connection setup, in milliseconds.
130
+ */
127
131
  this.startTime = -1;
128
- /** @type {number} */
132
+ /** When the last byte of the response body is received, in milliseconds. */
129
133
  this.endTime = -1;
130
- /** @type {number} */
134
+ /** When the last byte of the response headers is received, in milliseconds. */
131
135
  this.responseReceivedTime = -1;
132
136
 
133
137
  // Go read the comment on _updateTransferSizeForLightrider.
@@ -217,7 +221,8 @@ class NetworkRequest {
217
221
  };
218
222
  this.isSecure = UrlUtils.isSecureScheme(this.parsedURL.scheme);
219
223
 
220
- this.startTime = data.timestamp;
224
+ // Expected to be overriden with better value in `_recomputeTimesWithResourceTiming`.
225
+ this.startTime = data.timestamp * 1000;
221
226
 
222
227
  this.requestMethod = data.request.method;
223
228
 
@@ -261,7 +266,7 @@ class NetworkRequest {
261
266
  if (this.finished) return;
262
267
 
263
268
  this.finished = true;
264
- this.endTime = data.timestamp;
269
+ this.endTime = data.timestamp * 1000;
265
270
  if (data.encodedDataLength >= 0) {
266
271
  this.transferSize = data.encodedDataLength;
267
272
  }
@@ -279,7 +284,7 @@ class NetworkRequest {
279
284
  if (this.finished) return;
280
285
 
281
286
  this.finished = true;
282
- this.endTime = data.timestamp;
287
+ this.endTime = data.timestamp * 1000;
283
288
 
284
289
  this.failed = true;
285
290
  this.resourceType = data.type && RESOURCE_TYPES[data.type];
@@ -305,7 +310,7 @@ class NetworkRequest {
305
310
  this._onResponse(data.redirectResponse, data.timestamp, data.type);
306
311
  this.resourceType = undefined;
307
312
  this.finished = true;
308
- this.endTime = data.timestamp;
313
+ this.endTime = data.timestamp * 1000;
309
314
 
310
315
  this._updateResponseReceivedTimeIfNecessary();
311
316
  }
@@ -319,7 +324,7 @@ class NetworkRequest {
319
324
 
320
325
  /**
321
326
  * @param {LH.Crdp.Network.Response} response
322
- * @param {number} timestamp
327
+ * @param {number} timestamp in seconds
323
328
  * @param {LH.Crdp.Network.ResponseReceivedEvent['type']=} resourceType
324
329
  */
325
330
  _onResponse(response, timestamp, resourceType) {
@@ -330,7 +335,7 @@ class NetworkRequest {
330
335
 
331
336
  if (response.protocol) this.protocol = response.protocol;
332
337
 
333
- this.responseReceivedTime = timestamp;
338
+ this.responseReceivedTime = timestamp * 1000;
334
339
 
335
340
  this.transferSize = response.encodedDataLength;
336
341
  if (typeof response.fromDiskCache === 'boolean') this.fromDiskCache = response.fromDiskCache;
@@ -364,8 +369,8 @@ class NetworkRequest {
364
369
  // Take startTime and responseReceivedTime from timing data for better accuracy.
365
370
  // Timing's requestTime is a baseline in seconds, rest of the numbers there are ticks in millis.
366
371
  // TODO: This skips the "queuing time" before the netstack has taken over ... is this a mistake?
367
- this.startTime = timing.requestTime;
368
- const headersReceivedTime = timing.requestTime + timing.receiveHeadersEnd / 1000;
372
+ this.startTime = timing.requestTime * 1000;
373
+ const headersReceivedTime = this.startTime + timing.receiveHeadersEnd;
369
374
  if (!this.responseReceivedTime || this.responseReceivedTime < 0) {
370
375
  this.responseReceivedTime = headersReceivedTime;
371
376
  }
@@ -478,7 +483,7 @@ class NetworkRequest {
478
483
  }
479
484
 
480
485
  this.lrStatistics = {
481
- endTimeDeltaMs: (this.endTime - (this.startTime + (totalMs / 1000))) * 1000,
486
+ endTimeDeltaMs: this.endTime - (this.startTime + totalMs),
482
487
  TCPMs: TCPMs,
483
488
  requestMs: requestMs,
484
489
  responseMs: responseMs,
package/core/runner.js CHANGED
@@ -521,5 +521,4 @@ class Runner {
521
521
  }
522
522
  }
523
523
 
524
- // TODO(esmodules): make this not a class.
525
524
  export {Runner};
@@ -3438,6 +3438,7 @@ class I18n {
3438
3438
 
3439
3439
  this._locale = locale;
3440
3440
  this._strings = strings;
3441
+ this._cachedNumberFormatters = new Map();
3441
3442
  }
3442
3443
 
3443
3444
  get strings() {
@@ -3472,7 +3473,24 @@ class I18n {
3472
3473
  number = 0;
3473
3474
  }
3474
3475
 
3475
- return new Intl.NumberFormat(this._locale, opts).format(number).replace(' ', NBSP2);
3476
+ let formatter;
3477
+ // eslint-disable-next-line max-len
3478
+ const cacheKey = [
3479
+ opts.minimumFractionDigits,
3480
+ opts.maximumFractionDigits,
3481
+ opts.style,
3482
+ opts.unit,
3483
+ opts.unitDisplay,
3484
+ this._locale,
3485
+ ].join('');
3486
+
3487
+ formatter = this._cachedNumberFormatters.get(cacheKey);
3488
+ if (!formatter) {
3489
+ formatter = new Intl.NumberFormat(this._locale, opts);
3490
+ this._cachedNumberFormatters.set(cacheKey, formatter);
3491
+ }
3492
+
3493
+ return formatter.format(number).replace(' ', NBSP2);
3476
3494
  }
3477
3495
 
3478
3496
  /**
@@ -26,7 +26,7 @@
26
26
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
27
27
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
28
28
  */
29
- const ta=1024,ia=1048576;class oa{constructor(e,a){"en-XA"===e&&(e="de"),this._locale=e,this._strings=a}get strings(){return this._strings}_formatNumberWithGranularity(e,a,n={}){if(void 0!==a){const t=-Math.log10(a);Number.isInteger(t)||(console.warn(`granularity of ${a} is invalid. Using 1 instead`),a=1),a<1&&((n={...n}).minimumFractionDigits=n.maximumFractionDigits=Math.ceil(t)),e=Math.round(e/a)*a,Object.is(e,-0)&&(e=0)}else Math.abs(e)<5e-4&&(e=0);return new Intl.NumberFormat(this._locale,n).format(e).replace(" "," ")}formatNumber(e,a){return this._formatNumberWithGranularity(e,a)}formatInteger(e){return this._formatNumberWithGranularity(e,1)}formatPercent(e){return new Intl.NumberFormat(this._locale,{style:"percent"}).format(e)}formatBytesToKiB(e,a){return this._formatNumberWithGranularity(e/ta,a)+" KiB"}formatBytesToMiB(e,a){return this._formatNumberWithGranularity(e/ia,a)+" MiB"}formatBytes(e,a=1){return this._formatNumberWithGranularity(e,a,{style:"unit",unit:"byte",unitDisplay:"long"})}formatBytesWithBestUnit(e,a){return e>=ia?this.formatBytesToMiB(e,a):e>=ta?this.formatBytesToKiB(e,a):this._formatNumberWithGranularity(e,a,{style:"unit",unit:"byte",unitDisplay:"narrow"})}formatKbps(e,a){return this._formatNumberWithGranularity(e,a,{style:"unit",unit:"kilobit-per-second",unitDisplay:"short"})}formatMilliseconds(e,a){return this._formatNumberWithGranularity(e,a,{style:"unit",unit:"millisecond",unitDisplay:"short"})}formatSeconds(e,a){return this._formatNumberWithGranularity(e/1e3,a,{style:"unit",unit:"second",unitDisplay:"short"})}formatDateTime(e){const a={month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"numeric",timeZoneName:"short"};let n;try{n=new Intl.DateTimeFormat(this._locale,a)}catch(e){a.timeZone="UTC",n=new Intl.DateTimeFormat(this._locale,a)}return n.format(new Date(e))}formatDuration(e){let a=e/1e3;if(0===Math.round(a))return"None";const n=[],t={day:86400,hour:3600,minute:60,second:1};return Object.keys(t).forEach((e=>{const i=t[e],o=Math.floor(a/i);if(o>0){a-=o*i;const t=this._formatNumberWithGranularity(o,1,{style:"unit",unit:e,unitDisplay:"narrow"});n.push(t)}})),n.join(" ")}}
29
+ const ta=1024,ia=1048576;class oa{constructor(e,a){"en-XA"===e&&(e="de"),this._locale=e,this._strings=a,this._cachedNumberFormatters=new Map}get strings(){return this._strings}_formatNumberWithGranularity(e,a,n={}){if(void 0!==a){const t=-Math.log10(a);Number.isInteger(t)||(console.warn(`granularity of ${a} is invalid. Using 1 instead`),a=1),a<1&&((n={...n}).minimumFractionDigits=n.maximumFractionDigits=Math.ceil(t)),e=Math.round(e/a)*a,Object.is(e,-0)&&(e=0)}else Math.abs(e)<5e-4&&(e=0);let t;const i=[n.minimumFractionDigits,n.maximumFractionDigits,n.style,n.unit,n.unitDisplay,this._locale].join("");return t=this._cachedNumberFormatters.get(i),t||(t=new Intl.NumberFormat(this._locale,n),this._cachedNumberFormatters.set(i,t)),t.format(e).replace(" "," ")}formatNumber(e,a){return this._formatNumberWithGranularity(e,a)}formatInteger(e){return this._formatNumberWithGranularity(e,1)}formatPercent(e){return new Intl.NumberFormat(this._locale,{style:"percent"}).format(e)}formatBytesToKiB(e,a){return this._formatNumberWithGranularity(e/ta,a)+" KiB"}formatBytesToMiB(e,a){return this._formatNumberWithGranularity(e/ia,a)+" MiB"}formatBytes(e,a=1){return this._formatNumberWithGranularity(e,a,{style:"unit",unit:"byte",unitDisplay:"long"})}formatBytesWithBestUnit(e,a){return e>=ia?this.formatBytesToMiB(e,a):e>=ta?this.formatBytesToKiB(e,a):this._formatNumberWithGranularity(e,a,{style:"unit",unit:"byte",unitDisplay:"narrow"})}formatKbps(e,a){return this._formatNumberWithGranularity(e,a,{style:"unit",unit:"kilobit-per-second",unitDisplay:"short"})}formatMilliseconds(e,a){return this._formatNumberWithGranularity(e,a,{style:"unit",unit:"millisecond",unitDisplay:"short"})}formatSeconds(e,a){return this._formatNumberWithGranularity(e/1e3,a,{style:"unit",unit:"second",unitDisplay:"short"})}formatDateTime(e){const a={month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"numeric",timeZoneName:"short"};let n;try{n=new Intl.DateTimeFormat(this._locale,a)}catch(e){a.timeZone="UTC",n=new Intl.DateTimeFormat(this._locale,a)}return n.format(new Date(e))}formatDuration(e){let a=e/1e3;if(0===Math.round(a))return"None";const n=[],t={day:86400,hour:3600,minute:60,second:1};return Object.keys(t).forEach((e=>{const i=t[e],o=Math.floor(a/i);if(o>0){a-=o*i;const t=this._formatNumberWithGranularity(o,1,{style:"unit",unit:e,unitDisplay:"narrow"});n.push(t)}})),n.join(" ")}}
30
30
  /**
31
31
  * @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
32
32
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0