lighthouse 8.5.1-dev.20211012 → 8.5.1

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 (172) hide show
  1. package/dist/report/flow.js +149 -0
  2. package/dist/report/standalone.js +228 -0
  3. package/flow-report/assets/styles.css +9 -272
  4. package/flow-report/jest.config.js +1 -1
  5. package/flow-report/src/app.tsx +9 -31
  6. package/flow-report/src/common.tsx +7 -86
  7. package/flow-report/src/icons.tsx +3 -20
  8. package/flow-report/src/sidebar/sidebar.tsx +16 -11
  9. package/flow-report/src/summary/category.tsx +24 -42
  10. package/flow-report/src/summary/summary.tsx +29 -32
  11. package/flow-report/src/topbar.tsx +4 -54
  12. package/flow-report/src/util.ts +1 -26
  13. package/flow-report/src/wrappers/report-renderer.tsx +1 -1
  14. package/flow-report/src/wrappers/report.tsx +21 -6
  15. package/flow-report/test/app-test.tsx +13 -17
  16. package/flow-report/test/setup/env-setup.ts +0 -1
  17. package/flow-report/test/sidebar/flow-test.tsx +12 -6
  18. package/flow-report/test/sidebar/sidebar-test.tsx +13 -7
  19. package/flow-report/test/summary/category-test.tsx +34 -79
  20. package/flow-report/test/summary/summary-test.tsx +17 -11
  21. package/flow-report/test/util-test.tsx +12 -1
  22. package/flow-report/tsconfig.json +0 -1
  23. package/flow-report/types/flow-report.d.ts +1 -2
  24. package/jest.config.js +15 -1
  25. package/lighthouse-cli/bin.js +0 -5
  26. package/lighthouse-cli/cli-flags.js +3 -10
  27. package/lighthouse-cli/commands/commands.js +0 -1
  28. package/lighthouse-cli/run.js +2 -2
  29. package/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +0 -0
  30. package/lighthouse-cli/test/smokehouse/report-assert.js +4 -20
  31. package/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +1 -2
  32. package/lighthouse-core/audits/byte-efficiency/unused-javascript.js +1 -1
  33. package/lighthouse-core/audits/seo/crawlable-anchors.js +12 -10
  34. package/lighthouse-core/computed/js-bundles.js +2 -1
  35. package/lighthouse-core/computed/unused-javascript-summary.js +3 -3
  36. package/lighthouse-core/config/config.js +2 -2
  37. package/lighthouse-core/config/default-config.js +0 -5
  38. package/lighthouse-core/fraggle-rock/api.js +0 -10
  39. package/lighthouse-core/fraggle-rock/config/filters.js +3 -22
  40. package/lighthouse-core/fraggle-rock/gather/driver.js +0 -4
  41. package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +2 -2
  42. package/lighthouse-core/fraggle-rock/user-flow.js +6 -35
  43. package/lighthouse-core/gather/driver/navigation.js +0 -5
  44. package/lighthouse-core/gather/driver/prepare.js +0 -14
  45. package/lighthouse-core/gather/driver/storage.js +0 -5
  46. package/lighthouse-core/gather/gather-runner.js +2 -2
  47. package/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js +1 -5
  48. package/lighthouse-core/gather/gatherers/full-page-screenshot.js +24 -30
  49. package/{shared/localization/i18n-module.js → lighthouse-core/lib/cdt/Common.js} +8 -3
  50. package/lighthouse-core/lib/cdt/SDK.js +123 -3
  51. package/lighthouse-core/lib/cdt/generated/SourceMap.js +312 -148
  52. package/lighthouse-core/lib/csp-evaluator.js +1 -2
  53. package/lighthouse-core/lib/i18n/README.md +6 -6
  54. package/lighthouse-core/lib/i18n/i18n.js +342 -9
  55. package/{shared/localization → lighthouse-core/lib/i18n}/locales/ar-XB.json +0 -0
  56. package/{shared/localization → lighthouse-core/lib/i18n}/locales/ar.json +0 -0
  57. package/{shared/localization → lighthouse-core/lib/i18n}/locales/bg.json +0 -0
  58. package/{shared/localization → lighthouse-core/lib/i18n}/locales/ca.json +0 -0
  59. package/{shared/localization → lighthouse-core/lib/i18n}/locales/cs.json +0 -0
  60. package/{shared/localization → lighthouse-core/lib/i18n}/locales/da.json +0 -0
  61. package/{shared/localization → lighthouse-core/lib/i18n}/locales/de.json +0 -0
  62. package/{shared/localization → lighthouse-core/lib/i18n}/locales/el.json +0 -0
  63. package/{shared/localization → lighthouse-core/lib/i18n}/locales/en-GB.json +0 -0
  64. package/{shared/localization → lighthouse-core/lib/i18n}/locales/en-US.json +0 -111
  65. package/{shared/localization → lighthouse-core/lib/i18n}/locales/en-XA.json +0 -0
  66. package/{shared/localization → lighthouse-core/lib/i18n}/locales/en-XL.json +0 -111
  67. package/{shared/localization → lighthouse-core/lib/i18n}/locales/es-419.json +0 -0
  68. package/{shared/localization → lighthouse-core/lib/i18n}/locales/es.json +0 -0
  69. package/{shared/localization → lighthouse-core/lib/i18n}/locales/fi.json +0 -0
  70. package/{shared/localization → lighthouse-core/lib/i18n}/locales/fil.json +0 -0
  71. package/{shared/localization → lighthouse-core/lib/i18n}/locales/fr.json +0 -0
  72. package/{shared/localization → lighthouse-core/lib/i18n}/locales/he.json +0 -0
  73. package/{shared/localization → lighthouse-core/lib/i18n}/locales/hi.json +0 -0
  74. package/{shared/localization → lighthouse-core/lib/i18n}/locales/hr.json +0 -0
  75. package/{shared/localization → lighthouse-core/lib/i18n}/locales/hu.json +0 -0
  76. package/{shared/localization → lighthouse-core/lib/i18n}/locales/id.json +0 -0
  77. package/{shared/localization → lighthouse-core/lib/i18n}/locales/it.json +0 -0
  78. package/{shared/localization → lighthouse-core/lib/i18n}/locales/ja.json +0 -0
  79. package/{shared/localization → lighthouse-core/lib/i18n}/locales/ko.json +0 -0
  80. package/{shared/localization → lighthouse-core/lib/i18n}/locales/lt.json +0 -0
  81. package/{shared/localization → lighthouse-core/lib/i18n}/locales/lv.json +0 -0
  82. package/{shared/localization → lighthouse-core/lib/i18n}/locales/nl.json +0 -0
  83. package/{shared/localization → lighthouse-core/lib/i18n}/locales/no.json +0 -0
  84. package/{shared/localization → lighthouse-core/lib/i18n}/locales/pl.json +0 -0
  85. package/{shared/localization → lighthouse-core/lib/i18n}/locales/pt-PT.json +0 -0
  86. package/{shared/localization → lighthouse-core/lib/i18n}/locales/pt.json +0 -0
  87. package/{shared/localization → lighthouse-core/lib/i18n}/locales/ro.json +0 -0
  88. package/{shared/localization → lighthouse-core/lib/i18n}/locales/ru.json +0 -0
  89. package/{shared/localization → lighthouse-core/lib/i18n}/locales/sk.json +0 -0
  90. package/{shared/localization → lighthouse-core/lib/i18n}/locales/sl.json +0 -0
  91. package/{shared/localization → lighthouse-core/lib/i18n}/locales/sr-Latn.json +0 -0
  92. package/{shared/localization → lighthouse-core/lib/i18n}/locales/sr.json +0 -0
  93. package/{shared/localization → lighthouse-core/lib/i18n}/locales/sv.json +0 -0
  94. package/{shared/localization → lighthouse-core/lib/i18n}/locales/ta.json +0 -0
  95. package/{shared/localization → lighthouse-core/lib/i18n}/locales/te.json +0 -0
  96. package/{shared/localization → lighthouse-core/lib/i18n}/locales/th.json +0 -0
  97. package/{shared/localization → lighthouse-core/lib/i18n}/locales/tr.json +0 -0
  98. package/{shared/localization → lighthouse-core/lib/i18n}/locales/uk.json +0 -0
  99. package/{shared/localization → lighthouse-core/lib/i18n}/locales/vi.json +0 -0
  100. package/{shared/localization → lighthouse-core/lib/i18n}/locales/zh-HK.json +0 -0
  101. package/{shared/localization → lighthouse-core/lib/i18n}/locales/zh-TW.json +0 -0
  102. package/{shared/localization → lighthouse-core/lib/i18n}/locales/zh.json +0 -0
  103. package/{shared/localization → lighthouse-core/lib/i18n}/locales.js +1 -2
  104. package/{shared/localization → lighthouse-core/lib/i18n}/swap-locale.js +7 -9
  105. package/lighthouse-core/lib/page-functions.js +4 -4
  106. package/lighthouse-core/lib/stack-packs.js +13 -1
  107. package/{shared → lighthouse-core/lib}/type-verifiers.js +0 -0
  108. package/lighthouse-core/runner.js +6 -6
  109. package/lighthouse-core/scripts/manual-chrome-launcher.js +1 -4
  110. package/lighthouse-core/util-commonjs.js +4 -20
  111. package/package.json +16 -19
  112. package/readme.md +1 -1
  113. package/report/assets/standalone-template.html +1 -0
  114. package/report/assets/styles.css +41 -16
  115. package/report/assets/templates.html +4 -42
  116. package/report/clients/psi.js +0 -1
  117. package/report/clients/standalone.js +2 -1
  118. package/report/generator/file-namer.js +8 -17
  119. package/report/generator/report-generator.js +1 -0
  120. package/report/renderer/category-renderer.js +16 -4
  121. package/report/renderer/components.js +71 -107
  122. package/report/renderer/dom.js +0 -19
  123. package/report/renderer/logger.js +2 -35
  124. package/report/renderer/performance-category-renderer.js +21 -23
  125. package/report/renderer/pwa-category-renderer.js +2 -1
  126. package/report/renderer/report-renderer.js +0 -21
  127. package/report/renderer/report-ui-features.js +19 -7
  128. package/report/renderer/util.js +4 -20
  129. package/report/test/clients/psi-test.js +4 -0
  130. package/report/test/generator/file-namer-test.js +2 -2
  131. package/report/test/renderer/category-renderer-test.js +1 -1
  132. package/report/test/renderer/performance-category-renderer-test.js +0 -12
  133. package/report/test/renderer/report-renderer-test.js +55 -0
  134. package/report/test/renderer/util-test.js +8 -68
  135. package/report/test-assets/faux-psi-template.html +1 -0
  136. package/report/tsconfig.json +1 -2
  137. package/report/types/html-renderer.d.ts +1 -2
  138. package/root.js +0 -18
  139. package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +3 -5
  140. package/third-party/chromium-synchronization/installability-errors-test.js +1 -2
  141. package/tsconfig-all.json +0 -1
  142. package/tsconfig-base.json +1 -1
  143. package/tsconfig.json +3 -2
  144. package/types/config.d.ts +0 -1
  145. package/types/externs.d.ts +0 -2
  146. package/types/lhr/flow.d.ts +0 -7
  147. package/types/lhr/i18n.d.ts +3 -0
  148. package/changelog.md +0 -5395
  149. package/flow-report/.eslintrc.cjs +0 -49
  150. package/flow-report/package.json +0 -4
  151. package/flow-report/src/header.tsx +0 -88
  152. package/flow-report/src/help-dialog.tsx +0 -120
  153. package/flow-report/src/i18n/i18n.tsx +0 -44
  154. package/flow-report/src/i18n/localized-strings.js +0 -11
  155. package/flow-report/src/i18n/ui-strings.js +0 -86
  156. package/flow-report/test/common-test.tsx +0 -89
  157. package/flow-report/test/header-test.tsx +0 -55
  158. package/flow-report/test/sample-flow.ts +0 -17
  159. package/flow-report/test/topbar-test.tsx +0 -68
  160. package/lighthouse-cli/commands/list-locales.js +0 -16
  161. package/lighthouse-core/lib/cdt/Platform.js +0 -55
  162. package/lighthouse-core/scripts/package.json +0 -4
  163. package/report/renderer/swap-locale-feature.js +0 -82
  164. package/report/test/renderer/report-renderer-axe-test.js +0 -86
  165. package/shared/localization/format.js +0 -422
  166. package/shared/localization/swap-flow-locale.js +0 -20
  167. package/shared/test/localization/format-test.js +0 -377
  168. package/shared/test/localization/locales-test.js +0 -47
  169. package/shared/test/localization/swap-locale-test.js +0 -140
  170. package/shared/tsconfig.json +0 -22
  171. package/shared/types/shared.d.ts +0 -24
  172. package/types/es-main.d.ts +0 -18
