lighthouse 9.1.0-dev.20211209 → 9.1.0-dev.20211213

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.
@@ -147,6 +147,9 @@ class PageDependencyGraph {
147
147
  const directInitiatorRequest = node.record.initiatorRequest || rootNode.record;
148
148
  const directInitiatorNode =
149
149
  networkNodeOutput.idToNodeMap.get(directInitiatorRequest.requestId) || rootNode;
150
+ const canDependOnInitiator =
151
+ !directInitiatorNode.isDependentOn(node) &&
152
+ node.canDependOn(directInitiatorNode);
150
153
  const initiators = PageDependencyGraph.getNetworkInitiators(node.record);
151
154
  if (initiators.length) {
152
155
  initiators.forEach(initiator => {
@@ -156,16 +159,18 @@ class PageDependencyGraph {
156
159
  parentCandidates[0].startTime <= node.startTime &&
157
160
  !parentCandidates[0].isDependentOn(node)) {
158
161
  node.addDependency(parentCandidates[0]);
159
- } else if (!directInitiatorNode.isDependentOn(node)) {
162
+ } else if (canDependOnInitiator) {
160
163
  directInitiatorNode.addDependent(node);
161
164
  }
162
165
  });
163
- } else if (!directInitiatorNode.isDependentOn(node)) {
166
+ } else if (canDependOnInitiator) {
164
167
  directInitiatorNode.addDependent(node);
165
168
  }
166
169
 
167
170
  // Make sure the nodes are attached to the graph if the initiator information was invalid.
168
- if (node !== rootNode && node.getDependencies().length === 0) node.addDependency(rootNode);
171
+ if (node !== rootNode && node.getDependencies().length === 0 && node.canDependOn(rootNode)) {
172
+ node.addDependency(rootNode);
173
+ }
169
174
 
170
175
  if (!node.record.redirects) return;
171
176
 
@@ -321,7 +326,8 @@ class PageDependencyGraph {
321
326
  }
322
327
  }
323
328
 
324
- if (node.getNumberOfDependencies() === 0) {
329
+ // Nodes starting before the root node cannot depend on it.
330
+ if (node.getNumberOfDependencies() === 0 && node.canDependOn(rootNode)) {
325
331
  node.addDependency(rootNode);
326
332
  }
327
333
  }