@@ -162,23 +162,6 @@ function filterAuditsByGatherMode(audits, mode) {
162
162
  });
163
163
  }
164
164
 
165
- /**
166
- * Optional `supportedModes` property can explicitly exclude a category even if some audits are available.
167
- *
168
- * @param {LH.Config.Config['categories']} categories
169
- * @param {LH.Gatherer.GatherMode} mode
170
- * @return {LH.Config.Config['categories']}
171
- */
172
- function filterCategoriesByGatherMode(categories, mode) {
173
- if (!categories) return null;
174
-
175
- const categoriesToKeep = Object.entries(categories)
176
- .filter(([_, category]) => {
177
- return !category.supportedModes || category.supportedModes.includes(mode);
178
- });
179
- return Object.fromEntries(categoriesToKeep);
180
- }
181
-
182
165
  /**
183
166
  * Filters a categories object and their auditRefs down to the specified category ids.
184
167
  *
@@ -242,10 +225,9 @@ function filterCategoriesByAvailableAudits(categories, availableAudits) {
242
225
  */
243
226
  function filterConfigByGatherMode(config, mode) {
244
227
  const artifacts = filterArtifactsByGatherMode(config.artifacts, mode);
245
- const supportedAudits = filterAuditsByGatherMode(config.audits, mode);
246
- const audits = filterAuditsByAvailableArtifacts(supportedAudits, artifacts || []);
247
- const supportedCategories = filterCategoriesByGatherMode(config.categories, mode);
248
- const categories = filterCategoriesByAvailableAudits(supportedCategories, audits || []);
228
+ const availableAudits = filterAuditsByAvailableArtifacts(config.audits, artifacts || []);
229
+ const audits = filterAuditsByGatherMode(availableAudits, mode);
230
+ const categories = filterCategoriesByAvailableAudits(config.categories, audits || []);
249
231
 
250
232
  return {
251
233
  ...config,
@@ -309,5 +291,4 @@ module.exports = {
309
291
  filterAuditsByGatherMode,
310
292
  filterCategoriesByAvailableAudits,
311
293
  filterCategoriesByExplicitFilters,
312
- filterCategoriesByGatherMode,
313
294
  };
@@ -5,7 +5,6 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const log = require('lighthouse-logger');
9
8
  const ProtocolSession = require('./session.js');
10
9
  const ExecutionContext = require('../../gather/driver/execution-context.js');
11
10
  const Fetcher = require('../../gather/fetcher.js');
@@ -69,13 +68,10 @@ class Driver {
69
68
  /** @return {Promise<void>} */
70
69
  async connect() {
71
70
  if (this._session) return;
72
- const status = {msg: 'Connecting to browser', id: 'lh:driver:connect'};
73
- log.time(status);
74
71
  const session = await this._page.target().createCDPSession();
75
72
  this._session = this.defaultSession = new ProtocolSession(session);
76
73
  this._executionContext = new ExecutionContext(this._session);
77
74
  this._fetcher = new Fetcher(this._session, this._executionContext);
78
- log.timeEnd(status);
79
75
  }
80
76
 
81
77
  /** @return {Promise<void>} */
@@ -20,7 +20,7 @@ const emulation = require('../../lib/emulation.js');
20
20
  const {defaultNavigationConfig} = require('../../config/constants.js');
21
21
  const {initializeConfig} = require('../config/config.js');
22
22
  const {getBaseArtifacts, finalizeArtifacts} = require('./base-artifacts.js');
23
- const format = require('../../../shared/localization/format.js');
23
+ const i18n = require('../../lib/i18n/i18n.js');
24
24
  const LighthouseError = require('../../lib/lh-error.js');
25
25
  const {getPageLoadError} = require('../../lib/navigation-error.js');
26
26
  const Trace = require('../../gather/gatherers/trace.js');
@@ -165,7 +165,7 @@ async function _computeNavigationResult(
165
165
 
166
166
  if (pageLoadError) {
167
167
  const locale = navigationContext.config.settings.locale;
168
- const localizedMessage = format.getFormatted(pageLoadError.friendlyMessage, locale);
168
+ const localizedMessage = i18n.getFormatted(pageLoadError.friendlyMessage, locale);
169
169
  log.error('NavigationRunner', localizedMessage, navigationContext.requestedUrl);
170
170
 
171
171
  /** @type {Partial<LH.GathererArtifacts>} */
@@ -6,13 +6,11 @@
6
6
  'use strict';
7
7
 
8
8
  const {generateFlowReportHtml} = require('../../report/generator/report-generator.js');
9
- const {snapshot} = require('./gather/snapshot-runner.js');
10
- const {startTimespan} = require('./gather/timespan-runner.js');
11
- const {navigation} = require('./gather/navigation-runner.js');
9
+ const {navigation, startTimespan, snapshot} = require('./api.js');
12
10
 
13
11
  /** @typedef {Parameters<snapshot>[0]} FrOptions */
14
- /** @typedef {Omit<FrOptions, 'page'> & {name?: string}} UserFlowOptions */
15
- /** @typedef {Omit<FrOptions, 'page'> & {stepName?: string}} StepOptions */
12
+ /** @typedef {Omit<FrOptions, 'page'>} UserFlowOptions */
13
+ /** @typedef {UserFlowOptions & {stepName?: string}} StepOptions */
16
14
 
17
15
  class UserFlow {
18
16
  /**
@@ -22,8 +20,6 @@ class UserFlow {
22
20
  constructor(page, options) {
23
21
  /** @type {FrOptions} */
24
22
  this.options = {page, ...options};
25
- /** @type {string|undefined} */
26
- this.name = options && options.name;
27
23
  /** @type {LH.FlowResult.Step[]} */
28
24
  this.steps = [];
29
25
  }
@@ -53,29 +49,6 @@ class UserFlow {
53
49
  }
54
50
  }
55
51
 
56
- /**
57
- * @param {string} url
58
- * @param {StepOptions=} stepOptions
59
- */
60
- _getNextNavigationOptions(url, stepOptions) {
61
- const options = {url, ...this.options, ...stepOptions};
62
-
63
- // On repeat navigations, we want to disable storage reset by default (i.e. it's not a cold load).
64
- const isSubsequentNavigation = this.steps.some(step => step.lhr.gatherMode === 'navigation');
65
- if (isSubsequentNavigation) {
66
- const configContext = {...options.configContext};
67
- const settingsOverrides = {...configContext.settingsOverrides};
68
- if (settingsOverrides.disableStorageReset === undefined) {
69
- settingsOverrides.disableStorageReset = true;
70
- }
71
-
72
- configContext.settingsOverrides = settingsOverrides;
73
- options.configContext = configContext;
74
- }
75
-
76
- return options;
77
- }
78
-
79
52
  /**
80
53
  * @param {string} url
81
54
  * @param {StepOptions=} stepOptions
@@ -83,7 +56,8 @@ class UserFlow {
83
56
  async navigate(url, stepOptions) {
84
57
  if (this.currentTimespan) throw Error('Timespan already in progress');
85
58
 
86
- const result = await navigation(this._getNextNavigationOptions(url, stepOptions));
59
+ const options = {url, ...this.options, ...stepOptions};
60
+ const result = await navigation(options);
87
61
  if (!result) throw Error('Navigation returned undefined');
88
62
 
89
63
  const providedName = stepOptions && stepOptions.stepName;
@@ -146,10 +120,7 @@ class UserFlow {
146
120
  * @return {LH.FlowResult}
147
121
  */
148
122
  getFlowResult() {
149
- if (!this.steps.length) throw Error('Need at least one step before getting the flow result');
150
- const url = new URL(this.steps[0].lhr.finalUrl);
151
- const name = this.name || `User flow (${url.hostname})`;
152
- return {steps: this.steps, name};
123
+ return {steps: this.steps};
153
124
  }
154
125
 
155
126
  /**
@@ -5,7 +5,6 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const log = require('lighthouse-logger');
9
8
  const NetworkMonitor = require('./network-monitor.js');
10
9
  const {waitForFullyLoaded, waitForFrameNavigated, waitForUserToContinue} = require('./wait-for-condition.js'); // eslint-disable-line max-len
11
10
  const constants = require('../../config/constants.js');
@@ -83,9 +82,6 @@ function resolveWaitForFullyLoadedOptions(options) {
83
82
  * @return {Promise<{finalUrl: string, warnings: Array<LH.IcuMessage>}>}
84
83
  */
85
84
  async function gotoURL(driver, url, options) {
86
- const status = {msg: `Navigating to ${url}`, id: 'lh:driver:navigate'};
87
- log.time(status);
88
-
89
85
  const session = driver.defaultSession;
90
86
  const networkMonitor = new NetworkMonitor(driver.defaultSession);
91
87
 
@@ -129,7 +125,6 @@ async function gotoURL(driver, url, options) {
129
125
  await waitForUserToContinue(driver);
130
126
  }
131
127
 
132
- log.timeEnd(status);
133
128
  return {
134
129
  finalUrl,
135
130
  warnings: getNavigationWarnings({timedOut, finalUrl, requestedUrl: url}),
@@ -142,16 +142,11 @@ async function prepareDeviceEmulationAndAsyncStacks(driver, settings) {
142
142
  * @param {LH.Config.Settings} settings
143
143
  */
144
144
  async function prepareTargetForTimespanMode(driver, settings) {
145
- const status = {msg: 'Preparing target for timespan mode', id: 'lh:prepare:timespanMode'};
146
- log.time(status);
147
-
148
145
  await prepareDeviceEmulationAndAsyncStacks(driver, settings);
149
146
  await prepareThrottlingAndNetwork(driver.defaultSession, settings, {
150
147
  disableThrottling: false,
151
148
  blockedUrlPatterns: undefined,
152
149
  });
153
-
154
- log.timeEnd(status);
155
150
  }
156
151
 
157
152
  /**
@@ -164,9 +159,6 @@ async function prepareTargetForTimespanMode(driver, settings) {
164
159
  * @param {LH.Config.Settings} settings
165
160
  */
166
161
  async function prepareTargetForNavigationMode(driver, settings) {
167
- const status = {msg: 'Preparing target for navigation mode', id: 'lh:prepare:navigationMode'};
168
- log.time(status);
169
-
170
162
  await prepareDeviceEmulationAndAsyncStacks(driver, settings);
171
163
 
172
164
  // Automatically handle any JavaScript dialogs to prevent a hung renderer.
@@ -179,8 +171,6 @@ async function prepareTargetForNavigationMode(driver, settings) {
179
171
  if (settings.throttlingMethod === 'simulate') {
180
172
  await shimRequestIdleCallbackOnNewDocument(driver, settings);
181
173
  }
182
-
183
- log.timeEnd(status);
184
174
  }
185
175
 
186
176
  /**
@@ -194,9 +184,6 @@ async function prepareTargetForNavigationMode(driver, settings) {
194
184
  * @return {Promise<{warnings: Array<LH.IcuMessage>}>}
195
185
  */
196
186
  async function prepareTargetForIndividualNavigation(session, settings, navigation) {
197
- const status = {msg: 'Preparing target for navigation', id: 'lh:prepare:navigation'};
198
- log.time(status);
199
-
200
187
  /** @type {Array<LH.IcuMessage>} */
201
188
  const warnings = [];
202
189
 
@@ -208,7 +195,6 @@ async function prepareTargetForIndividualNavigation(session, settings, navigatio
208
195
 
209
196
  await prepareThrottlingAndNetwork(session, settings, navigation);
210
197
 
211
- log.timeEnd(status);
212
198
  return {warnings};
213
199
  }
214
200
 
@@ -33,9 +33,6 @@ const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
33
33
  * @return {Promise<void>}
34
34
  */
35
35
  async function clearDataForOrigin(session, url) {
36
- const status = {msg: 'Cleaning origin data', id: 'lh:storage:clearDataForOrigin'};
37
- log.time(status);
38
-
39
36
  const origin = new URL(url).origin;
40
37
 
41
38
  // Clear some types of storage.
@@ -66,8 +63,6 @@ async function clearDataForOrigin(session, url) {
66
63
  } else {
67
64
  throw err;
68
65
  }
69
- } finally {
70
- log.timeEnd(status);
71
66
  }
72
67
  }
73
68
 
@@ -10,7 +10,7 @@ const NetworkRecords = require('../computed/network-records.js');
10
10
  const {getPageLoadError} = require('../lib/navigation-error.js');
11
11
  const emulation = require('../lib/emulation.js');
12
12
  const constants = require('../config/constants.js');
13
- const format = require('../../shared/localization/format.js');
13
+ const i18n = require('../lib/i18n/i18n.js');
14
14
  const {getBenchmarkIndex, getEnvironmentWarnings} = require('./driver/environment.js');
15
15
  const prepare = require('./driver/prepare.js');
16
16
  const storage = require('./driver/storage.js');
@@ -574,7 +574,7 @@ class GatherRunner {
574
574
  networkRecords: loadData.networkRecords,
575
575
  });
576
576
  if (pageLoadError) {
577
- const localizedMessage = format.getFormatted(pageLoadError.friendlyMessage,
577
+ const localizedMessage = i18n.getFormatted(pageLoadError.friendlyMessage,
578
578
  passContext.settings.locale);
579
579
  log.error('GatherRunner', localizedMessage, passContext.url);
580
580
 
@@ -20,11 +20,7 @@ const {fetchResponseBodyFromCache} = require('../../driver/network.js');
20
20
  const NetworkRecords = require('../../../computed/network-records.js');
21
21
 
22
22
  const CHROME_EXTENSION_PROTOCOL = 'chrome-extension:';
23
- const compressionHeaders = [
24
- 'content-encoding',
25
- 'x-original-content-encoding',
26
- 'x-content-encoding-over-network',
27
- ];
23
+ const compressionHeaders = ['content-encoding', 'x-original-content-encoding'];
28
24
  const compressionTypes = ['gzip', 'br', 'deflate'];
29
25
  const binaryMimeTypes = ['image', 'audio', 'video'];
30
26
  /** @type {LH.Crdp.Network.ResourceType[]} */
@@ -22,26 +22,6 @@ function snakeCaseToCamelCase(str) {
22
22
  return str.replace(/(-\w)/g, m => m[1].toUpperCase());
23
23
  }
24
24
 
25
- /* c8 ignore start */
26
-
27
- // eslint-disable-next-line no-inner-declarations
28
- function getObservedDeviceMetrics() {
29
- // Convert the Web API's snake case (landscape-primary) to camel case (landscapePrimary).
30
- const screenOrientationType = /** @type {LH.Crdp.Emulation.ScreenOrientationType} */ (
31
- snakeCaseToCamelCase(window.screen.orientation.type));
32
- return {
33
- width: document.documentElement.clientWidth,
34
- height: document.documentElement.clientHeight,
35
- screenOrientation: {
36
- type: screenOrientationType,
37
- angle: window.screen.orientation.angle,
38
- },
39
- deviceScaleFactor: window.devicePixelRatio,
40
- };
41
- }
42
-
43
- /* c8 ignore stop */
44
-
45
25
  class FullPageScreenshot extends FRGatherer {
46
26
  /** @type {LH.Gatherer.GathererMeta} */
47
27
  meta = {
@@ -160,17 +140,9 @@ class FullPageScreenshot extends FRGatherer {
160
140
  const executionContext = context.driver.executionContext;
161
141
  const settings = context.settings;
162
142
 
163
- // In case some other program is controlling emulation, remember what the device looks
143
+ // In case some other program is controlling emulation, try to remember what the device looks
164
144
  // like now and reset after gatherer is done.
165
- let observedDeviceMetrics;
166
145
  const lighthouseControlsEmulation = !settings.screenEmulation.disabled;
167
- if (!lighthouseControlsEmulation) {
168
- observedDeviceMetrics = await executionContext.evaluate(getObservedDeviceMetrics, {
169
- args: [],
170
- useIsolation: true,
171
- deps: [snakeCaseToCamelCase],
172
- });
173
- }
174
146
 
175
147
  try {
176
148
  return {
@@ -181,7 +153,7 @@ class FullPageScreenshot extends FRGatherer {
181
153
  // Revert resized page.
182
154
  if (lighthouseControlsEmulation) {
183
155
  await emulation.emulate(session, settings);
184
- } else if (observedDeviceMetrics) {
156
+ } else {
185
157
  // Best effort to reset emulation to what it was.
186
158
  // https://github.com/GoogleChrome/lighthouse/pull/10716#discussion_r428970681
187
159
  // TODO: seems like this would be brittle. Should at least work for devtools, but what
@@ -189,6 +161,28 @@ class FullPageScreenshot extends FRGatherer {
189
161
  // in the LH runner api, which for ex. puppeteer consumers would setup puppeteer emulation,
190
162
  // and then just call that to reset?
191
163
  // https://github.com/GoogleChrome/lighthouse/issues/11122
164
+
165
+ // eslint-disable-next-line no-inner-declarations
166
+ function getObservedDeviceMetrics() {
167
+ // Convert the Web API's snake case (landscape-primary) to camel case (landscapePrimary).
168
+ const screenOrientationType = /** @type {LH.Crdp.Emulation.ScreenOrientationType} */ (
169
+ snakeCaseToCamelCase(window.screen.orientation.type));
170
+ return {
171
+ width: document.documentElement.clientWidth,
172
+ height: document.documentElement.clientHeight,
173
+ screenOrientation: {
174
+ type: screenOrientationType,
175
+ angle: window.screen.orientation.angle,
176
+ },
177
+ deviceScaleFactor: window.devicePixelRatio,
178
+ };
179
+ }
180
+
181
+ const observedDeviceMetrics = await executionContext.evaluate(getObservedDeviceMetrics, {
182
+ args: [],
183
+ useIsolation: true,
184
+ deps: [snakeCaseToCamelCase],
185
+ });
192
186
  await session.sendCommand('Emulation.setDeviceMetricsOverride', {
193
187
  mobile: settings.formFactor === 'mobile',
194
188
  ...observedDeviceMetrics,
@@ -1,9 +1,14 @@
1
1
  /**
2
- * @license Copyright 2021 Google Inc. All Rights Reserved.
2
+ * @license Copyright 2020 The Lighthouse Authors. All Rights Reserved.
3
3
  * 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
4
4
  * 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.
5
5
  */
6
6
  'use strict';
7
7
 
8
- module.exports.swapLocale = require('./swap-locale.js');
9
- module.exports.format = require('./format.js');
8
+ /** @fileoverview Needed for the generated/SourceMap.js file */
9
+
10
+ const Common = {
11
+ console,
12
+ };
13
+
14
+ module.exports = Common;
@@ -4,25 +4,145 @@
4
4
  * 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.
5
5
  */
6
6
  'use strict';
7
+
7
8
  const SDK = {
8
9
  TextSourceMap: require('./generated/SourceMap.js'),
9
10
  };
10
11
 
12
+ /**
13
+ * CDT pollutes Array.prototype w/ `lowerBound/upperBound`. SourceMap
14
+ * relies on this, but only for a couple method return values. To avoid global pollution,
15
+ * we explicitly set the extension functions on the return values.
16
+ *
17
+ * @param {unknown[]} array
18
+ */
19
+ function extendArray(array) {
20
+ // @ts-expect-error
21
+ if (array.lowerBound) return;
22
+
23
+ // @ts-expect-error
24
+ array.lowerBound = lowerBound.bind(array);
25
+ // @ts-expect-error
26
+ array.upperBound = upperBound.bind(array);
27
+
28
+ array.slice = function(start, end) {
29
+ const retVal = Array.prototype.slice.call(array, start, end);
30
+ extendArray(retVal);
31
+ return retVal;
32
+ };
33
+ // @ts-expect-error
34
+ array.filter = function(fn) {
35
+ const retVal = Array.prototype.filter.call(array, fn);
36
+ extendArray(retVal);
37
+ return retVal;
38
+ };
39
+ }
40
+
41
+ const originalMappings = SDK.TextSourceMap.prototype.mappings;
42
+ SDK.TextSourceMap.prototype.mappings = function() {
43
+ const mappings = originalMappings.call(this);
44
+ extendArray(mappings);
45
+ return mappings;
46
+ };
47
+
48
+ const originalReversedMappings = SDK.TextSourceMap.prototype._reversedMappings;
49
+ /** @param {string} sourceURL */
50
+ SDK.TextSourceMap.prototype._reversedMappings = function(sourceURL) {
51
+ const mappings = originalReversedMappings.call(this, sourceURL);
52
+ extendArray(mappings);
53
+ return mappings;
54
+ };
55
+
56
+ /**
57
+ * `upperBound` and `lowerBound` are copied from CDT utilities.js.
58
+ * These are the only methods needed from that file.
59
+ */
60
+
61
+ /**
62
+ * Return index of the leftmost element that is greater
63
+ * than the specimen object. If there's no such element (i.e. all
64
+ * elements are smaller or equal to the specimen) returns right bound.
65
+ * The function works for sorted array.
66
+ * When specified, |left| (inclusive) and |right| (exclusive) indices
67
+ * define the search window.
68
+ *
69
+ * @param {!T} object
70
+ * @param {function(!T,!S):number=} comparator
71
+ * @param {number=} left
72
+ * @param {number=} right
73
+ * @return {number}
74
+ * @this {Array.<!S>}
75
+ * @template T,S
76
+ */
77
+ function upperBound(object, comparator, left, right) {
78
+ // @ts-expect-error
79
+ function defaultComparator(a, b) {
80
+ return a < b ? -1 : (a > b ? 1 : 0);
81
+ }
82
+ comparator = comparator || defaultComparator;
83
+ let l = left || 0;
84
+ let r = right !== undefined ? right : this.length;
85
+ while (l < r) {
86
+ const m = (l + r) >> 1;
87
+ if (comparator(object, this[m]) >= 0) {
88
+ l = m + 1;
89
+ } else {
90
+ r = m;
91
+ }
92
+ }
93
+ return r;
94
+ }
95
+
96
+ /**
97
+ * Return index of the leftmost element that is equal or greater
98
+ * than the specimen object. If there's no such element (i.e. all
99
+ * elements are smaller than the specimen) returns right bound.
100
+ * The function works for sorted array.
101
+ * When specified, |left| (inclusive) and |right| (exclusive) indices
102
+ * define the search window.
103
+ *
104
+ * @param {!T} object
105
+ * @param {function(!T,!S):number=} comparator
106
+ * @param {number=} left
107
+ * @param {number=} right
108
+ * @return {number}
109
+ * @this {Array.<!S>}
110
+ * @template T,S
111
+ */
112
+ function lowerBound(object, comparator, left, right) {
113
+ // @ts-expect-error
114
+ function defaultComparator(a, b) {
115
+ return a < b ? -1 : (a > b ? 1 : 0);
116
+ }
117
+ comparator = comparator || defaultComparator;
118
+ let l = left || 0;
119
+ let r = right !== undefined ? right : this.length;
120
+ while (l < r) {
121
+ const m = (l + r) >> 1;
122
+ if (comparator(object, this[m]) > 0) {
123
+ l = m + 1;
124
+ } else {
125
+ r = m;
126
+ }
127
+ }
128
+ return r;
129
+ }
130
+
11
131
  // Add `lastColumnNumber` to mappings. This will eventually be added to CDT.
12
132
  // @ts-expect-error
13
133
  SDK.TextSourceMap.prototype.computeLastGeneratedColumns = function() {
14
134
  const mappings = this.mappings();
15
- if (mappings.length && mappings[0].lastColumnNumber !== undefined) return;
135
+ // @ts-expect-error: `lastColumnNumber` is not on types yet.
136
+ if (mappings.length && typeof mappings[0].lastColumnNumber !== 'undefined') return;
16
137
 
17
138
  for (let i = 0; i < mappings.length - 1; i++) {
18
139
  const mapping = mappings[i];
19
140
  const nextMapping = mappings[i + 1];
20
141
  if (mapping.lineNumber === nextMapping.lineNumber) {
142
+ // @ts-expect-error: `lastColumnNumber` is not on types yet.
21
143
  mapping.lastColumnNumber = nextMapping.columnNumber;
22
144
  }
23
145
  }
24
-
25
- // Now, all but the last mapping on each line will have 'lastColumnNumber' set to a number.
26
146
  };
27
147
 
28
148
  module.exports = SDK;