@@ -388,23 +394,27 @@ class PageDependencyGraph {
388
394
  const networkNodeOutput = PageDependencyGraph.getNetworkNodeOutput(networkRecords);
389
395
  const cpuNodes = PageDependencyGraph.getCPUNodes(processedTrace);
390
396
 
391
- // The root request is the earliest network request, using position in networkRecords array to break ties.
392
- const rootRequest = networkRecords.reduce((min, r) => (r.startTime < min.startTime ? r : min));
393
- const rootNode = networkNodeOutput.idToNodeMap.get(rootRequest.requestId);
394
397
  // The main document request is the earliest network request *of type document*.
395
398
  // This will be different from the root request when there are server redirects.
396
399
  const mainDocumentRequest = NetworkAnalyzer.findMainDocument(networkRecords);
397
400
  const mainDocumentNode = networkNodeOutput.idToNodeMap.get(mainDocumentRequest.requestId);
398
-
399
- if (!rootNode || !mainDocumentNode) {
400
- // Should always be found.
401
- throw new Error(`${rootNode ? 'mainDocument' : 'root'}Node not found.`);
401
+ if (!mainDocumentNode) {
402
+ // mainDocumentNode should always be found.
403
+ throw new Error('mainDocumentNode not found.');
402
404
  }
403
405
 
404
- if (mainDocumentNode !== rootNode &&
405
- (!mainDocumentNode.record.redirects ||
406
- !mainDocumentNode.record.redirects.includes(rootNode.record))) {
407
- throw new Error('Root node was not in redirect chain of mainDocument');
406
+ // The root request is the earliest request in the main document redirect chain.
407
+ // Will be undefined if there were no redirects.
408
+ const rootRequest = mainDocumentNode.record.redirects && mainDocumentNode.record.redirects[0];
409
+
410
+ let rootNode;
411
+ if (rootRequest) {
412
+ // rootNode should always be found.
413
+ rootNode = rootRequest && networkNodeOutput.idToNodeMap.get(rootRequest.requestId);
414
+ if (!rootNode) throw new Error('rootNode not found');
415
+ } else {
416
+ // Use main document as root if there were no redirects.
417
+ rootNode = mainDocumentNode;
408
418
  }
409
419
 
410
420
  PageDependencyGraph.linkNetworkNodes(rootNode, networkNodeOutput);
@@ -27,6 +27,8 @@ const Trace = require('../../gather/gatherers/trace.js');
27
27
  const DevtoolsLog = require('../../gather/gatherers/devtools-log.js');
28
28
  const NetworkRecords = require('../../computed/network-records.js');
29
29
 
30
+ /** @typedef {{skipAboutBlank?: boolean}} InternalOptions */
31
+
30
32
  /**
31
33
  * @typedef NavigationContext
32
34
  * @property {Driver} driver
@@ -35,17 +37,20 @@ const NetworkRecords = require('../../computed/network-records.js');
35
37
  * @property {string} requestedUrl
36
38
  * @property {LH.FRBaseArtifacts} baseArtifacts
37
39
  * @property {Map<string, LH.ArbitraryEqualityMap>} computedCache
40
+ * @property {InternalOptions} [options]
38
41
  */
39
42
 
40
43
  /** @typedef {Omit<Parameters<typeof collectPhaseArtifacts>[0], 'phase'>} PhaseState */
41
44
 
42
45
  /**
43
- * @param {{driver: Driver, config: LH.Config.FRConfig, requestedUrl: string}} args
46
+ * @param {{driver: Driver, config: LH.Config.FRConfig, requestedUrl: string, options?: InternalOptions}} args
44
47
  * @return {Promise<{baseArtifacts: LH.FRBaseArtifacts}>}
45
48
  */
46
- async function _setup({driver, config, requestedUrl}) {
49
+ async function _setup({driver, config, requestedUrl, options}) {
47
50
  await driver.connect();
48
- await gotoURL(driver, defaultNavigationConfig.blankPage, {waitUntil: ['navigated']});
51
+ if (!options?.skipAboutBlank) {
52
+ await gotoURL(driver, defaultNavigationConfig.blankPage, {waitUntil: ['navigated']});
53
+ }
49
54
 
50
55
  const baseArtifacts = await getBaseArtifacts(config, driver, {gatherMode: 'navigation'});
51
56
  baseArtifacts.URL.requestedUrl = requestedUrl;
@@ -59,8 +64,10 @@ async function _setup({driver, config, requestedUrl}) {
59
64
  * @param {NavigationContext} navigationContext
60
65
  * @return {Promise<{warnings: Array<LH.IcuMessage>}>}
61
66
  */
62
- async function _setupNavigation({requestedUrl, driver, navigation, config}) {
63
- await gotoURL(driver, navigation.blankPage, {...navigation, waitUntil: ['navigated']});
67
+ async function _setupNavigation({requestedUrl, driver, navigation, config, options}) {
68
+ if (!options?.skipAboutBlank) {
69
+ await gotoURL(driver, navigation.blankPage, {...navigation, waitUntil: ['navigated']});
70
+ }
64
71
  const {warnings} = await prepare.prepareTargetForIndividualNavigation(
65
72
  driver.defaultSession,
66
73
  config.settings,
@@ -216,10 +223,10 @@ async function _navigation(navigationContext) {
216
223
  }
217
224
 
218
225
  /**
219
- * @param {{driver: Driver, config: LH.Config.FRConfig, requestedUrl: string; baseArtifacts: LH.FRBaseArtifacts, computedCache: NavigationContext['computedCache']}} args
226
+ * @param {{driver: Driver, config: LH.Config.FRConfig, requestedUrl: string; baseArtifacts: LH.FRBaseArtifacts, computedCache: NavigationContext['computedCache'], options?: InternalOptions}} args
220
227
  * @return {Promise<{artifacts: Partial<LH.FRArtifacts & LH.FRBaseArtifacts>}>}
221
228
  */
222
- async function _navigations({driver, config, requestedUrl, baseArtifacts, computedCache}) {
229
+ async function _navigations({driver, config, requestedUrl, baseArtifacts, computedCache, options}) {
223
230
  if (!config.navigations) throw new Error('No navigations configured');
224
231
 
225
232
  /** @type {Partial<LH.FRArtifacts & LH.FRBaseArtifacts>} */
@@ -235,6 +242,7 @@ async function _navigations({driver, config, requestedUrl, baseArtifacts, comput
235
242
  config,
236
243
  baseArtifacts,
237
244
  computedCache,
245
+ options,
238
246
  };
239
247
 
240
248
  let shouldHaltNavigations = false;
@@ -274,11 +282,14 @@ async function navigation(options) {
274
282
  const {url: requestedUrl, page, configContext = {}} = options;
275
283
  const {config} = initializeConfig(options.config, {...configContext, gatherMode: 'navigation'});
276
284
  const computedCache = new Map();
285
+ const internalOptions = {
286
+ skipAboutBlank: configContext.skipAboutBlank,
287
+ };
277
288
 
278
289
  return Runner.run(
279
290
  async () => {
280
291
  const driver = new Driver(page);
281
- const context = {driver, config, requestedUrl};
292
+ const context = {driver, config, requestedUrl, options: internalOptions};
282
293
  const {baseArtifacts} = await _setup(context);
283
294
  const {artifacts} = await _navigations({...context, baseArtifacts, computedCache});
284
295
  await _cleanup(context);
@@ -59,20 +59,24 @@ class UserFlow {
59
59
  */
60
60
  _getNextNavigationOptions(url, stepOptions) {
61
61
  const options = {url, ...this.options, ...stepOptions};
62
+ const configContext = {...options.configContext};
63
+ const settingsOverrides = {...configContext.settingsOverrides};
64
+
65
+ if (configContext.skipAboutBlank === undefined) {
66
+ configContext.skipAboutBlank = true;
67
+ }
62
68
 
63
69
  // On repeat navigations, we want to disable storage reset by default (i.e. it's not a cold load).
64
70
  const isSubsequentNavigation = this.steps.some(step => step.lhr.gatherMode === 'navigation');
65
71
  if (isSubsequentNavigation) {
66
- const configContext = {...options.configContext};
67
- const settingsOverrides = {...configContext.settingsOverrides};
68
72
  if (settingsOverrides.disableStorageReset === undefined) {
69
73
  settingsOverrides.disableStorageReset = true;
70
74
  }
71
-
72
- configContext.settingsOverrides = settingsOverrides;
73
- options.configContext = configContext;
74
75
  }
75
76
 
77
+ configContext.settingsOverrides = settingsOverrides;
78
+ options.configContext = configContext;
79
+
76
80
  return options;
77
81
  }
78
82
 
@@ -211,6 +211,7 @@ class ExecutionContext {
211
211
  window.__nativePromise = window.Promise;
212
212
  window.__nativeURL = window.URL;
213
213
  window.__nativePerformance = window.performance;
214
+ window.__nativeFetch = window.fetch;
214
215
  window.__ElementMatches = window.Element.prototype.matches;
215
216
  // Ensure the native `performance.now` is not overwritable.
216
217
  const performance = window.performance;
@@ -232,6 +233,7 @@ class ExecutionContext {
232
233
  'const Promise = globalThis.__nativePromise || globalThis.Promise',
233
234
  'const URL = globalThis.__nativeURL || globalThis.URL',
234
235
  'const performance = globalThis.__nativePerformance || globalThis.performance',
236
+ 'const fetch = globalThis.__nativeFetch || globalThis.fetch',
235
237
  ].join(';\n');
236
238
 
237
239
  /**
@@ -345,6 +345,14 @@ class BaseNode {
345
345
 
346
346
  return false;
347
347
  }
348
+
349
+ /**
350
+ * @param {Node} node
351
+ * @return {boolean}
352
+ */
353
+ canDependOn(node) {
354
+ return node.startTime <= this.startTime;
355
+ }
348
356
  }
349
357
 
350
358
  BaseNode.TYPES = /** @type {{NETWORK: 'network', CPU: 'cpu'}} */({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse",
3
- "version": "9.1.0-dev.20211209",
3
+ "version": "9.1.0-dev.20211213",
4
4
  "description": "Automated auditing, performance metrics, and best practices for the web.",
5
5
  "main": "./lighthouse-core/index.js",
6
6
  "bin": {
@@ -80,10 +80,11 @@
80
80
  --audit-group-padding-vertical: 8px;
81
81
  --audit-margin-horizontal: 5px;
82
82
  --audit-padding-vertical: 8px;
83
- --category-padding: calc(var(--default-padding) * 6) calc(var(--default-padding) * 4) calc(var(--default-padding) * 4);
83
+ --category-padding: calc(var(--default-padding) * 6) var(--edge-gap-padding) calc(var(--default-padding) * 4);
84
84
  --chevron-line-stroke: var(--color-gray-600);
85
85
  --chevron-size: 12px;
86
86
  --default-padding: 8px;
87
+ --edge-gap-padding: calc(var(--default-padding) * 4);
87
88
  --env-item-background-color: var(--color-gray-100);
88
89
  --env-item-font-size: 28px;
89
90
  --env-item-line-height: 36px;
@@ -124,11 +125,12 @@
124
125
  --report-icon-size: var(--score-icon-background-size);
125
126
  --report-line-height: 24px;
126
127
  --report-line-height-secondary: 20px;
127
- --report-min-width: 360px;
128
128
  --report-monospace-font-size: calc(var(--report-font-size) * 0.85);
129
129
  --report-text-color-secondary: var(--color-gray-800);
130
130
  --report-text-color: var(--color-gray-900);
131
- --report-content-width: calc(60 * var(--report-font-size)); /* defaults to 840px */
131
+ --report-content-max-width: calc(60 * var(--report-font-size)); /* defaults to 840px */
132
+ --report-content-min-width: 360px;
133
+ --report-content-max-width-minus-edge-gap: calc(var(--report-content-max-width) - var(--edge-gap-padding) * 2);
132
134
  --score-container-padding: 8px;
133
135
  --score-icon-background-size: 24px;
134
136
  --score-icon-margin-left: 6px;
@@ -217,7 +219,7 @@
217
219
  @media only screen and (max-width: 480px) {
218
220
  .lh-vars {
219
221
  --audit-group-margin-bottom: 20px;
220
- --category-padding: 12px;
222
+ --edge-gap-padding: var(--default-padding);
221
223
  --env-name-min-width: 120px;
222
224
  --gauge-circle-size-big: 96px;
223
225
  --gauge-circle-size: 72px;
@@ -686,6 +688,7 @@
686
688
  grid-auto-rows: 1fr;
687
689
  grid-template-columns: 1fr 1fr;
688
690
  grid-column-gap: var(--report-line-height);
691
+ margin-bottom: var(--default-padding);
689
692
  }
690
693
 
691
694
  .lh-metric {
@@ -1070,8 +1073,13 @@
1070
1073
  word-wrap: break-word;
1071
1074
  }
1072
1075
 
1076
+ .lh-header-container .lh-scores-wrapper {
1077
+ border-bottom: 1px solid var(--color-gray-200);
1078
+ }
1079
+
1080
+
1073
1081
  .lh-report {
1074
- min-width: var(--report-min-width);
1082
+ min-width: var(--report-content-min-width);
1075
1083
  }
1076
1084
 
1077
1085
  .lh-exception {
@@ -1103,8 +1111,7 @@
1103
1111
  color: var(--toplevel-warning-text-color);
1104
1112
  margin-left: auto;
1105
1113
  margin-right: auto;
1106
- --content-width-minus-category-padding-sides: calc(var(--report-content-width) - calc(var(--default-padding) * 4) * 2);
1107
- max-width: var(--content-width-minus-category-padding-sides);
1114
+ max-width: var(--report-content-max-width-minus-edge-gap);
1108
1115
  padding: var(--toplevel-warning-padding);
1109
1116
  border-radius: 8px;
1110
1117
  }
@@ -1397,7 +1404,7 @@
1397
1404
 
1398
1405
  .lh-category {
1399
1406
  padding: var(--category-padding);
1400
- max-width: var(--report-content-width);
1407
+ max-width: var(--report-content-max-width);
1401
1408
  margin: 0 auto;
1402
1409
 
1403
1410
  --sticky-header-height: calc(var(--gauge-circle-size-sm) + var(--score-container-padding) * 2);
@@ -1413,10 +1420,6 @@
1413
1420
  border-bottom: 1px solid var(--color-gray-200);
1414
1421
  }
1415
1422
 
1416
- .lh-category-wrapper:first-of-type {
1417
- border-top: 1px solid var(--color-gray-200);
1418
- }
1419
-
1420
1423
  .lh-category-header {
1421
1424
  margin-bottom: var(--section-padding-vertical);
1422
1425
  }
@@ -512,7 +512,7 @@ limitations under the License.
512
512
  <style>
513
513
  .lh-footer {
514
514
  padding: var(--footer-padding-vertical) calc(var(--default-padding) * 2);
515
- max-width: var(--report-content-width);
515
+ max-width: var(--report-content-max-width);
516
516
  margin: 0 auto;
517
517
  }
518
518
  .lh-footer .lh-generated {